Flag-Friday: debugging tests with –java_debug

To step through a Java test that you’re running with bazel test, use the --java_test flag:

$ bazel test --java_debug //src/test/java/com/example:hello-test
WARNING: Streamed test output requested so all tests will be run locally, without sharding, one at a time.
INFO: Found 1 test target...
Listening for transport dt_socket at address: 5005

At this point, switch over to your IDE and fire up a remote debugging configuration, with the host localhost:5005. The debugger will attach to the running process, your test will start, and the debugger will stop at your first breakpoint.

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: