How to debug tests with Play! 2.0

∥☆過路亽.° 提交于 2019-11-28 21:40:45

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.

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.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!