Reputation: 164129
I'm having issues when trying to debug a test which fails in Play.
At first I couldn't make it hit a break point, which turned out to be caused by the forking of a new JVM which happens when testing, so I found out I need to add:
javaOptions in Test ++= Seq(
"-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9998"
)
to the build.sbt
file.
Now it hits the break point when I start the debugger (I'm using IntelliJ) but the problem is that it won't let me start the debugger before it starts the tests.
If I use play debug
then play starts and opens the socket (9999) and then I can start the debugger and only then in the play console start my app (using run), but I can't do the same with the tests..
Once I use play test
the tests start so I have to start the debugger after the tests started running.
Is there any way around this?
Thanks!
Upvotes: 4
Views: 1659
Reputation: 12385
This is how I do it which will hopefully help others.
Change the build.sbt or build.scala to remove the default option of forking each test. Add the line Keys.fork in (Test) := false
val main = play.Project(appName, appVersion, appDependencies).settings(
resolvers += Resolver.sonatypeRepo("snapshots"),
resolvers += Resolver.sonatypeRepo("releases"),
Keys.fork in (Test) := false
)
I start my play session (I am now using activator) with the following command which I store as an alias.
'JAVA_HOME=`/usr/libexec/java_home -v 1.7`; JAVA_OPTS="-Xms1g -Xloggc:gc.log -verbose:gc -XX:+PrintGCDateStamps -server -Xmx2g -Dhttps.port=9443" activator -jvm-debug 9999'
This way you can start play in debug mode and attach the idea to the remote server. In intelliJ you add
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9999
And set the port in the above case its localhost 9999
The reason I like doing it this way is you start the play server once and attach the ide to the remote server. You can then run tests via the console and it will hit your breakpoints, no need to restart and attach the ide for each test.
Upvotes: 5