Skip to content

Files

Latest commit

 

History

History
28 lines (18 loc) · 769 Bytes

JUnitPublicField.md

File metadata and controls

28 lines (18 loc) · 769 Bytes

Pattern: JUnit - public field

Issue: -

Description

Checks for public fields on a JUnit test class. There is usually no reason to have a public field (even a constant) on a test class.

Fields within interfaces and fields annotated with @Rule are ignored.

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

Example of violations:

import org.junit.Test
class SomeTestCase {
    public int count                        // violation
    public static final MAX_VALUE = 1000    // violation

    @Test
    void testMe() { }
}

Further Reading