Rule "TestCases should contain tests" to also support JUnit 5 @ParameterizedTest

482 views
Skip to first unread message

gunnar....@googlemail.com

unread,
Jun 21, 2017, 5:56:19 AM6/21/17
to SonarQube
Rule "TestCases should contain tests" (squid:S2187) currently supports "@Test" annotations of JUnit 4+5 + TestNG, but not ParameterizedTest of JUnit 5, which leads to an issue if all tests of a testclass happen to be parameterized.

Responsible code is sonar-java/java-checks/src/main/java/org/sonar/java/checks/NoTestInTestClassCheck.java

private static boolean isTestAnnotation(Type type) {
return type.is("org.junit.Test") || type.is("org.testng.annotations.Test") || type.is("org.junit.jupiter.api.Test")
|| type.symbol().metadata().isAnnotatedWith("org.junit.jupiter.api.Test");
}

I'd be happy to implement and contribute this myself, addition could be as simple as extending following method to also check for type.is("org.junit.jupiter.api.ParameterizedTest")

or to be a little more generic to check for type.symbol().metadata().isAnnotatedWith("org.junit.jupiter.api.TestTemplate")

Nicolas Peru

unread,
Jul 12, 2017, 10:32:58 AM7/12/17
to gunnar....@googlemail.com, SonarQube
Hi, 

I created a ticket to handle what I understood from your feedback :  https://jira.sonarsource.com/browse/SONARJAVA-2390
Given that we have to work on that rule for other junit5 topics, could you specify a complete testcase where an issue is raised and it should not if it doesn't match what is in that ticket ? 
If i'm correct you are talking about class that contains method(s) annotated with org.junit.jupiter.param.ParameterizedTest

Cheers ,



--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/f6b9f0dc-450b-4f3f-9217-060f841fb74d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Nicolas Peru | SonarSource
Reply all
Reply to author
Forward
0 new messages