Skip to content

Commit

Permalink
Log if the test failed in LoggingFreeSpecLike
Browse files Browse the repository at this point in the history
  • Loading branch information
lefou committed Oct 24, 2018
1 parent 024ea3a commit 5dd49a1
Showing 1 changed file with 15 additions and 10 deletions.
@@ -1,34 +1,39 @@
package blended.testsupport.scalatest

import blended.util.logging.Logger
import org.apache.camel.FailedToStartRouteException
import org.scalatest.Args
import org.scalatest.FreeSpec
import org.scalatest.FreeSpecLike
import org.scalatest.Status
import org.scalatest.Suite

/**
* Same as [[org.scalatest.FreeSpecLike]] but log the start and the end of each test case to SLF4j in Debug level.
*
* @see LoggingFreeSpec
*/
* Same as [[org.scalatest.FreeSpecLike]] but log the start and the end of each test case to SLF4j in Debug level.
*
* @see LoggingFreeSpec
*/
trait LoggingFreeSpecLike extends FreeSpecLike {

abstract protected override def runTest(testName: String, args: Args): Status = {
val log: Logger = Logger[this.type]
log.info(s"Starting test case: ${testName}")
var reported = false
try {
super.runTest(testName, args)
val status = super.runTest(testName, args)
log.info(s"${if (status.succeeds()) "Finished" else "Failed"} test case: ${testName}")
reported = true
status
} finally {
log.info(s"Finished test case: ${testName}")
if (!reported) log.info(s"Finished test case: ${testName}")
}
}

}

/**
* Same as [[org.scalatest.FreeSpec]] but log the start and the end of each test case to SLF4j in Debug level.
*
* @see LoggingFreeSpecLike
*/
* Same as [[org.scalatest.FreeSpec]] but log the start and the end of each test case to SLF4j in Debug level.
*
* @see LoggingFreeSpecLike
*/
class LoggingFreeSpec extends FreeSpec with LoggingFreeSpecLike

0 comments on commit 5dd49a1

Please sign in to comment.