2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-04-28 16:49:39 +02:00
Annotating unit tests with more than one test-related annotation is not only useless but could also result in unexpected behavior like failing tests or unwanted side-effects.
This rule reports an issue when a test method is annotated with more than one of the following competing annotation:
* @Test
* @RepeatedTest
* @ParameterizedTest
* @TestFactory
* @TestTemplate
2021-04-28 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
@Test
@RepeatedTest(2) // Noncompliant, this test will be repeated 3 times
void test() { }
@ParameterizedTest
@Test
@MethodSource("methodSource")
void test2(int argument) { } // Noncompliant, this test will fail with ParameterResolutionException
----
2021-04-28 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
@RepeatedTest(2)
void test() { }
@ParameterizedTest
@MethodSource("methodSource")
void test2(int argument) { }
----
2021-04-28 18:08:03 +02:00
2021-09-20 15:38:42 +02:00
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== Message
Remove one of these conflicting annotations.
=== Highlighting
Primary location: method name
Secondaries: test annotations
2021-09-20 15:38:42 +02:00
endif::env-github,rspecator-view[]