how to dermine if a test failed in afterEach of a FunSpec in scalatest

拟墨画扇 提交于 2020-01-21 10:08:26

问题


In scalatest using FunSpec I have some code that fires in the afterEach. I would like to execute some code to get a screenshot only when the test fails. Just about everything I have looked at tries to solve this by putting asserts in try blocks which seems awful. Is there anything like onTestFailure in TestNG or a context I can get like RSpec to determine if the test failed? Looking at the scala doc I see a implementation that takes a configMap, but that is empty when I run the test. Any help would be appreciated.


回答1:


pretty sure I figured it out. coming from a TestNG background it seemed weird to have to mess with fixtures to accomplish it. I suspect others with a background like mine may also look in all the wrong places as well, so going to leave this here to help others:

override def withFixture(test: NoArgTest) = { // after
   val outcome = super.withFixture(test)
   outcome match {
     case Failed(ex) =>
     // log ex (the exception) and a screenshot
   }
   outcome
}


来源:https://stackoverflow.com/questions/37555933/how-to-dermine-if-a-test-failed-in-aftereach-of-a-funspec-in-scalatest

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!