Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run sbt tests for debugging when debug is disabled by default?

I find it incredibly awkward to have to restart sbt with special flags if I want to run the tests (or a main) with debug enabled. It's also a pain if the main or test is usually in a forked JVM:

How to set fork in Test when -jvm-debug given on command line?

Is there any simple way to conditionally do a run, test, test-quick or test-only and ask for debugging to be enabled in the forked process? e.g. with syntax like test-only -jdb

I don't really want to have to write my own Tasks to do this... maintaining them is going to be a nightmare. But I guess that would allow syntax like module/jdb:test-only

like image 718
fommil Avatar asked Nov 10 '14 19:11

fommil


2 Answers

While Eugene accurately mentions that we could provide debug:testOnly out of the box, the following should help you out:

val DebugTest = config("dtest") extend Test

lazy val myproject =
  project.configs(DebugTest).
  settings(inConfig(DebugTest)(Defaults.testSettings):_*).
  settings(
    fork in DebugTest := true,
    javaOptions in DebugTest += "debugging options",
    definedTests in DebugTest := (definedTests in Test).value
  )

This should allow you to do dtest:testOnly *, dtest:run and dtest:test on myproject. The forked JVM (note fork in DebugTest := true) will use whatever debugging options you've provided.

like image 159
jsuereth Avatar answered Sep 19 '22 03:09

jsuereth


I don't think there's any simple feature that enables debugging out of the box.

As you mentioned on sbt-dev list, making a custom configuration like debug:testOnly sounds like a good strategy.

like image 3
Eugene Yokota Avatar answered Sep 21 '22 03:09

Eugene Yokota