diktat
diktat copied to clipboard
`BACKTICKS_PROHIBITED` false positives for JUnit 5 tests annotated with `@ParameterizedTest` and `@Nested`
False-positives are reported for JUnit 5 test classes and methods annotated with @ParameterizedTest
and/or @Nested
:
import org.junit.jupiter.api.Nested
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource
class Test {
@Nested
inner class `Test group 1` {
@ParameterizedTest
@ValueSource(booleans = [false, true])
fun `test 1`(flag: Boolean) {
}
@ParameterizedTest
@ValueSource(booleans = [false, true])
fun `test 2`(flag: Boolean) {
}
}
@Nested
inner class `Test group 2` {
@ParameterizedTest
@ValueSource(booleans = [false, true])
fun `test 1`(flag: Boolean) {
}
@ParameterizedTest
@ValueSource(booleans = [false, true])
fun `test 2`(flag: Boolean) {
}
}
}
Such occurrences should never be reported, except when an element (a class or a test method) is annotated with @DisplayName
(which renders the backticks useless).
The issue can be worked around by modifying the default configuration:
# Checks that backticks (``) are not used in the identifier name, except the case when it is test method (marked with @Test annotation)
- name: BACKTICKS_PROHIBITED
enabled: true
# all code blocks annotated with @Nested, @ParameterizedTest (JUnit 5) will
# be ignored and not checked.
ignoreAnnotated: [ Nested, ParameterizedTest ]
Environment information
- diktat version: 1.2.0
- build tool (maven/gradle): Maven
- how is diktat run (CLI, plugin, etc.): Maven plug-in
- kotlin version: 1.7.0
- operating system: Windows
The issue can be worked around by modifying the default configuration:
@0x6675636b796f75676974687562 I think can be considered not a workaround but rather the entire solution, because it's exactly what we have introduced ignoreAnnotated
mechanism for. Are you planning on including logic with Junit annotations into the rule itself? I think it's too specific
Closing as not planned.