Альтернативные способы отображения Scalatest результатов - PullRequest
2 голосов
/ 27 июня 2019

Я подумываю о создании пакета автоматического приемочного тестирования с помощью Scalatest и вывода результатов на простую веб-панель управления (скажем, распечатывать каждый текст сценария, сложенный галочками или крестиками рядом с ними).Есть ли встроенная функциональность, которую я могу использовать для альтернативных способов отображения обычного вывода, или мне нужно было бы выводить и анализировать журналы самостоятельно?

Ответы [ 2 ]

2 голосов
/ 27 июня 2019

Рассмотрите возможность создания пользовательской Reporter:

Черта, экземпляры которой собирают результаты запущенного набора тестов и каким-то образом представляют эти результаты пользователю.

Переопределить apply метод для обработки тестовых событий :

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

Сконфигурировать SBT для использования настраиваемого репортера, например, через аргумент -C:

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

Вот рабочий пример scalatest-custom-reporter-example .

0 голосов
/ 27 июня 2019

Я снова просмотрел документацию после ответа Марио и, похоже, на самом деле есть встроенная функциональность для вариантов использования, подобных моему

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
...