Add tests and enhance descriptions for JUnit4TestShouldUseBeforeAnnotation,JUnit4TestShouldUseAfterAnnotation (https://github.com/pmd/pmd/issues/940)
This commit is contained in:
1 parent
664d76e072
commit
2ead1237d6
3 files changed
+62
-4
No files matched your search
@@ -445,12 +445,13 @@ public class GoodTest {
|
||||
<rule name="JUnit4TestShouldUseAfterAnnotation"
|
||||
language="java"
|
||||
since="4.0"
|
||||
message="JUnit 4 tests that clean up tests should use the @After annotation"
|
||||
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.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#junit4testshoulduseafterannotation">
|
||||
<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
|
||||
JUnit 4 skips the tearDown method and executes all 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>
|
||||
<properties>
|
||||
@@ -483,12 +484,13 @@ public class MyTest2 {
|
||||
<rule name="JUnit4TestShouldUseBeforeAnnotation"
|
||||
language="java"
|
||||
since="4.0"
|
||||
message="JUnit 4 tests that set up tests should use the @Before annotation"
|
||||
message="JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#junit4testshouldusebeforeannotation">
|
||||
<description>
|
||||
In JUnit 3, the setUp method was used to set up all data entities required in running tests.
|
||||
JUnit 4 skips the setUp method and executes all methods annotated with @Before before all tests
|
||||
JUnit 4 skips the setUp method and executes all methods annotated with @Before before all tests.
|
||||
JUnit 5 introduced @BeforeEach and @BeforeAll annotations to execute methods before each test or before all tests in the class, respectively.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
|
||||
+28
@@ -61,6 +61,34 @@ public class Foo {
|
||||
public void tearDown(Method m) {
|
||||
//...
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>#940 False positive with JUnit4TestShouldUseBeforeAnnotation when JUnit5's 'AfterEach' is used</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
|
||||
public class Foo {
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
//...
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>#940 False positive with JUnit4TestShouldUseBeforeAnnotation when JUnit5's 'AfterAll' is used</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
|
||||
public class Foo {
|
||||
@AfterAll
|
||||
public void tearDown() {
|
||||
//...
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
+28
@@ -73,6 +73,34 @@ public class Foo {
|
||||
public void setUp(Method m) {
|
||||
//...
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>#940 False positive with JUnit4TestShouldUseBeforeAnnotation when JUnit5's 'BeforeEach' is used</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
public class Foo {
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
//...
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>#940 False positive with JUnit4TestShouldUseBeforeAnnotation when JUnit5's 'BeforeAll' is used</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
||||
public class Foo {
|
||||
@BeforeAll
|
||||
public void setUp() {
|
||||
//...
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
Reference in new issue
Block a user