问题描述
我目前正在使用大量specs2规范测试进行基于Maven的Scala项目,并且正在将Intellij 2020.2和Scala 2.12.10与specs2版本4.9.4配合使用
我能够运行每个规范没有问题,但是在使用IntelliJ依次运行所有测试时出现了问题,而beforeAll和afterall似乎没有按预期工作(但单独运行时确实可以工作)。
我当时正在考虑创建一个父级规范,该规范会创建所有子级规范的列表,然后执行它们-希望以此方式我可以控制更多。
我的'儿童'规范使用可变的。规范并遵循:
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
参数来执行链接的规范(可用参数列表可用here)。
在IntelliJ specs2中,需要将属性指定为Java系统属性,因此您需要在IntelliJ运行配置中指定-Dspecs2.all
。