【问题标题】:Running list of specs2 specifications from a single spec2s parent specification来自单个 spec2s 父规范的 specs2 规范的运行列表
【发布时间】: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


【解决方案1】:

可以通过传递all 参数来执行链接的规范(可用参数的列表是可用的here)。

在 IntelliJ specs2 中需要将属性指定为 Java 系统属性,因此您需要在 IntelliJ 运行配置中指定 -Dspecs2.all

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-03
    • 2017-04-21
    • 1970-01-01
    相关资源
    最近更新 更多