Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you attach the Scala Intellij debugger for tests?

What steps are needed to configure the IntelliJ debugger to attach to scala Play tests managed by sbt?


In IntelliJ 2019, you can attach the debugger to the sbt run command using the debug button in the sbt shell with no configuration changes.
However, the debugger does not attach to the test command.

like image 266
Jethro Avatar asked Aug 07 '19 12:08

Jethro


1 Answers

Consider attaching the debugger via IntelliJ's sbt shell:

  1. In the sbt projects tool window select checkbox Use sbt shell for builds
  2. Open sbt shell tool window (usually found at the bottom)
  3. Click Attach debugger to sbt shell button (the icon looks like a bug)
  4. In the status bar it should say Connected to the target VM (see the image bellow)
  5. Set breakpoints in your test
  6. Execute test command in the sbt shell tool window
  7. Debug sbt shell window should open and execution should stop at the first breakpoint.

enter image description here


Note if you are using Play like OP, then by default Play runs tests in forked JVM, so for the above technique to work try setting Test / fork := false in build.sbt.

like image 139
Mario Galic Avatar answered Nov 15 '22 04:11

Mario Galic