Skip to content

How to pass key/value pairs into JUnit test when clicking VSCode “Run Test” codelens

We set several key/value pairs in our file. (eg LOGIN_UID, LOGIN_PWD)

We can successfully reference them in our build.gradle (eg $LOGIN_UID) and our JUnit tests (eg System.getProperty("LOGIN_UID") when running gradle test from the cmdline.

However when clicking on a Run Test codelens within a JUnit’s Java file within VSCode are not passed in. Guessing the Gradle test task is not being executed?

Greatly appreciate it if someone can help us understand and solve this running from a codelens.



Basically what you need is to add a setting in VS Code, something like this:

    "java.test.config": {
        "vmArgs": ["-DLOGIN_UID=id", ...]

Then test runner will pick up them and pass the properties to JVM.

At last, the configuration can be persisted in your workspace’s .vscode/settings.json. If the properties have any sensitive data, like password, don’t commit them to the source control!

5 People found this is helpful