BAEL-1843 - JUnit4 -> JUnit5 migration guide (#4816)

* Added code for the migration from JUnit 4 to JUnit 5

* Add example for Rule migration support

* Add fix to access modifiers to test methods

* Remove wrong header

* Add junit5-migration module and its code snippets

* Add module configuration to pom

* Remove test classes that were added for the migration from JUnit 4 to JUnit 5 article (moved under correct module)
This commit is contained in:
Carlo Corti
2018-08-06 23:38:54 +02:00
committed by Grzegorz Piwowarek
parent b5d5a4949f
commit b7355cbab0
25 changed files with 656 additions and 9 deletions
+6
View File
@@ -33,6 +33,12 @@
<version>${junit.vintage.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-migrationsupport</artifactId>
<version>${junit.vintage.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
@@ -11,14 +11,17 @@ import java.util.Optional;
import java.util.function.BooleanSupplier;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
/**
* Unit test that demonstrate the different assertions available within JUnit 4
*/
@DisplayName("Test case for assertions")
public class AssertionUnitTest {
@Test
@DisplayName("Arrays should be equals")
public void whenAssertingArraysEquality_thenEqual() {
char[] expected = {'J', 'u', 'p', 'i', 't', 'e', 'r'};
char[] actual = "Jupiter".toCharArray();
@@ -27,6 +30,7 @@ public class AssertionUnitTest {
}
@Test
@DisplayName("The area of two polygons should be equal")
public void whenAssertingEquality_thenEqual() {
float square = 2 * 2;
float rectangle = 2 * 2;
@@ -10,13 +10,13 @@ import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
public class NestedUnitTest {
Stack<Object> stack;
boolean isRun = false;
@Test
@DisplayName("is instantiated with new Stack()")
void isInstantiatedWithNew() {
new Stack<Object>();
new Stack<>();
}
@Nested
@@ -25,7 +25,7 @@ public class NestedUnitTest {
@BeforeEach
void init() {
stack = new Stack<Object>();
stack = new Stack<>();
}
@Test
@@ -1,4 +1,4 @@
package com.baeldung;
package com.baeldung.migration.junit5;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
@@ -10,19 +10,19 @@ import org.junit.jupiter.api.Test;
public class AssumptionUnitTest {
@Test
void trueAssumption() {
assumeTrue(5 > 1);
public void trueAssumption() {
assumeTrue(5 > 1, () -> "5 is greater the 1");
assertEquals(5 + 2, 7);
}
@Test
void falseAssumption() {
assumeFalse(5 < 1);
public void falseAssumption() {
assumeFalse(5 < 1, () -> "5 is less then 1");
assertEquals(5 + 2, 7);
}
@Test
void assumptionThat() {
public void assumptionThat() {
String someString = "Just a string";
assumingThat(someString.equals("Just a string"), () -> assertEquals(2 + 2, 4));
}