46 lines
1.0 KiB
Plaintext
46 lines
1.0 KiB
Plaintext
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:
|
|
|
|
----
|
|
public void setUp() { ... } // Noncompliant; should be annotated with @Before
|
|
public void tearDown() { ... } // Noncompliant; should be annotated with @After
|
|
----
|
|
|
|
* JUnit5:
|
|
|
|
----
|
|
public void setUp() { ... } // Noncompliant; should be annotated with @BeforeEach
|
|
public void tearDown() { ... } // Noncompliant; should be annotated with @AfterEach
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
* JUnit4:
|
|
|
|
----
|
|
@Before
|
|
public void setUp() { ... }
|
|
|
|
@After
|
|
public void tearDown() { ... }
|
|
----
|
|
|
|
* JUnit5:
|
|
|
|
----
|
|
@BeforeEach
|
|
void setUp() { ... }
|
|
|
|
@AfterEach
|
|
void tearDown() { ... }
|
|
----
|
|
|