Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log if the test failed in LoggingFreeSpecLike
- Loading branch information
Showing
1 changed file
with
15 additions
and
10 deletions.
There are no files selected for viewing
25 changes: 15 additions & 10 deletions
25
blended.testsupport/src/main/scala/blended/testsupport/scalatest/LoggingFreeSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |