Scala Specs2(版本 3.x)- 如何创建和使用通知程序?

Scala Specs2 (version 3.x) - How create and work with Notifier?

如何正确使用 Scala Specs2 Notifier

还没有找到任何示例来演示 Notifier 特性的一些用例。

编辑:

按如下方式使用 Notifier 时,它完美地工作:

class TestSpec extends TestUtils {

  "Arithmetic" should {
    "add two numbers" in {
      1 + 1 mustEqual 2
    }

    "add three numbers" in {
      1 + 1 + 1 mustEqual 3
    }
  }
}
class TestNotifier extends ConsoleNotifier

trait TestUtils extends Specification {
  args.report(notifier = "com.stuff.TestNotifier")
}

但是,当我尝试为每个测试添加一些新的上下文创建时:

class TestSpec extends TestUtils {

  trait Context {
    val justNum = 4
  }

  "Arithmetic" should {
    "add two numbers" in new Context {
      1 + 1 mustEqual 2
    }

    "add three numbers" in new Context {
      1 + 1 + 1 mustEqual 3
    }
  }
}

出现错误:

Error:(12, 23) could not find implicit value for evidence parameter of type org.specs2.execute.AsResult[TestSpec.this.Context] "add two numbers" in new Context {

Notifier 的 3.0.x 文档是 here (and the corresponding API is there).

基本上你需要定义一个 class 来实现 Notifier 特性,然后用 notifier 参数调用它:

sbt> testOnly *BinarySpec* -- notifier org.acme.reporting.FtpNotifier

您可以查看 ConsoleNotifier 以获得简单的实施示例。