Formatting pass on recent updates
This commit is contained in:
Родитель
a174fc0f8e
Коммит
a520e33225
|
@ -11,13 +11,11 @@ Author: Xiaokai He
|
|||
|
||||
September 28, 2017 Xiaokai He
|
||||
|
||||
For Java developers on Visual Studio Code, the [Language Support for Java™ by Red Hat](https://marketplace.visualstudio.com/items?itemName=redhat.java) extension has been great for providing language features such as IntelliSense and project support. At the same time, we've also heard feedback that users would also like Java debugging. Today, we're excited to announce our ongoing collaboration with Red Hat and enabling Java developers to debug Java applications with a new lightweight [Java Debugger for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug) based on [Java Debug Server](https://github.com/microsoft/java-debug).
|
||||
For Java developers on Visual Studio Code, the [Language Support for Java™ by Red Hat](https://marketplace.visualstudio.com/items?itemName=redhat.java) extension has been great for providing language features such as IntelliSense and project support. At the same time, we've also heard feedback that users would also like Java debugging. Today, we're excited to announce our ongoing collaboration with Red Hat and enabling Java developers to debug Java applications with a new lightweight [Debugger for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug) based on [Java Debug Server](https://github.com/microsoft/java-debug).
|
||||
|
||||
![Java debug extension](java-debug-extension.png)
|
||||
|
||||
>**Note**: Both the **Java Debugger for Visual Studio Code** and **Java Debug Server** will be open sourced shortly after the initial release.
|
||||
|
||||
To help Java developers to get started with VS Code quickly, we also created an [Extension Pack for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack) which includes both the [Language Support for Java™ by Red Hat](https://marketplace.visualstudio.com/items?itemName=redhat.java) and [Java Debugger for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug) extensions so you won't need to search for them individually. This is just the start to creating a modern workflow for Java and we'll be adding more features and extensions to the **Extension Pack for Java** in the future.
|
||||
To help Java developers to get started with VS Code quickly, we also created an [Extension Pack for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack) which includes both the [Language Support for Java™ by Red Hat](https://marketplace.visualstudio.com/items?itemName=redhat.java) and [Debugger for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug) extensions so you won't need to search for them individually. This is just the start to creating a modern workflow for Java and we'll be adding more features and extensions to the **Extension Pack for Java** in the future.
|
||||
|
||||
## Getting started
|
||||
|
||||
|
@ -25,7 +23,7 @@ To get started:
|
|||
|
||||
1. In Visual Studio Code, open the **Extensions** view (`kb(workbench.view.extensions)`).
|
||||
2. Type "java" to filter the list.
|
||||
3. Find and install the [Extension Pack for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack) or standalone [Java Debugger for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug) extension if you already have [Language Support for Java™ by Red Hat](https://marketplace.visualstudio.com/items?itemName=redhat.java) installed.
|
||||
3. Find and install the [Extension Pack for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack) or standalone [Debugger for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug) extension if you already have [Language Support for Java™ by Red Hat](https://marketplace.visualstudio.com/items?itemName=redhat.java) installed.
|
||||
|
||||
You also install the **Extension Pack for Java** directly from this blog post:
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ To help set up Java on VS Code, there is the Microsoft [Extension Pack for Java]
|
|||
|
||||
1. [Language Support for Java™ by Red Hat](https://marketplace.visualstudio.com/items?itemName=redhat.java)
|
||||
2. [Debugger for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug)
|
||||
3. [Java Test Runner](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test)
|
||||
3. [Test Runner for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test)
|
||||
4. [Maven for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-maven)
|
||||
5. [Project Manager for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-dependency)
|
||||
6. [Visual Studio IntelliCode](https://marketplace.visualstudio.com/items?itemName=VisualStudioExptTeam.vscodeintellicode)
|
||||
|
|
|
@ -87,7 +87,7 @@ Currently we don't plan to extend the Java support to Visual Studio. There are a
|
|||
|
||||
## Does VS Code Java support other display languages?
|
||||
|
||||
Currently we support Chinese in addition to English for a few extensions including [Debugger for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug), [Java Test Runner](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test), [Maven for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-maven), [Project Manager for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-dependency). To learn how to switch the VS Code display language, see [Display Languages](/docs/getstarted/locales.md).
|
||||
Currently we support Chinese in addition to English for a few extensions including [Debugger for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug), [Test Runner for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test), [Maven for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-maven), [Project Manager for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-dependency). To learn how to switch the VS Code display language, see [Display Languages](/docs/getstarted/locales.md).
|
||||
|
||||
You can contribute to the extension repositories if you're interested in additional display language support.
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ Area: java
|
|||
TOCTitle: Testing
|
||||
ContentId: 82be3b78-2c09-4571-abec-69f95f111e0f
|
||||
PageTitle: Java Unit Tests in Visual Studio Code
|
||||
DateApproved: 9/1/2021
|
||||
DateApproved: 11/30/2021
|
||||
MetaDescription: See how you can test your Java code in Visual Studio Code.
|
||||
MetaSocialImage:
|
||||
---
|
||||
|
@ -34,14 +34,16 @@ The [Test Runner for Java](https://marketplace.visualstudio.com/items?itemName=v
|
|||
- Visual Studio Code (version 1.59.0 or later)
|
||||
- [Extension Pack for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack)
|
||||
|
||||
|
||||
<a class="tutorial-install-extension-btn" href="vscode:extension/vscjava.vscode-java-pack">Install the Extension Pack for Java</a>
|
||||
|
||||
## Project Setup
|
||||
(If you have already setup your Java test framework in your project, you can skip to the [Features](#features) section.)
|
||||
|
||||
**Note**: If you have already setup your Java test framework in your project, you can skip to the [Features](#features) section.
|
||||
|
||||
### JUnit 4
|
||||
|
||||
#### Maven
|
||||
|
||||
Add following configuration into your `pom.xml`:
|
||||
|
||||
```xml
|
||||
|
@ -54,6 +56,7 @@ Add following configuration into your `pom.xml`:
|
|||
```
|
||||
|
||||
#### Gradle
|
||||
|
||||
Make sure following lines are added in your `build.gradle`:
|
||||
|
||||
```groovy
|
||||
|
@ -66,22 +69,27 @@ dependencies {
|
|||
}
|
||||
```
|
||||
|
||||
#### Unmanaged Folder
|
||||
If your project does not use any build tools. You need to download the following JARs and add them to the project classpath (via setting `java.project.referencedLibraries`, check [Library Configuration](/docs/java/java-project.md#library-configuration) for more information):
|
||||
#### Unmanaged folder
|
||||
|
||||
If your project does not use any build tools, download the following JARs and add them to the project classpath (via setting `java.project.referencedLibraries`, check [Library Configuration](/docs/java/java-project.md#library-configuration) for more information):
|
||||
|
||||
- [junit.jar](https://search.maven.org/search?q=g:junit%20AND%20a:junit)
|
||||
- [hamcrest-core.jar](https://search.maven.org/artifact/org.hamcrest/hamcrest-core/1.3/jar)
|
||||
|
||||
> You can check the [official wiki](https://github.com/junit-team/junit4/wiki/Download-and-Install) for more information about how to setup JUnit 4.
|
||||
> You can check the [official JUnit wiki](https://github.com/junit-team/junit4/wiki/Download-and-Install) for more information about how to setup JUnit 4.
|
||||
|
||||
### JUnit 5
|
||||
|
||||
The JUnit 5 team provides a collection of sample projects with different build tools. Check the [junit5-sample repository](https://github.com/junit-team/junit5-samples) if your project uses Maven or Gradle as your build tool.
|
||||
|
||||
#### Unmanaged Folder
|
||||
#### Unmanaged folder
|
||||
|
||||
If your project does not use any build tools, for simplicity, you can directly include the [junit-platform-console-standalone](https://repo1.maven.org/maven2/org/junit/platform/junit-platform-console-standalone/) JAR in the project classpath (via setting `java.project.referencedLibraries`, check [Library Configuration](/docs/java/java-project.md#library-configuration) for more information).
|
||||
|
||||
### TestNG
|
||||
|
||||
#### Maven
|
||||
|
||||
Add following configuration into your `pom.xml`:
|
||||
|
||||
```xml
|
||||
|
@ -94,6 +102,7 @@ Add following configuration into your `pom.xml`:
|
|||
```
|
||||
|
||||
#### Gradle
|
||||
|
||||
Make sure following lines are added in your `build.gradle`:
|
||||
|
||||
```groovy
|
||||
|
@ -106,8 +115,9 @@ dependencies {
|
|||
}
|
||||
```
|
||||
|
||||
#### Unmanaged Folder
|
||||
If your project does not use any build tools. You need to download the following JARs and add them to the project classpath (via setting `java.project.referencedLibraries`, check [Library Configuration](/docs/java/java-project.md#library-configuration) for more information):
|
||||
#### Unmanaged folder
|
||||
|
||||
If your project does not use any build tools, download the following JARs and add them to the project classpath (via setting `java.project.referencedLibraries`, check [Library Configuration](/docs/java/java-project.md#library-configuration) for more information):
|
||||
|
||||
- [testng.jar](https://search.maven.org/search?q=g:org.testng%20AND%20a:testng)
|
||||
- [jcommander.jar](https://search.maven.org/artifact/com.beust/jcommander/1.81/jar)
|
||||
|
@ -116,13 +126,13 @@ If your project does not use any build tools. You need to download the following
|
|||
|
||||
### 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, click the green play button. You can also right-click on it to see more options.
|
||||
The Test Runner for Java extension will generate shortcuts (the green play button) on the left side of the class and method definition. To run the target test cases, click the green play button. You can also right-click on it to see more options.
|
||||
|
||||
![Run/Debug Test Cases](images/java-testing/editor-decoration.png)
|
||||
|
||||
### Test Explorer
|
||||
|
||||
The Test Explorer is a tree view to show all the test cases in your workspace. You can click the beaker-like button on the left-side activity bar of Visual Studio Code to open it. You can also run/debug your test cases and view their test results from there.
|
||||
The Test Explorer is a tree view to show all the test cases in your workspace. You can click the beaker button on the left-side Activity bar of Visual Studio Code to open it. You can also run/debug your test cases and view their test results from there.
|
||||
|
||||
![Test Explorer](images/java-testing/test_explorer.png)
|
||||
|
||||
|
@ -133,20 +143,22 @@ Sometimes you may want to customize the configuration to run your test cases. To
|
|||
![Customize test configurations](images/java-testing/configuration.png)
|
||||
|
||||
Currently the supported configurations are:
|
||||
- **args**: Specify the command line arguments which will be passed to the test runner.
|
||||
|
||||
- **args**: Specify the command-line arguments that will be passed to the test runner.
|
||||
- **classPaths**: The classpaths defined in this setting will be appended to the resolved classpaths.
|
||||
- **env**: Specify the extra environment variables when running the tests via a key-value object.
|
||||
- **envFile**: Specify the absolute path to a file containing environment variable definitions.
|
||||
- **modulePaths**: The modulepaths defined in this setting will be appended to the resolved modulepaths.
|
||||
- **name**: Specify the name of the configuration item. You can set the default configuration name via setting `java.test.defaultConfig`
|
||||
- **preLaunchTask**: Specify the label of a task specified in tasks.json (in the workspace's .vscode folder). The task will be launched before the start of testing
|
||||
- **sourcePaths**: Specify the extra source paths when debugging the tests
|
||||
- **vmArgs**: Specify the extra options and system properties for the JVM
|
||||
- **workingDirectory**: Specify the working directory when running the tests
|
||||
- **name**: Specify the name of the configuration item. You can set the default configuration name via setting `java.test.defaultConfig`.
|
||||
- **preLaunchTask**: Specify the label of a task specified in `tasks.json` (in the workspace's `.vscode` folder). The task will be launched before the start of testing.
|
||||
- **sourcePaths**: Specify the extra source paths when debugging the tests.
|
||||
- **vmArgs**: Specify the extra options and system properties for the JVM.
|
||||
- **workingDirectory**: Specify the working directory when running the tests.
|
||||
|
||||
More details can be found on the [vscode-java-test Wiki](https://github.com/Microsoft/vscode-java-test/wiki/Run-with-Configuration).
|
||||
|
||||
### 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](images/java-testing/test_report.png)
|
||||
|
@ -154,26 +166,28 @@ After running/debugging the test cases, the state of the related test items will
|
|||
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.
|
||||
|
||||
### Generate tests
|
||||
The extension provides features to help you scaffold test cases. You can find the entry in the editor context menu. Select `Source Action...` and then choose `Generate Tests...`.
|
||||
|
||||
If you trigger this source action from your main source code (test subject), you will be asked the test class's fully qualified name and the methods you want to test, the extension will generate the test code for you:
|
||||
The extension provides features to help you scaffold test cases. You can find the entry in the editor context menu. Select **Source Action...** and then choose **Generate Tests...**.
|
||||
|
||||
If you trigger this source action from your main source code (test subject), you will be asked the test class's fully qualified name and the methods you want to test. The extension will then generate the test code for you:
|
||||
|
||||
<video autoplay loop muted playsinline controls>
|
||||
<source src="/docs/java/java-testing/generate-tests-from-main.mp4" type="video/mp4">
|
||||
</video>
|
||||
|
||||
If you trigger it from your test source code, you will be asked which kinds of test methods you want to add. Including the lifecycle methods and the test method:
|
||||
If you trigger the source action from your test source code, you will be asked which kinds of test methods you want to add. Including the lifecycle methods and the test method:
|
||||
|
||||
<video autoplay loop muted playsinline controls>
|
||||
<source src="/docs/java/java-testing/generate-tests-from-test.mp4" type="video/mp4">
|
||||
</video>
|
||||
|
||||
### Test navigation
|
||||
The extension provides features to help you navigate between your tests and test subjects. If your source code is contained in `src/main/java` or `src/test/java`, you can find the entry named `Go to Test` or `Go to Test Subject` in the editor context menu:
|
||||
|
||||
The extension provides features to help you navigate between your tests and test subjects. If your source code is contained in `src/main/java` or `src/test/java`, you can find the entry named **Go to Test** or **Go to Test Subject** in the editor context menu:
|
||||
|
||||
![Go to tests](images/java-testing/goto-test.png)
|
||||
|
||||
You can also find the command in the Command Palette (`kb(workbench.action.showCommands)`) by searching `>Java: Go to Test`
|
||||
You can also find the command in the Command Palette (`kb(workbench.action.showCommands)`) by searching for **Java: Go to Test**.
|
||||
|
||||
### VS Code testing commands
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ If you are an existing VS Code user, you can also add Java support by installing
|
|||
|
||||
* [Language Support for Java™ by Red Hat](https://marketplace.visualstudio.com/items?itemName=redhat.java)
|
||||
* [Debugger for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug)
|
||||
* [Java Test Runner](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test)
|
||||
* [Test Runner for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test)
|
||||
* [Maven for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-maven)
|
||||
* [Project Manager for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-dependency)
|
||||
* [Visual Studio IntelliCode](https://marketplace.visualstudio.com/items?itemName=VisualStudioExptTeam.vscodeintellicode)
|
||||
|
|
|
@ -40,7 +40,7 @@ If you have already installed VS Code and want to add Java support to it, we rec
|
|||
|
||||
1. [Language Support for Java™ by Red Hat](https://marketplace.visualstudio.com/items?itemName=redhat.java)
|
||||
2. [Debugger for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug)
|
||||
3. [Java Test Runner](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test)
|
||||
3. [Test Runner for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test)
|
||||
4. [Maven for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-maven)
|
||||
5. [Project Manager for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-dependency)
|
||||
6. [Visual Studio IntelliCode](https://marketplace.visualstudio.com/items?itemName=VisualStudioExptTeam.vscodeintellicode)
|
||||
|
@ -155,7 +155,7 @@ Although it's lightweight, the Java debugger supports advanced features such as
|
|||
|
||||
## Testing
|
||||
|
||||
With the support from the [Java Test Runner](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test) extension, you can easily run, debug, and manage your JUnit and TestNG test cases.
|
||||
With the support from the [Test Runner for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test) extension, you can easily run, debug, and manage your JUnit and TestNG test cases.
|
||||
|
||||
<video autoplay loop muted playsinline controls>
|
||||
<source src="/docs/languages/java/testng.mp4" type="video/mp4">
|
||||
|
|
|
@ -380,7 +380,7 @@ Last fall we began work on adding native support for running tests in VS Code, a
|
|||
|
||||
Existing users of the [Test Explorer UI](https://marketplace.visualstudio.com/items?itemName=hbenl.vscode-test-explorer) extension can get the native experience by setting `testExplorer.useNativeTesting` to `true`. However, the conversion is a reflection of the Test Explorer UI extension's existing API, so some features like rich diff support are not included.
|
||||
|
||||
One of the first extensions to adopt the testing API was the Microsoft [Java Test Runner](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test) included in the [Extension Pack for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack).
|
||||
One of the first extensions to adopt the testing API was the Microsoft [Test Runner for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test) included in the [Extension Pack for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack).
|
||||
|
||||
![Java extension using the native test API in VS Code](images/1_59/java-extension-test-support.png)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче