如何为 sbt 中的每个测试分叉 jvm [英] How to fork the jvm for each test in sbt
问题描述
我正在处理一些(出于某种原因)只能在单个 VM 中使用一次的类.如果我在我的 sbt
设置中启用单独运行它们(fork := true
),我的测试用例就可以工作.
I am working with some classes that (for some reason) can only be used once within a single VM. My test cases work if I run them individually (fork := true
) enabled in my sbt
settings.
如果我运行多个这些测试,它们会失败并出现异常,线程执行器拒绝任务(它很可能已关闭).找出导致问题的原因将非常耗时,即使我找到了问题,我也可能无法解决它(我无权访问源代码).
If I run more than one of these tests, they fail with an exception that has to with a thread executor rejecting a task (it's most likely closed). It would be very time consuming to find out what causes the problem and even if I find the problem, I might not be able to resolve it (I do not have access to the source code).
我目前正在使用 specs2
测试框架,但任何使用 sbt
的测试框架都可以接受.
I am currently using the specs2
test framework, but any test framework using sbt
would be acceptable.
是否有任何 sbt
测试框架能够在 jvm
fork 中运行每个测试?
Is there any test framework for sbt
that is capable of running each test in a jvm
fork?
当然欢迎对可能的其他解决方案提出想法或想法.
Thoughts or ideas on possible other solutions are of course welcome.
推荐答案
事实证明这很容易实现.文档就足够了,可以在 测试 - 分叉测试中找到
It turns out this is fairly easy to achieve. The documentation is sufficient and can be found at Testing - Forking tests
// Define a method to group tests, in my case a single test per group
def singleTests(tests: Seq[TestDefinition]) =
tests map { test =>
new Group(
name = test.name,
tests = Seq(test),
runPolicy = SubProcess(javaOptions = Seq.empty[String]))
}
// Add the following to the `Project` settings
testGrouping in Test <<= definedTests in Test map singleTests
这篇关于如何为 sbt 中的每个测试分叉 jvm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!