Menu

#930 false positive in JUnit4TestShouldUseBeforeAnnotation

open
pmd (543)
5
2012-10-07
2010-06-17
No

JUnit4 does not require particular method names. The current JUnit4TestShouldUseBeforeAnnotation (PDM 4.0) tests for:

//ClassOrInterfaceBodyDeclaration[MethodDeclaration/MethodDeclarator[@Image='setUp']]
[count(Annotation/MarkerAnnotation/Name[@Image='Before'])=0]

which, IMHO, causes a false positive if the setUp method is annotated with @BeforeClass. The issue could be resolved by changing the XPath to something along the lines of:

//ClassOrInterfaceBodyDeclaration[MethodDeclaration/MethodDeclarator[@Image='setUp']]
[count(Annotation/MarkerAnnotation/Name[@Image='Before'])=0&count(Annotation/MarkerAnnotation/Name[@Image='BeforeClass'])=0]

Given setUp() in JUnit3 was tied to what is @Before in JUnit4, I guess it makes sense to suggest @Before.

Discussion


Log in to post a comment.