I am setting up a project using Play 2 and I am already able to debug the webapp using eclipse remote debugging. Though, I'd also like to use breakpoints along my tests. Does anyone know how setup unit tests' remote debugging?
-
2Does this help? http://stackoverflow.com/questions/10859064/how-to-debug-play-2-unit-test-for-server-side – Behe Mar 04 '13 at 21:37
-
No, it does not. I am using play and not the typesafe stack. – Pedro Rolo Mar 05 '13 at 10:20
-
Did you tried command: `play debug ~test` – adis Mar 05 '13 at 10:41
-
1@PedroMorteRolo actually, even if you're not using the Typesafe stack, still that the play console is an SBT one. So the SBT_OTPS should do the trick – Andy Petrella Mar 05 '13 at 11:20
3 Answers
This is happening since Play (SBT) forks separate JVM for tests, without options needed for remote debug. You have at least two options: disable fork of new JVM, pass additional options to JVM used for tests.
To disable fork, modify Build.scala, add fork in (Test) := false
, see full Build.scala example below:
import sbt._
import play.Project._
object ApplicationBuild extends Build {
val appName = "so1"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
// Add your project dependencies here,
javaCore,
javaJdbc,
javaEbean
)
val main = play.Project(appName, appVersion, appDependencies).settings(
// Add your own project settings here
Keys.fork in (Test) := false
)
}
To pass additional options, add you can use this code:
val main = play.Project(appName, appVersion, appDependencies).settings(
Keys.javaOptions in (Test) +=
"-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9998"
)
You will need to configure your IDE to use port 9998 to attach to tests. Also, you will need to re-attach debugger each time when you run tests, that could be inconvenient.

- 1,689
- 2
- 19
- 36
-
Thank you for your answer. I am not using play anymore so I do not know if this answer is correct nor I do have time to try it. If it will have more upvotes I will later mark it as accepted. – Pedro Rolo Apr 10 '13 at 11:22
-
1a better way is to prevent the test to fork as describe [here](http://stackoverflow.com/a/16742485/508064). This allow you use same connection for both the app and the test and the connection is open while the play console is running so one don't need to reattach the debugger. – roterl Jul 03 '14 at 14:45
i use eclipse or rather scala ide
instead of running "play" i run this command "play debug" then play would print this message:
Listening for transport dt_socket at address: 9999
the normal $ prompt for play would appear. then enter this command "run"
from eclipse, i set the breakpoint and click "Run -> Debug Configurations..." look for "Remote Java Application" on the left and click "Launch New Configuration" (small icon, top left, looks like a 'new document' icon). the default port would be 8000, change it to 9999 and change the machine, most probably you would be using localhost. and click on the [Debug] button
that should do it.
just load the normal http://localhost:9000
on your browser
just wait for the application to hit the breakpoint.

- 858
- 7
- 11
-
2this doesn't really help with debugging unit tests though, would have been a useful answer if it was for remote debugging a play app – Stowelly Mar 20 '13 at 10:21
By disabling fork and parallel executing in Test environment, You can debug tests.
Only you should add these lines end of Your build.sbt
file:
parallelExecution in Test := false
fork in Test := false

- 4,447
- 3
- 40
- 63