diff --git a/testing-modules/junit-5/src/test/java/org/baeldung/java/customtestname/CustomNameUnitTest.java b/testing-modules/junit-5/src/test/java/org/baeldung/java/customtestname/CustomNameUnitTest.java new file mode 100644 index 0000000000..f04b825c89 --- /dev/null +++ b/testing-modules/junit-5/src/test/java/org/baeldung/java/customtestname/CustomNameUnitTest.java @@ -0,0 +1,17 @@ +package org.baeldung.java.customtestname; + +import static org.junit.Assert.assertNotNull; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +public class CustomNameUnitTest { + + @ParameterizedTest + @ValueSource(strings = { "Hello", "World" }) + @DisplayName("Test Method to check that the inputs are not nullable") + void givenString_TestNullOrNot(String word) { + assertNotNull(word); + } +} diff --git a/testing-modules/junit-5/src/test/java/org/baeldung/java/parameterisedsource/ParameterizedUnitTest.java b/testing-modules/junit-5/src/test/java/org/baeldung/java/parameterisedsource/ParameterizedUnitTest.java new file mode 100644 index 0000000000..8d09161176 --- /dev/null +++ b/testing-modules/junit-5/src/test/java/org/baeldung/java/parameterisedsource/ParameterizedUnitTest.java @@ -0,0 +1,45 @@ +package org.baeldung.java.parameterisedsource; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.EnumSet; +import java.util.stream.Stream; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.EnumSource; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ValueSource; + +public class ParameterizedUnitTest { + + @ParameterizedTest + @ValueSource(strings = { "Hello", "World" }) + void givenString_TestNullOrNot(String word) { + assertNotNull(word); + } + + @ParameterizedTest + @EnumSource(value = PizzaDeliveryStrategy.class, names = {"EXPRESS", "NORMAL"}) + void givenEnum_TestContainsOrNot(PizzaDeliveryStrategy timeUnit) { + assertTrue(EnumSet.of(PizzaDeliveryStrategy.EXPRESS, PizzaDeliveryStrategy.NORMAL).contains(timeUnit)); + } + + @ParameterizedTest + @MethodSource("wordDataProvider") + void givenMethodSource_TestInputStream(String argument) { + assertNotNull(argument); + } + + static Stream wordDataProvider() { + return Stream.of("foo", "bar"); + } + + @ParameterizedTest + @CsvSource({ "1, Car", "2, House", "3, Train" }) + void givenCSVSource_TestContent(int id, String word) { + assertNotNull(id); + assertNotNull(word); + } +} diff --git a/testing-modules/junit-5/src/test/java/org/baeldung/java/parameterisedsource/PizzaDeliveryStrategy.java b/testing-modules/junit-5/src/test/java/org/baeldung/java/parameterisedsource/PizzaDeliveryStrategy.java new file mode 100644 index 0000000000..ecfc7b4627 --- /dev/null +++ b/testing-modules/junit-5/src/test/java/org/baeldung/java/parameterisedsource/PizzaDeliveryStrategy.java @@ -0,0 +1,6 @@ +package org.baeldung.java.parameterisedsource; + +public enum PizzaDeliveryStrategy { + EXPRESS, + NORMAL; +} diff --git a/testing-modules/junit-5/src/test/java/org/baeldung/java/suite/SelectClassesSuiteUnitTest.java b/testing-modules/junit-5/src/test/java/org/baeldung/java/suite/SelectClassesSuiteUnitTest.java new file mode 100644 index 0000000000..220897eae7 --- /dev/null +++ b/testing-modules/junit-5/src/test/java/org/baeldung/java/suite/SelectClassesSuiteUnitTest.java @@ -0,0 +1,13 @@ +package org.baeldung.java.suite; + +import org.baeldung.java.suite.childpackage1.Class1UnitTest; +import org.baeldung.java.suite.childpackage2.Class2UnitTest; +import org.junit.platform.runner.JUnitPlatform; +import org.junit.platform.suite.api.SelectClasses; +import org.junit.runner.RunWith; + +@RunWith(JUnitPlatform.class) +@SelectClasses({Class1UnitTest.class, Class2UnitTest.class}) +public class SelectClassesSuiteUnitTest { + +} diff --git a/testing-modules/junit-5/src/test/java/org/baeldung/java/suite/SelectPackagesSuiteUnitTest.java b/testing-modules/junit-5/src/test/java/org/baeldung/java/suite/SelectPackagesSuiteUnitTest.java new file mode 100644 index 0000000000..ae887ae43b --- /dev/null +++ b/testing-modules/junit-5/src/test/java/org/baeldung/java/suite/SelectPackagesSuiteUnitTest.java @@ -0,0 +1,11 @@ +package org.baeldung.java.suite; + +import org.junit.platform.runner.JUnitPlatform; +import org.junit.platform.suite.api.SelectPackages; +import org.junit.runner.RunWith; + +@RunWith(JUnitPlatform.class) +@SelectPackages({ "org.baeldung.java.suite.childpackage1", "org.baeldung.java.suite.childpackage2" }) +public class SelectPackagesSuiteUnitTest { + +} diff --git a/testing-modules/junit-5/src/test/java/org/baeldung/java/suite/childpackage1/Class1UnitTest.java b/testing-modules/junit-5/src/test/java/org/baeldung/java/suite/childpackage1/Class1UnitTest.java new file mode 100644 index 0000000000..78469cb971 --- /dev/null +++ b/testing-modules/junit-5/src/test/java/org/baeldung/java/suite/childpackage1/Class1UnitTest.java @@ -0,0 +1,15 @@ +package org.baeldung.java.suite.childpackage1; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.Test; + + +public class Class1UnitTest { + + @Test + public void testCase_InClass1UnitTest() { + assertTrue(true); + } + +} diff --git a/testing-modules/junit-5/src/test/java/org/baeldung/java/suite/childpackage2/Class2UnitTest.java b/testing-modules/junit-5/src/test/java/org/baeldung/java/suite/childpackage2/Class2UnitTest.java new file mode 100644 index 0000000000..4463ecfad9 --- /dev/null +++ b/testing-modules/junit-5/src/test/java/org/baeldung/java/suite/childpackage2/Class2UnitTest.java @@ -0,0 +1,14 @@ +package org.baeldung.java.suite.childpackage2; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.Test; + +public class Class2UnitTest { + + @Test + public void testCase_InClass2UnitTest() { + assertTrue(true); + } + +}