7

My project requires the following vmArgs to run :

"vmArgs": "-javaagent:lib/aspectjweaver-1.9.5.jar -javaagent:lib/spring-instrument-5.2.3.RELEASE.jar --module-path lib/javafx-sdk-13.0.2/lib --add-modules=javafx.controls"

Putting this in the launch.json configuration object makes the project run perfectly. For unit tests, the same vmArgs should be put into the settings.json's java.test.config object, which I did as you see below :

{
    "java.test.config": 
    [
        {
            "name": "testConfig",
            "workingDirectory": "${workspaceFolder}",
            "vmArgs": "-javaagent:lib/aspectjweaver-1.9.5.jar -javaagent:lib/spring-instrument-5.2.3.RELEASE.jar --module-path lib/javafx-sdk-13.0.2/lib --add-modules=javafx.controls"
        }
    ],
    "java.test.defaultConfig": "testConfig"
}

This part is not working. My JUnit tests are not being instrumented correctly. What am I doing wrong? The vmArgs line is an exact copy of what I have in launch.json.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
Martin
  • 1,977
  • 5
  • 30
  • 67
  • Anyone working on a Java project in vsCode where unit tests require JVM arguments? – Martin Feb 28 '20 at 15:21
  • I haven't used JUnit test case within Visual Studio code. However, while comparing your configuration against an example at https://code.visualstudio.com/docs/java/java-testing, I noticed differences -- (i) JSON structure (you have used array for `java.test.config`) and (ii) arguments are proivided in a comma separated list enclosed in a square bracket. Could this be a reason? What is an exact error message you are getting? – Kishan Parekh Mar 02 '20 at 19:02
  • No error per se but the tests fail because the JVM is not being properly instrumented before the Spring context starts therefore said context can't even initialize. I saw that page you linked and I think I tried it like that also but I will give it another shot. – Martin Mar 02 '20 at 19:05
  • Sadly this does not work either : "vmArgs": ["-javaagent:lib/aspectjweaver-1.9.5.jar","-javaagent:lib/spring-instrument-5.2.3.RELEASE.jar","--module-path lib/javafx-sdk-13.0.2/lib","--add-modules=javafx.controls"] – Martin Mar 02 '20 at 19:18

1 Answers1

2

I think it might be caused by the capitalization. Previously, it's vmargs not vmArgs. But the extension has changed to support both in this PR: https://github.com/microsoft/vscode-java-test/pull/1080

Do you still have this issue now?

Sheng Chen
  • 1,012
  • 4
  • 18