Skip to main content
Engineering LibreTexts

9.8: Continuing After a Failure

  • Page ID
    43064
    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    SUnit also allows us to specify whether or not a test should continue after a failure. This is a really powerful feature that uses Pharo’s exception mechanisms. To see what this can be used for, let’s look at an example. Consider the following test expression:

    aCollection do: [ :each | self assert: each even ]
    

    In this case, as soon as the test finds the first element of the collection that isn’t even, the test stops. However, we would usually like to continue, and see both how many elements, and which elements, aren’t even (and maybe also log this information). You can do this as follows:

    aCollection do: [ :each |
        self
            assert: each even
            description: each printString, ' is not even'
            resumable: true ]
    

    This will print out a message on your logging stream for each element that fails. It doesn’t accumulate failures, i.e, if the assertion fails 10 times in your test method, you’ll still only see one failure. All the other assertion methods that we have seen are not resumable by default; assert: p description: s is equivalent to assert: p description: s resumable: false.


    This page titled 9.8: Continuing After a Failure is shared under a CC BY-SA 3.0 license and was authored, remixed, and/or curated by via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.