From 5dd49a1c80490231312213aba21cd1df40fc4b43 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Wed, 24 Oct 2018 13:39:11 +0200 Subject: [PATCH] Log if the test failed in LoggingFreeSpecLike --- .../scalatest/LoggingFreeSpec.scala | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/blended.testsupport/src/main/scala/blended/testsupport/scalatest/LoggingFreeSpec.scala b/blended.testsupport/src/main/scala/blended/testsupport/scalatest/LoggingFreeSpec.scala index e1fe45c96..a4cb3467a 100644 --- a/blended.testsupport/src/main/scala/blended/testsupport/scalatest/LoggingFreeSpec.scala +++ b/blended.testsupport/src/main/scala/blended/testsupport/scalatest/LoggingFreeSpec.scala @@ -1,6 +1,7 @@ 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 @@ -8,27 +9,31 @@ 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