Matt Howlett

Matt Howlett

every blog should have a tagline

Interactive Debugging of JUnit Tests in VS Code


Today, Microsoft published a Java debugging extension for VS Code. I'm a big fan of this editor, and interactive debugging of Java brings it a big step closer to being a viable alternative to IntelliJ for Java development.

Something that was not immediately apparent to me is whether or not it's possible to interactively debug JUnit tests. Turns out that it is (thanks @andxu!), but currently you need to manually set this up in your launch.json file - you can't just right click a method and select run. Also, it's not possible to run an individual test method - you can only specify the entire test class. Neither of these things is ideal, but I'm finding the situation workable.

Here's the launch.json entry I've been using to debug unit tests for Confluent's JMS Kafka Client:

  "type": "java",
  "name": "Java Debug",
  "request": "launch",
  "cwd": "${workspaceRoot}",
  "mainClass": "org.junit.runner.JUnitCore",
  "args": "io.confluent.kafka.jms.KafkaQueueTest",
  "sourcePaths": [