显示 Scalatest 结果的替代方法 [英] Alternative ways to display Scalatest results

查看:47
本文介绍了显示 Scalatest 结果的替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑使用 Scalatest 设置一个自动化验收测试套件,并将结果输出到一个简单的 Web 仪表板中(比如打印每个场景文本,并在它们旁边堆放复选标记或叉号).是否有内置功能可以用于显示普通输出的替代方式,还是需要自己输出和解析日志?

I am thinking about setting up an automated acceptance testing suite with Scalatest and output the results into a simple web dashboard (say print each scenario text stacked with check marks or crosses next to them). Is there a built-in functionality I can use for alternative ways to display the ordinary output or would I need to output and parse the logs myself?

推荐答案

考虑创建自定义 Reporter:

Consider creating a custom Reporter:

特征,其实例收集正在运行的测试套件的结果并以某种方式向用户展示这些结果.

Trait whose instances collect the results of a running suite of tests and presents those results in some way to the user.

覆盖 apply 方法来处理 测试事件:

Override apply method to handle test events:

class MyReporter extends Reporter {
  def apply(event: Event): Unit = {
    event match {
      case event: InfoProvided => 
      case event: TestFailed =>
      case ...
      case _ =>
    }
  }
}

通过 -C 参数配置 SBT 以使用自定义报告器:

Configure SBT to use custom reporter like so via -C argument:

Test / testOptions += Tests.Argument("-C", "example.MyReporter")

这是一个工作示例 scalatest-custom-reporter-example.

这篇关于显示 Scalatest 结果的替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆