如何使用 Play 调试测试!2.0 [英] How to debug tests with Play! 2.0

查看:26
本文介绍了如何使用 Play 调试测试!2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Play 2 设置一个项目,并且我已经能够使用 eclipse 远程调试来调试 web 应用程序.不过,我也想在我的测试中使用断点.有谁知道如何设置单元测试的远程调试?

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?

推荐答案

发生这种情况是因为 Play (SBT) 将单独的 JVM 用于测试,而无需远程调试选项.您至少有两个选择:禁用新 JVM 的 fork,将其他选项传递给用于测试的 JVM.

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.

要禁用 fork,修改 Build.scala,在 (Test) := false 中添加 fork,参见下面完整的 Build.scala 示例:

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"
  )

您需要将 IDE 配置为使用端口 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.

这篇关于如何使用 Play 调试测试!2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆