
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
78 lines
1.5 KiB
Plaintext
78 lines
1.5 KiB
Plaintext
== Why is this an issue?
|
|
|
|
The ``++setUp()++`` and ``++tearDown()++`` methods (initially introduced with JUnit3 to execute a block of code before and after each test) need to be correctly annotated with the equivalent annotation in order to preserve the same behavior when migrating from JUnit3 to JUnit4 or JUnit5.
|
|
|
|
|
|
This rule consequently raise issues on ``++setUp()++`` and ``++tearDown()++`` methods which are not annotated in test classes.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
* JUnit4:
|
|
|
|
[source,java]
|
|
----
|
|
public void setUp() { ... } // Noncompliant; should be annotated with @Before
|
|
public void tearDown() { ... } // Noncompliant; should be annotated with @After
|
|
----
|
|
|
|
* JUnit5:
|
|
|
|
[source,java]
|
|
----
|
|
public void setUp() { ... } // Noncompliant; should be annotated with @BeforeEach
|
|
public void tearDown() { ... } // Noncompliant; should be annotated with @AfterEach
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
* JUnit4:
|
|
|
|
[source,java]
|
|
----
|
|
@Before
|
|
public void setUp() { ... }
|
|
|
|
@After
|
|
public void tearDown() { ... }
|
|
----
|
|
|
|
* JUnit5:
|
|
|
|
[source,java]
|
|
----
|
|
@BeforeEach
|
|
void setUp() { ... }
|
|
|
|
@AfterEach
|
|
void tearDown() { ... }
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
setUp: Annotate this method with @Before/@BeforeEach (JUnit4/JUnit5)
|
|
|
|
tearDown: Annotated this method with @After/@AfterEach (JUnit4/JUnit5)
|
|
|
|
|
|
=== Highlighting
|
|
|
|
method name
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== relates to: S2391
|
|
|
|
endif::env-github,rspecator-view[]
|