显示Scalatest结果的其他方法

时间:2019-06-27 12:14:06

标签: scala scalatest

我正在考虑使用Scalatest建立一个自动验收测试套件,并将结果输出到一个简单的Web仪表板中(例如,打印每个方案文本,并在其旁边打上复选标记或叉号)。是否有内置功能可用于显示普通输出的替代方法,还是我需要自行输出和解析日志?

2 个答案:

答案 0 :(得分:2)

考虑创建自定义Reporter

  

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

覆盖apply方法以处理test events

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

通过-C参数将SBT配置为使用自定义报告程序:

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

这是一个有效的示例scalatest-custom-reporter-example

答案 1 :(得分:0)

在Mario回答之后,我再次浏览了文档,似乎实际上是针对诸如我的用例的内置功能

http://www.scalatest.org/user_guide/using_scalatest_with_sbt

Using Reporters
You can use ScalaTest's reporters by specifying the passing the following arguments to ScalaTest:

-f[configs...] <filename> - causes test results to be written to the named file
-u <directory> - causes test results to be written to junit-style xml files in the named directory
-h <directory> [-Y ] - causes test results to be written to HTML files in the named directory, optionally included the specified CSS file
-a <number of files to archive> - causes specified number of old summary and durations files to be archived (in summaries/ and durations/ subdirectories) for dashboard reporter (default is two)
-o[configs...] - causes test results to be written back to sbt, which usually displays it on the standard output
-e[configs...] - causes test results to be written to the standard error
-k <host> <port> - causes test results to be written to socket in the named host and port number, using XML format
-K <host> <port> - causes test results to be written to socket in the named host and port number, using Java object binary format
-C[configs...] <reporterclass> - causes test results to be reported to an instance of the specified fully qualified Reporter class name