Skip to content

Files

Latest commit

 

History

History
36 lines (25 loc) · 905 Bytes

ChainedTest.md

File metadata and controls

36 lines (25 loc) · 905 Bytes

Pattern: Chained test

Issue: -

Description

A test method that invokes another test method is a chained test; the methods are dependent on one another. Tests should be isolated, and not be dependent on one another.

Example of violations:

class SomeTest extends GroovyTestCase {
    public void testFoo() {

        // violations, calls test method on self
        5.times { testBar() }
        5.times { this.testBar() }

        // OK, no violation: one arg method is not actually a test method
        5.times { testBar(it) }
    }

    private static void assertSomething() {
        testBar() // violation, even if in helper method
        this.testBar() // violation, even if in helper method
    }

    public void testBar() {
        // ...
    }
}

Further Reading