Run and debug Java test cases in Visual Studio Code.
Перейти к файлу
Sheng Chen fbf75384ff
chore(deps): Migrate to @vscode/test-electron (#1445)
Signed-off-by: Sheng Chen <sheche@microsoft.com>
2022-06-30 14:51:42 +08:00
.github chore: Update to Java 17 in CI (#1434) 2022-06-08 00:53:59 -07:00
.vscode test: Add tests for enabling tests (#1358) 2022-01-20 10:49:22 +08:00
demo refactor: Adopt to the new VS Code tests API (#1257) 2021-08-03 13:49:53 +08:00
java-extension chore(deps): Bump vscode-extension-telemetry-wrapper to 0.13.1 (#1443) 2022-06-29 12:21:52 +08:00
resources refactor: Adopt to the new VS Code tests API (#1257) 2021-08-03 13:49:53 +08:00
scripts prepare for pre-release (#1389) 2022-03-24 19:05:30 +08:00
src fix: Line separators are missing in diff messages (#1444) 2022-06-29 15:29:42 +08:00
test chore(deps): Migrate to @vscode/test-electron (#1445) 2022-06-30 14:51:42 +08:00
.gitignore refactor: Adopt to the new VS Code tests API (#1257) 2021-08-03 13:49:53 +08:00
.vscodeignore chore: Remove the gulp dependency (#1313) 2021-09-27 09:46:18 +08:00
CHANGELOG.md chore(deps): Bump vscode-extension-telemetry-wrapper to 0.13.1 (#1443) 2022-06-29 12:21:52 +08:00
CONTRIBUTING.md test: Setup unit tests (#1324) 2021-10-26 14:52:48 +08:00
LICENSE.txt Re-structure the repo (#473) 2018-11-29 16:02:21 +08:00
README.md chore: Rename to Test Runner for Java (#1272) 2021-08-12 18:39:00 -07:00
SECURITY.md chore: Add Microsoft SECURITY.MD (#1421) 2022-05-18 18:14:32 -07:00
ThirdPartyNotices.txt chore: Add Java dependency notices to third party notice (#1322) 2021-10-19 15:14:32 +08:00
extension.bundle.ts refactor: Adopt to the new VS Code tests API (#1257) 2021-08-03 13:49:53 +08:00
javaConfig.json chore: support to debug Java side code in VS Code (#786) 2019-08-26 17:15:34 +08:00
main.js Add JUnit 4 E2E tests for Code Lens (#864) 2019-11-13 09:49:43 +08:00
package-lock.json chore(deps): Migrate to @vscode/test-electron (#1445) 2022-06-30 14:51:42 +08:00
package.json chore(deps): Migrate to @vscode/test-electron (#1445) 2022-06-30 14:51:42 +08:00
package.nls.json fix: Remove the refresh Java tests command (#1385) 2022-03-06 18:15:16 -08:00
package.nls.zh.json fix: Remove the refresh Java tests command (#1385) 2022-03-06 18:15:16 -08:00
tsconfig.json chore: Check no implicit any (#1107) 2020-11-25 16:52:43 +08:00
tslint.json chore: Adopt progress reporter API (#1119) 2021-01-05 09:23:37 +08:00
webpack.config.js refactor: Adopt to the new VS Code tests API (#1257) 2021-08-03 13:49:53 +08:00

README.md

Test Runner for Java

Run and debug Java test cases in Visual Studio Code

Overview

A lightweight extension to run and debug Java test cases in Visual Studio Code. The extension support 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 (i.e. extends junit.framework.TestCase).

The Test Runner for Java works with Language Support for Java by Red Hat and Debugger for Java to provide the following features:

  • Run/Debug test cases
  • Customize test configurations
  • View test report
  • View tests in Test Explorer

Requirements

Features

Run/Debug Test Cases

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, simply click on the green play button. You can also right click on it to see more options.

Test Explorer

Test Explorer

  • The Test Explorer is the place to show all the test cases in your workspace. You can also run/debug your test cases from here.

Customize Test Configurations

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.

Note: More details can be found here.


View Test Result

View Test Result

  • After running/debugging the test cases, the state of the related test items will be updated in both editor decoration and test explorer.
  • You can trigger the command Test: Peek Output to peek the result view.
  • You can click on the links in the stack trace to navigate to the source location.

VS Code Embedded Commands for Testing

VS Code Embedded Commands for Testing

There are other VS Code embedded commands for testing, which can be found by searching Test: 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 Embedded Settings for Testing

VS Code Embedded Settings for Testing

There are some other VS Code embedded settings for testing, which can be found by searching testing in the Settings view.

Project Setup

JUnit 5

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

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

JUnit 4

Please refer to Download and Install from the JUnit 4's official document for the getting started documentation.

TestNG

Please refer to TestNG Docs from the TestNG's official document for getting started documentation.

FAQ

If you meet any problem when using the extension, please refer to 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 check the document Contributing to Test Runner for Java, which covers the following parts:

License

This extension is licensed under MIT License.

Telemetry

This extension collects telemetry data to help improve our products. Please read Microsoft privacy statement to learn more. If you opt out to send telemetry data to Microsoft, please set below configuration in settings.json: telemetry.enableTelemetry = false. Learn more in our FAQ.