简体   繁体   中英

JUnit/Cucumber tests running via Maven not debugging in VS Code

I have a test suite written in Java and utilizing Cucumber and JUnit. This suite is usually ran via Maven, but I'm encountering issues. I want to debug these tests in Visual Studio Code. I've got the Java Extension Pack and set up the following in my launch.json:

{
    "type": "java",
    "name": "Debug (Attach)",
    "request": "attach",
    "hostName": "localhost",
    "port": 8000
}

I then run mvnDebug "-DforkCount=0" test to get Maven to listen on port 8000 and start debugging in VS Code. None of my breakpoints are hit, but the Maven job progresses once debugging starts. I want to be able to step through the code when Maven runs the suite. Suggestions?

I'd given up on VS Code and decided to install Eclipse. In the documentation for that, there was a note to add an argument to the Maven Debug configuration. I decided to try to use it with VS Code, and it worked! I ran mvnDebug test "-DforkMode=never" instead of the aforementioned command, started debugging in VSCode with the same launch.json configuration as listed above, and my breakpoint was hit successfully!

Hopefully this is useful for anyone else using VS Code on the Java stack.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM