我想挂起分叉的 vm,并仅在使用 IntegrationDebug
配置时等待来自外部调试器的连接。
参考 http://www.scala-sbt.org/1.x/docs/Testing.html 中的"共享源"部分,我想出了以下配置:
import sbt.Keys._
lazy val IntegrationDebug = config("itd") extend (IntegrationTest)
val scalaTestV = "3.0.4"
lazy val root = project.in(file("."))
.configs(
IntegrationTest,
IntegrationDebug
)
.settings(
Defaults.itSettings,
inConfig(IntegrationDebug)(Defaults.testTasks),
libraryDependencies ++= Seq(
"org.scalactic" %% "scalactic" % scalaTestV,
"org.scalatest" %% "scalatest" % scalaTestV,
),
fork in IntegrationTest := true,
javaOptions in IntegrationDebug += "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8123",
)
但是,它无法按预期工作:
it:test -> vm not suspended (expected)
itd:test -> vm not suspended (unexpected!!)
如果我将javaOptions
的范围更改为IntegrationTest
,即
...
javaOptions in IntegrationTest += "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8123",
...
然后
it:test -> vm suspended (unexpected!!)
itd:test -> vm suspended (expected)
有没有办法让它像这样工作:
it:test -> vm not suspended
itd:test -> vm suspended
好的,如果我没记错的话,我可能已经找到了问题的解决方案。
更换线:
javaOptions in IntegrationDebug += "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8123",
跟
testOptions in IntegrationDebug += Tests.Argument("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8123")
应该可以解决问题(在这种情况下,VM 仅针对itd:test
命令挂起)。
我知道这已经很长时间了,但有人可能会发现这很有用。我几乎遇到了同样的问题,这就是为我解决的问题。