Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
647 views
in Technique[技术] by (71.8m points)

eclipse - How to debug tests with Play! 2.0

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...