Provide parameters to TestNG in VSCode

Guriy Samarin
1 min readNov 20, 2023

--

If you have Test Runner for Java extension installed TestNG tests will be detected automatically. But the problem to augment their behaviour.

Usually TestNG tests configured using xml files. You can control execution method (how parallel do you want you test to run, not that it is very important for local run), log configuration and of course parameters. Lets assume you have some method like this

@BeforeSuite
@Parameters({"importantValue", "somethingElse"})
@Override
public void beforeSuite(final String importantValue, final String somethingElse) {
...
}

You can mark parameters as Optional, but it will be test modification for local debugging. One of the worst kind. You will have to revert it before each commit.

Thankfully you can control behaviour of TestNG using java.test.config. Just pass parameters via vmargs section and don’t forget to prefix them with -D

"java.test.config": [
{
"name": "testNGPerfTest",
"workingDirectory": "${workspaceFolder}",
"vmargs": [
"-DimportantValue=impVal",
"-DsomethingElse=else",
"-Dlog4j.configurationFile=build/log4j/Log4jLocal.xml",
"-Dcom.amazonaws.sdk.disableCertChecking"
],
"testKind": "testng",
}
],
"java.test.defaultConfig": "testNGPerfTest"

Don’t forget to add desired section name to java.test.defaultConfig

References:

https://github.com/Microsoft/vscode-java-test/wiki/Run-with-Configuration

--

--

Guriy Samarin
Guriy Samarin

Written by Guriy Samarin

Software developer at Amazon. Web (mostly backend) development now. My stack — .NET (APS.NET Core MVC).

No responses yet