【发布时间】:2020-12-02 10:08:13
【问题描述】:
我目前正在处理基于 maven 的 scala 项目,其中包含一堆 specs2 规范测试,并且正在使用 Intellij 2020.2 和 scala 2.12.10 以及 specs2 版本 4.9.4
我能够毫无问题地运行每个规范,但在使用 IntelliJ 顺序运行所有测试时遇到问题,而 beforeAll 和 afterAll 似乎没有按预期工作(但在单独运行时确实有效)。
我正在考虑创建一个父规范,该规范创建一个所有子规范的列表,然后执行它们 - 希望这样我有更多的控制权。
我的“孩子”规范使用 mutable.Specification 并遵循以下原则:
class BookmarkSpecs2(implicit ec: ExecutionEnv) extends Specification
with BeforeAfterAll
with Matchers
with FutureMatchers
with EmbedMongod {
val prefix = "mongodb"
val database = "bcTest"
val domain = "localhost"
val port = 12340
sequential
"Update items" should {
"adding" in {
...
}
}
注意包含类的变量(implicit ec: ExecutionEnv)
对于我一直在尝试的父规范:
import org.specs2.Specification
import org.specs2.concurrent.ExecutionEnv
import org.specs2.specification.core.SpecStructure
class AllTestsSpecs2(implicit ec: ExecutionEnv) extends Specification {
def is: SpecStructure = sequential ^ s2"""
${"bookmark" ~ bm}
"""
def bm = new BookmarkSpecs2()
}
当通过 IntelliJ 执行规范时,它显示:
Testing started at 10:36 AM ...
/opt/jdk/jdk8u265-b01/bin/java -javaagent:/home/colinbester/Projects/idea-IC-202.6397.94/lib/idea_rt.jar=46535:/home/colinbester/Projects/idea-IC-202.6397.94/bin -Dfile.encoding=UTF-8 -classpath ... org.jetbrains.plugins.scala.testingSupport.specs2.Specs2Runner -s com.besterdesigns.bc.rest.AllTestsSpecs2 -showProgressMessages true
Process finished with exit code 0
没有实际运行任何子测试。
很确定我在这里遗漏了一些东西,并希望朝着正确的方向轻推。
【问题讨论】:
-
您可以尝试将
all作为参数传递吗?在 Intellij 中,您需要将-Dspecs2.all指定为 Java 参数。all将执行父规范中的所有链接规范。 -
你是个明星,我正在拔头发 - 这解决了我的问题。
-
太好了,我把它变成了正确的答案
标签: intellij-idea specs2