I take the chance to add another use case. We have test classes that implement certain life-cycle methods. In delayedInit the life-cycle methods are called in proper sequence including the actual test code:
**
* Base trait for tests that takes care that the life-cycle methods of a test are called in proper sequence.
*
* Required components can be mixed into this trait. Read the documentation of the [[WithLifecycle]] trait
* carefully in order to implement proper startup and shutdown sequences.
*/
trait InnerTest extends WithLifecycle with WithLog with DelayedInit {
override def delayedInit(testCode: => Unit): Unit = {
tryFinally {
log.debug(s"before inner test - class: ${getClass.getSimpleName}")
startup()
log.debug(s"execute inner test - class: ${getClass.getSimpleName}")
testCode
log.debug(s"shutdown inner test - class: ${getClass.getSimpleName}")
shutdown()
log.debug(s"wait for completion of inner test - class: ${getClass.getSimpleName}")
waitForCompletion()
log.debug(s"inner test completed regularly - class: ${getClass.getSimpleName}")
} {
log.debug(s"cleanup inner test - class: ${getClass.getSimpleName}")
cleanup()
log.debug(s"after inner test - class: ${getClass.getSimpleName}")
}
}
}