Merge branch 'master' into master

This commit is contained in:
Loredana Crusoveanu
2019-05-11 16:01:13 +03:00
committed by GitHub
66 changed files with 1034 additions and 140 deletions
@@ -3,10 +3,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>junit-5-configuration</artifactId>
<artifactId>junit-5-basics</artifactId>
<version>1.0-SNAPSHOT</version>
<name>junit-5-configuration</name>
<description>Intro to JUnit 5 configuration</description>
<name>junit-5-basics</name>
<description>Intro to JUnit 5</description>
<parent>
<groupId>com.baeldung</groupId>
+12 -2
View File
@@ -21,24 +21,34 @@
<artifactId>junit-platform-engine</artifactId>
<version>${junit.platform.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.vintage.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-migrationsupport</artifactId>
<version>${junit.vintage.version}</version>
@@ -2,7 +2,21 @@ package com.baeldung;
import static java.time.Duration.ofSeconds;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
import static org.junit.jupiter.api.Assertions.assertLinesMatch;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTimeout;
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.ArrayList;
import java.util.LinkedList;
@@ -91,11 +105,12 @@ public class AssertionUnitTest {
@Test
public void givenMultipleAssertion_whenAssertingAll_thenOK() {
Object obj = null;
assertAll(
"heading",
() -> assertEquals(4, 2 * 2, "4 is 2 times 2"),
() -> assertEquals("java", "JAVA".toLowerCase()),
() -> assertEquals(null, null, "null is equal to null")
() -> assertEquals(obj, null, "null is equal to null")
);
}
@@ -0,0 +1,33 @@
package com.baeldung.junit5.order;
import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.MethodOrderer.Alphanumeric;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
@TestMethodOrder(Alphanumeric.class)
public class AlphanumericOrderUnitTest {
private static StringBuilder output = new StringBuilder("");
@Test
public void myATest() {
output.append("A");
}
@Test
public void myBTest() {
output.append("B");
}
@Test
public void myaTest() {
output.append("a");
}
@AfterAll
public static void assertOutput() {
assertEquals(output.toString(), "ABa");
}
}
@@ -0,0 +1,12 @@
package com.baeldung.junit5.order;
import org.junit.jupiter.api.MethodDescriptor;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.MethodOrdererContext;
public class CustomOrder implements MethodOrderer{
@Override
public void orderMethods(MethodOrdererContext context) {
context.getMethodDescriptors().sort((MethodDescriptor m1, MethodDescriptor m2)->m1.getMethod().getName().compareToIgnoreCase(m2.getMethod().getName()));
}
}
@@ -0,0 +1,33 @@
package com.baeldung.junit5.order;
import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
@TestMethodOrder(CustomOrder.class)
public class CustomOrderUnitTest {
private static StringBuilder output = new StringBuilder("");
@Test
public void myATest() {
output.append("A");
}
@Test
public void myBTest() {
output.append("B");
}
@Test
public void myaTest() {
output.append("a");
}
@AfterAll
public static void assertOutput() {
assertEquals(output.toString(), "AaB");
}
}
@@ -0,0 +1,37 @@
package com.baeldung.junit5.order;
import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
@TestMethodOrder(OrderAnnotation.class)
public class OrderAnnotationUnitTest {
private static StringBuilder output = new StringBuilder("");
@Test
@Order(1)
public void firstTest() {
output.append("a");
}
@Test
@Order(2)
public void secondTest() {
output.append("b");
}
@Test
@Order(3)
public void thirdTest() {
output.append("c");
}
@AfterAll
public static void assertOutput() {
assertEquals(output.toString(), "abc");
}
}
+1 -1
View File
@@ -32,6 +32,6 @@
<module>test-containers</module>
<module>testing</module>
<module>testng</module>
<module>junit-5-configuration</module>
<module>junit-5-basics</module>
</modules>
</project>