显示 Scalatest 结果的替代方法

Alternative ways to display Scalatest results

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

考虑创建自定义 Reporter

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

覆盖 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

我在 Mario 的回答后再次查看了文档,似乎实际上 built-in 功能适用于像我这样的用例

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