【问题标题】:Scala Specs2 (version 3.x) - How create and work with Notifier?Scala Specs2 (version 3.x) - 如何创建和使用通知程序?
【发布时间】:2015-03-12 12:11:23
【问题描述】:

如何正确使用 Scala Specs2 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
    }
  }
}

出现错误:

错误:(12, 23) 找不到证据参数的隐含值 类型 org.specs2.execute.AsResult[TestSpec.this.Context] 在新上下文中“添加两个数字”{

【问题讨论】:

  • 这与通知程序无关。您收到此消息是因为 Context 需要扩展 org.specs2.specification.Scope 才能用作示例正文。
  • 目前我还没有使用规范参数来确定如何运行它。所以通知器参数必须在命令行上传递。
  • 感谢 Eric,现在可以使用了。下次会记得的。

标签: scala specs2


【解决方案1】:

Notifier 的 3.0.x 文档是 here(对应的 API 是 there)。

基本上你需要定义一个实现Notifier trait 的类,然后用notifier 参数调用它:

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

您可以查看ConsoleNotifier 以获得一个简单的实现示例。

【讨论】:

  • 感谢 Eric,我成功完成了基本的通知程序,但是,它在我拥有的更具体的情况下不起作用。已编辑问题,感谢您的进一步帮助。
猜你喜欢
  • 1970-01-01
  • 2019-09-13
  • 1970-01-01
  • 2021-12-13
  • 2015-08-03
  • 1970-01-01
  • 2021-01-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多