Wayback Machine
129 captures
04 Jan 2019 - 22 Jun 2025
May AUG Oct
Previous capture 28 Next capture
2020 2021 2022
success
fail
About this capture
COLLECTED BY
Collection: Save Page Now Outlinks
TIMESTAMPS
loading
The Wayback Machine - https://web.archive.org/web/20210828215446/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.59 is now available! Read about the new features and fixes from July.

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
    • Julia
    • 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 Machine Learning
  • 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 CLI
    • 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.

Overview

The extension supports the following test frameworks:

  • JUnit 4 (v4.8.0+)
  • JUnit 5 (v5.1.0+)
  • TestNG (v6.8.0+)

Note: JUnit 3 styled tests are not supported in this extension (for example, extends junit.framework.TestCase).

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

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

Requirements

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

Features

Run/Debug Test Cases

The extension will generate shortcuts (the green play button) on the left side of the class and method definition. To run the target test cases, select the green play button. You can also right-click on the play button to see more options.

Run/Debug Test Cases

Test Explorer

The Test Explorer shows all the test cases in your workspace. You can also run/debug your test cases from there.

Test Explorer

Customize test configurations

Sometimes you may want to customize the configuration to run your test cases. To achieve this, you can add the configuration into your workspace settings under the section: java.test.config.

Customize test configurations

More details can be found on the vscode-java-test Wiki.

View test results

After running/debugging the test cases, the state of the related test items will be updated in both editor decorations and the Test Explorer.

View test results

You can trigger the command Test: Peek Output to peek the results view. You can select the links in the stack trace to navigate to the source location.

VS Code testing commands

There are other testing commands (for example, Run Tests in Current File) that can be found by searching for 'Test:' in the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)).

Testing commands in the Command Palette

Settings

Setting Name Description Default Value
java.test.config Specify the configuration for the test cases to run with. More details. {}
java.test.defaultConfig Specify the name of the default test configuration. ""

VS Code testing settings

There are VS Code settings specific to testing that can be found by searching for 'testing' in the Settings editor (⌘, (Windows, Linux Ctrl+,)).

Testing settings in the Settings editor

Project Setup

JUnit 5

Please refer to Getting Started from the JUnit 5's official website for getting started documentation.

Note: If your project does not use build tools (Maven/Gradle/...), make sure junit-platform-console-standalone.jar is on your project classpath.

JUnit 4

Refer to Download and Install from the JUnit 4's official website for the getting started documentation.

TestNG

Refer to the TestNG documentation from the TestNG official website for getting started information.

FAQ

If you meet any problem when using the extension, you can review the FAQ and our issue list to check if there is an answer to your problem.

Contributing and Feedback

If you are interested in providing feedback or contributing directly to the code base, please read Contributing to Java Test Runner, which covers the following:

  • Questions and Feedback
  • Reporting Issues
  • Contributing Fixes

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.
8/6/2021

In this article there are 8 sectionsIn this article

  • Overview
  • Requirements
  • Features
  • Settings
  • Project Setup
  • FAQ
  • Contributing and Feedback
  • Next steps
  • Hello from Seattle.
  • Follow @code
  • Support
  • Privacy
  • Manage Cookies
  • Terms of Use
  • License
Microsoft homepage Microsoft homepage © 2021 Microsoft