有没有办法在SCALATEST中访问测试状态(通过,失败)

时间:2018-08-15 06:42:05

标签: scalatest

我正在将Scalatest的AsyncFeatureSpecparallelExecution一起使用。 我们有一个要求,我需要在每次测试用例执行结束时立即记录整个测试日志。

以下是我用来实现该目标的代码的一部分

trait BaseFeatureSpec extends AsyncFeatureSpec
  with BeforeAndAfterAllConfigMap
  with BeforeAndAfter
  with BeforeAndAfterEach
  with Matchers
  with OptionValues
  with Inside
  with Inspectors
  with GivenWhenThen
  with ParallelTestExecution
   { this: Suite =>

     private val logger = MyLogger(this.getClass)
     val testRunID = System.getProperty("testRunID")
     val fulllog = new StringBuilder // this builds the log inside test 

  override def afterEach() {

    implicit val loggingContext = MyLoggerFactory(
    Map(
      "testid" -> getRandomUUID,
      "TestRunId"-> testRunID
    )
    )
    fulllog.append("***************************************END OF TEST ***************************************")
    logger.info(fulllog.mkString(""))
    try super.afterEach()
    finally fulllog.clear()
  }
}

如果我可以在afterEach方法中获得实际的测试名称和运行状态,那就太好了。这可以实现吗?达到要求的最佳方法是什么?

0 个答案:

没有答案
相关问题