9.8: Continuing After a Failure

Pharo by Example 5.0 · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-SA 3.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    9.8: Continuing After a Failure

    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 was last modified on Sat, 19 Dec 2020 08:13:49 GMT and 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.