javaVSCode icon indicating copy to clipboard operation
javaVSCode copied to clipboard

Support debugging unit tests

Open dgileadi opened this issue 7 years ago • 2 comments

I'm trying to set up a launch configuration for debugging unit tests, and have hit a wall. I was able to set up my classpath to find the JUnit jar file and launch it. However I'm unable to specify a test file to run. Here's my launch configuration:

        {
            "name": "Run a test",
            "type": "java",
            "request": "launch",
            "jdkPath": "${config:java.home}/bin",
            "sourcePath": ["${workspaceRoot}/src/test/java", "${workspaceRoot}/src/main/java"],
            "cwd": "${workspaceRoot}",
            "startupClass": "org.junit.runner.JUnitCore",
            "options": [
                "-classpath",
                "\"${workspaceRoot}/target/classes:${workspaceRoot}/target/test-classes:/Users/david.gileadi/.m2/repository/junit/junit/4.12/junit-4.12.jar:.\""
            ]
        }

My first thought was to change "startupClass" to include both JUnitCore and my test class, separated by a space. However if I make that change then it's no longer able to start JUnit—it complains:

Error: Could not find or load main class org.junit.runner.JUnitCore path.to.MyTest

Any suggestions?

dgileadi avatar Jun 22 '17 19:06 dgileadi

Remove \" seems that isn't necesary.

"options": [
	"-classpath",
	"${workspaceRoot}/target/classes:${workspaceRoot}/target/test-classes:/Users/david.gileadi/.m2/repository/junit/junit/4.12/junit-4.12.jar:."
]

This problem is already fixed in #45, just waitting to @DonJayamanne to publish a new version :sweat_smile:

faustinoaq avatar Jun 22 '17 19:06 faustinoaq

As soon as fix https://github.com/DonJayamanne/javaVSCode/pull/55 gets published, it will be also possible to specify arguments which will be placed after the startupClass on the java command line. This allows you to select the class which should be tested.

dueckminor avatar Jul 20 '17 15:07 dueckminor