Class that allows multiple assertions to be performed within a test, with any failures accumulated and reported together at the end of the test.
Class that allows multiple assertions to be performed within a test, with any failures accumulated and reported together at the end of the test.
See the main documentation for trait Checkpoints for more information and an example.
Trait providing class
Checkpoint, which enables multiple assertions to be performed within a test, with any failures accumulated and reported together at the end of the test.Because ScalaTest uses exceptions to signal failed assertions, normally execution of a test will stop as soon as the first failed assertion is encountered. Trait
Checkpointsprovides an option when you want to continue executing the remainder of the test body, or part of it, even if an assertion has already failed in that test.To use a
Checkpoint(once you've mixed in or imported the members of traitCheckpoints), you first need to create one, like this:Then give the
Checkpointassertions to execute by passing them (via a by-name parameter) to itsapplymethod, like this:val (x, y) = (1, 2) cp { x should be < 0 } cp { y should be > 9 }Both of the above assertions will fail, but it won't be reported yet. The
Checkpointwill execute them right away, each time itsapplymethod is invoked. But it will catch theTestFailedExceptionsand save them, only reporting them later whenreportAllis invoked. Thus, at the end of the test, you must callreportAll, like this:This
reportAllinvocation will complete abruptly with aTestFailedExceptionwhose message includes the message, source file, and line number of each of the checkpointed assertions that previously failed. For example:Make sure you invoke
reportAllbefore the test completes, otherwise any failures that were detected by theCheckpointwill not be reported.Note that a
Checkpointwill catch and record for later reporting (viareportAll) exceptions that mix inStackDepthexcept forTestCanceledException,TestRegistrationClosedException,NotAllowedException, andDuplicateTestNameException. If a block of code passed to aCheckpoint'sapplymethod completes abruptly with any of theStackDepthexceptions in the previous list, or any non-StackDepthexception, that invocation of theapplymethod will complete abruptly with the same exception immediately. Unless you putreportAllin a finally clause and handle this case, such an unexpected exception will cause you to lose any information about assertions that failed earlier in the test and were recorded by theCheckpoint.