Wayback Machine
129 captures
04 Jan 2019 - 22 Jun 2025
May AUG Oct
Previous capture 04 Next capture
2020 2021 2022
success
fail
About this capture
COLLECTED BY
Collection: Common Crawl
Web crawl data from Common Crawl.
TIMESTAMPS
loading
The Wayback Machine - https://web.archive.org/web/20210804003633/https://code.visualstudio.com/docs/java/java-testing
Skip to content  Visual Studio Code
  • Docs
  • Updates
  • Blog
  • API
  • Extensions
  • FAQ
  • Learn
  • Search
  • Search Search
  • Download VS Code Download VS Code Download

Version 1.58 is now available! Read about the new features and fixes from June.

Dismiss this update
'; document.body.appendChild(div.children[0]); } function pushCodingPackEvent(language, os) { let id = `${language}-${os}-coding-pack`; var analytics = window.vscodeAnalytics; analytics && analytics.event( 'click', 'download', id, ); }
  • Overview
  • Setup
    • Overview
    • Linux
    • macOS
    • Windows
    • Raspberry Pi
    • Network
    • Additional Components
  • Get Started
    • Intro Videos
    • Tips and Tricks
    • User Interface
    • Themes
    • Settings
    • Key Bindings
    • Display Language
    • Telemetry
  • User Guide
    • Basic Editing
    • Extension Marketplace
    • IntelliSense
    • Code Navigation
    • Refactoring
    • Debugging
    • Version Control
    • Working with GitHub
    • Integrated Terminal
    • Tasks
    • Settings Sync
    • Snippets
    • Emmet
    • Command Line
    • Workspace Trust
    • Multi-root Workspaces
    • Accessibility
  • Languages
    • Overview
    • JavaScript
    • JSON
    • HTML
    • CSS, SCSS and Less
    • TypeScript
    • Markdown
    • PowerShell
    • C++
    • Java
    • PHP
    • Python
    • Go
    • T-SQL
    • C#
    • .NET Core
  • Node.js / JavaScript
    • Working with JavaScript
    • Node.js Tutorial
    • Node.js Debugging
    • Node.js Deployment
    • Browser Debugging
    • Angular Tutorial
    • React Tutorial
    • Vue Tutorial
    • Ember Tutorial
    • Debugging Recipes
    • Extensions
  • TypeScript
    • Tutorial
    • Compiling
    • Debugging
  • Python
    • Tutorial
    • Editing Code
    • Linting
    • Debugging
    • Environments
    • Testing
    • Data Science
    • Python Interactive
    • Django Tutorial
    • Flask Tutorial
    • Create containers
    • Python on Azure
    • Settings Reference
  • Java
    • Getting Started
    • Navigate and Edit
    • Refactoring
    • Formatting and Linting
    • Project Management
    • Build Tools
    • Run and Debug
    • Testing
    • Spring Boot
    • Application Servers
    • Java on Azure
    • Extensions
    • FAQ
  • C++
    • Intro Videos
    • GCC on Linux
    • GCC on Windows
    • GCC on Windows Subsystem for Linux
    • Clang on macOS
    • Microsoft C++ on Windows
    • CMake Tools on Linux
    • Debugging
    • Editing
    • Settings
    • Configure IntelliSense for cross-compiling
    • FAQ
  • Containers
    • Overview
    • Node.js
    • Python
    • ASP.NET Core
    • Debug
    • Docker Compose
    • Registries
    • Deploy to Azure
    • Choose a dev environment
    • Customize
    • Develop with Kubernetes
    • Tips and Tricks
  • Data Science
    • Overview
    • Jupyter Notebooks
    • Data Science Tutorial
    • Python Interactive
    • PyTorch Support
  • Azure
    • Extensions
    • Deployment
    • Remote Debugging for Node.js
    • Docker
    • MongoDB
    • Kubernetes
  • Remote
    • Overview
    • SSH
    • Containers
    • Windows Subsystem for Linux
    • GitHub Codespaces
    • SSH Tutorial
    • Containers Tutorial
    • WSL Tutorial
    • Attach to Container
    • Create a Dev Container
    • Advanced Containers
    • devcontainer.json
    • Tips and Tricks
    • FAQ

Topics

Testing Java with Visual Studio Code

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.

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

Install the Java Test Runner

If you run into any issues when using the features below, you can contact us by clicking the Report an issue button below.

Report an issue

Quickstart

Make sure you have the below tools available already

  • JDK (version 11 or later)
  • VS Code (version 1.23.0 or later)
  • Language Support for Java by Red Hat
  • Debugger for Java

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

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

Run from Codelens

  • 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

Run from Explorer

  • 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

Configuration

  • 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

Status Bar

  • 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.

Report Navigation

  • For a quick peek of the test status or results, you can see them in the Test Explorer directly.

Test Status in Explorer

  • 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.

DisplayName annotation

ParameterizedTest annotation

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

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.
4/14/2021

In this article there are 9 sectionsIn this article

  • Quickstart
  • Run/Debug Test Cases
  • Test Explorer
  • Customize Test Configurations
  • View Test Report
  • JUnit5 Support
  • FAQ
  • More Information
  • Next steps
  • Hello from Seattle.
  • Follow @code
  • Support
  • Privacy
  • Manage Cookies
  • Terms of Use
  • License
Microsoft homepage Microsoft homepage © 2021 Microsoft