Rename JUnit4TestShouldUseAfterAnnotation
- Call it JUnitTestShouldUseAfterAnnotation instead as it not only applies to JUnit4 - Improve the doc to further clarify it's usages
This commit is contained in:
@ -666,15 +666,20 @@ public class GoodTest {
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="JUnit4TestShouldUseAfterAnnotation"
|
||||
<rule name="JUnit4TestShouldUseAfterAnnotation" deprecated="true" ref="JUnitTestShouldUseAfterAnnotation" />
|
||||
|
||||
<rule name="JUnitTestShouldUseAfterAnnotation"
|
||||
language="java"
|
||||
since="4.0"
|
||||
message="JUnit 4 tests that clean up tests should use the @After annotation, JUnit5 tests should use @AfterEach or @AfterAll"
|
||||
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#junit4testshoulduseafterannotation">
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#junittestshoulduseafterannotation">
|
||||
<description>
|
||||
In JUnit 3, the tearDown method was used to clean up all data entities required in running tests.
|
||||
JUnit 4 skips the tearDown method and executes all methods annotated with @After after running each test.
|
||||
This rule detects methods called tearDown() that are not properly annotated as a setup method.
|
||||
This is primarily intended to assist in upgrading from JUnit 3, where tear down methods were required to be called tearDown().
|
||||
To a lesser extent, this may help detect omissions under newer JUnit versions, as long as you are following this convention to name the methods.
|
||||
|
||||
JUnit 4 will only execute methods annotated with @After after running each test.
|
||||
JUnit 5 introduced @AfterEach and @AfterAll annotations to execute methods after each test or after all tests in the class, respectively.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
|
@ -9,7 +9,7 @@ import org.junit.Before;
|
||||
|
||||
import net.sourceforge.pmd.test.PmdRuleTst;
|
||||
|
||||
class JUnit4TestShouldUseAfterAnnotationTest extends PmdRuleTst {
|
||||
class JUnitTestShouldUseAfterAnnotationTest extends PmdRuleTst {
|
||||
// no additional unit tests
|
||||
|
||||
public static class BaseTest {
|
Reference in New Issue
Block a user