Skip to content

Run with Configuration

Sheng Chen edited this page Apr 24, 2024 · 15 revisions

You can run tests with custom configuration. The configuration can be specified in settings.json using the key java.test.config.

It's recommended to save the test configuration as workspace settings. To open workspace settings, run command Preferences: Open Workspace Settings (JSON).

TL;DR

Here is an example of the configuration schema:

"java.test.config": [{"name": "myConfiguration","workingDirectory": "${workspaceFolder}","vmargs": ["-Xmx512M"],"env": {"key": "value"},},{// Another configuration item...},
...
]

Note: The commands Run With Configuration and Debug With Configuration are removed from version 0.14.0. The extension will let you select the configuration if it detects there are customized configuration available.

Property Details

The value of java.test.config is an object or an object array, each object is a configuration item, which may have the following properties:

Property NameDescriptionDefault ValueSince
argsSpecify the command line arguments which will be passed to the test runner[]0.14.0
classPathsThe classpaths defined in this setting will be appended to the resolved classpaths[]0.33.0
coverage The configurations for test coverage{}0.41.0
coverage.appendResultWhether the coverage result is appended.true0.41.0
envSpecify the extra environment variables when running the tests{}0.14.0
envFileSpecify the absolute path to a file containing environment variable definitions{}0.33.0
filtersSpecify the test filters{}0.37.0
filters.tagsSpecify the tags to be included or excluded. Tags having ! as the prefix will be excluded. Note: This setting only takes effect when testKind is set to junit[]0.37.0
javaExecThe path to java executable to use. For example: C:\Program Files\jdk\bin\java.exe. If unset project JDK's java executable is used.""0.40.0
modulePathsThe modulepaths defined in this setting will be appended to the resolved modulepaths[]0.33.0
nameSpecify the name of the configuration item""0.14.0
postDebugTaskSpecify the label of a task specified in tasks.json (in the workspace's .vscode folder). The task will be launched at the very end of testing.""0.39.0
preLaunchTaskSpecify 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""0.33.0
sourcePathsSpecify the extra source paths when debugging the tests[]0.22.4
testKindSpecify the targeting test framework for this test configuration. Supported values are junit, testng"junit"0.37.0
vmArgsSpecify the extra options and system properties for the JVM[]0.25.0
whenThe when clause for matching tests by to determine if the configuration should be run with""0.41.0
workingDirectorySpecify the working directory when running the tests<PROJECT_ROOT_PATH>0.14.0

Custom Configurations

When you have custom configurations, you'll be asked to pick one every time when running/debugging your test cases. To avoid that, you can use java.test.defaultConfig and set its value to the name of a configuration.

If you want to bypass any existing configurations, you can use the built-in configuration named "default" which has the following definition:

{
"name": "default",
"workingDirectory": "${workspaceFolder}"
}

Clone this wiki locally