Skip to content

Files

Latest commit

 

History

History
31 lines (22 loc) · 768 Bytes

UnnecessaryFail.md

File metadata and controls

31 lines (22 loc) · 768 Bytes

Pattern: Unnecessary Assert.fail()

Issue: -

Description

In a unit test, catching an exception and immediately calling Assert.fail() is pointless and hides the stack trace. It is better to re-throw the exception or not catch the exception at all.

This rule sets the default value of the applyToClassNames property to only match class names ending in 'Test', 'Tests' or 'TestCase'.

Example of violations:

public void testSomething() {
    try {
        something()
    } catch (Exception e) {
        fail(e.message)
    }

    try {
        something()
    } catch (Exception e) {
        fail()
    }
}

Further Reading