Testing Java in Visual Studio Code is enabled by the Java Test Runner extension. It's a lightweight extension to run and debug Java test cases. The extension supports the following test frameworks:
- JUnit 4 (v4.8.0+)
- JUnit 5 (v5.1.0+)
- TestNG (v6.8.0+)
Note: More information about the test frameworks can be found at JUnit and TestNG.
- In the first one, we only want to run the Unit Tests because they are quick in execution and work as a first line of defense. Integration Tests take longer, and you want to run them once a night i.e. In a 'CI Nightly Build'. Run only Unit Tests. In the VSTS Build configuration, you can still use the standard 'Visual Studio Test' task.
- Our tests run from the command line. But it would be nice to run the tests from within VS Code. For that, we need another VS Code extension. If you search for C test, a large number of extensions show up. I chose C TestMate because it will run GoogleTest, Catch2 and DOCtest.
- Running our first test in Visual Studio Open a new project in the visual studio panel, and under the C tab, choose the test collection. You’ll then be prompted to choose the test type, we’ll go for Native Unit Testing now. Once you, in, you’ll find two source files, go to the unittest1.cpp file.
NUnit is a popular open-source unit testing framework for C#. It is ported from the JUnit framework. It is one of the most popular test frameworks used for the development and execution of tests with the.NET language. In this NUnit Testing Tutorial, we look at NUnit setup example of the environment for developing and executing NUnit tests.
The Java Test Runner works with the Language Support for Java by Red Hat and Debugger for Java extensions to provide the following features:
- Run/Debug test cases
- Customize test configurations
- View test report
- View tests in Test Explorer
- Show test logs
If you run into any issues when using the features below, you can contact us by clicking the Report an issue button below.
Quickstart
Make sure you have the below tools available already
- JDK (version 11 or later)
- VS Code (version 1.23.0 or later)
You may refer to Java Extensions to set up the environment.
Note: More information about JDK can be found at supported Java versions.
Getting Started for JUnit 5
Please refer to Getting Started from the JUnit 5 official documentation.
Note: You can use junit-platform-console-standalone.jar in projects that manually manage their dependencies similar to the plain-old JAR known from JUnit 4.
Getting Started for JUnit 4
Visual Studio Code Run Unit Tests C# Code
Please refer to Download and Install from the JUnit 4 official documentation.
Getting Started for TestNG
Please refer to TestNG Docs from the TestNG official documentation.
Run|Debug CodeLens
When you open a project with test cases from supported frameworks, Test Runner will be activated and you will find Run|Debug on the CodeLens of your test functions. Click on the CodeLens to run the individual test case. You can also access and run a group of test cases from the Test Explorer. For more information on debugging test cases, see Debugging Java.
Here's a brief session with TestNG:
Run/Debug Test Cases
- The extension will generate Run Test and Debug Test shortcuts (also known as CodeLens) above the class and method definition. Select them to start running or debugging the target test cases.

Note: If you cannot see the CodeLens in your editor, please refer to this issue comment as a workaround.
Test Explorer
Visual Studio Code Run Unit Tests C# Pdf
- The Test Explorer is the place to show all the test cases in your project. You can also run/debug your test cases from here.
- Click the node in the Test Explorer will navigate to the location of the source code.
Note: If the Test Explorer is empty, please refer to this issue comment as a workaround.
Customize Test Configurations
- Sometimes you may want to customize the configuration for running the test cases. To achieve this, you can add it into your workspace settings under the section:
java.test.config.
Note: More details can be found in Run with Configuration.
View Test Report
- After running/debugging the test cases, the test report is opened automatically. You can also see the final results in the status bar, by clicking on it to show the Test Report.
- You can also click the ✔️ or ❌ mark in the CodeLens to open the Test Report.
- For a quick peek of the test status or results, you can see them in the Test Explorer directly.
- You can navigate to the source location of the target test case by clicking the navigate button.
JUnit5 Support
The JUnit 5 support covers frequently used annotations such as @DisplayName, @ParameterizedTest, @TestFactory, @TestTemplate, and @Nested. It also supports meta-annotations and composed annotations.
FAQ
If you meet any problem when using the extension, you can refer to the FAQ to check if there is an answer to your problem.
More Information
Visual Studio Code Run Unit Tests
Visit the GitHub repository of the Java Test Runner for more details on commands and settings.
Next steps
Read on to find out about:
- Debugging - Find out how to debug your Java project with VS Code.
- Java Extensions - Learn about more useful Java extensions for VS Code.
