BAEL-6283 Creating a Test Suite with JUnit (#13873)

This commit is contained in:
Mateusz Szablak 2023-04-25 15:08:24 +02:00 committed by GitHub
parent 087561956f
commit 5b6d81ff3d
13 changed files with 160 additions and 0 deletions

View File

@ -33,6 +33,19 @@
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
@ -45,6 +58,9 @@
-javaagent:${settings.localRepository}/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar
</argLine>
<disableXmlReport>true</disableXmlReport>
<excludes>
<exclude>**/testsuite/**/*UnitTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
@ -53,6 +69,7 @@
<properties>
<jmockit.version>1.49</jmockit.version>
<assertj.version>3.24.2</assertj.version>
<junit-platform.version>1.9.2</junit-platform.version>
</properties>
</project>

View File

@ -0,0 +1,13 @@
package com.baeldung.testsuite;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class ClassOneUnitTest {
@Test
public void whenTrue_thenTrue() {
Assertions.assertTrue(true);
}
}

View File

@ -0,0 +1,13 @@
package com.baeldung.testsuite;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
public class ClassThreeUnitTest {
@Test
@Tag("slow")
public void whenTrue_thenTrue() {
Assertions.assertTrue(true);
}
}

View File

@ -0,0 +1,4 @@
/**
* Dummy tests - showing Junit Suite functionality
*/
package com.baeldung.testsuite;

View File

@ -0,0 +1,11 @@
package com.baeldung.testsuite.subpackage;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class ClassTwoUnitTest {
@Test
public void whenTrue_thenTrue() {
Assertions.assertTrue(true);
}
}

View File

@ -0,0 +1,14 @@
package com.baeldung.testsuite.suites;
import org.junit.platform.suite.api.ExcludeClassNamePatterns;
import org.junit.platform.suite.api.IncludeClassNamePatterns;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.platform.suite.api.Suite;
@Suite
@SelectPackages("com.baeldung.testsuite")
@IncludeClassNamePatterns("com.baeldung.testsuite.Class.*UnitTest")
@ExcludeClassNamePatterns("com.baeldung.testsuite.ClassTwoUnitTest")
public class JUnitClassNamePatternsSuite {
// runs ClassOneUnitTest and ClassThreeUnitTest
}

View File

@ -0,0 +1,12 @@
package com.baeldung.testsuite.suites;
import org.junit.platform.suite.api.ExcludePackages;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.platform.suite.api.Suite;
@Suite
@SelectPackages("com.baeldung.testsuite")
@ExcludePackages("com.baeldung.testsuite.subpackage")
public class JUnitExcludePackagesSuite {
// runs ClassOneUnitTest and ClassThreeUnitTest
}

View File

@ -0,0 +1,16 @@
package com.baeldung.testsuite.suites;
import com.baeldung.testsuite.ClassOneUnitTest;
import com.baeldung.testsuite.subpackage.ClassTwoUnitTest;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.SuiteDisplayName;
import org.junit.runner.RunWith;
@RunWith(JUnitPlatform.class)
@SuiteDisplayName("My Test Suite")
@SelectClasses({ClassOneUnitTest.class, ClassTwoUnitTest.class})
public class JUnitRunWithSuite {
// runs ClassOneUnitTest and ClassTwoUnitTest
// equivalent to JUnitSelectClassesSuite
}

View File

@ -0,0 +1,14 @@
package com.baeldung.testsuite.suites;
import com.baeldung.testsuite.ClassOneUnitTest;
import com.baeldung.testsuite.subpackage.ClassTwoUnitTest;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;
import org.junit.platform.suite.api.SuiteDisplayName;
@Suite
@SuiteDisplayName("My Test Suite")
@SelectClasses({ClassOneUnitTest.class, ClassTwoUnitTest.class})
public class JUnitSelectClassesSuite {
// runs ClassOneUnitTest and ClassTwoUnitTest
}

View File

@ -0,0 +1,10 @@
package com.baeldung.testsuite.suites;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.platform.suite.api.Suite;
@Suite
@SelectPackages({"com.baeldung.testsuite", "com.baeldung.testsuitetwo"})
public class JUnitSelectPackagesSuite {
// runs ClassOneUnitTest, ClassTwoUnitTest and ClassThreeUnitTest
}

View File

@ -0,0 +1,12 @@
package com.baeldung.testsuite.suites;
import org.junit.platform.suite.api.ExcludeTags;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.platform.suite.api.Suite;
@Suite
@SelectPackages("com.baeldung.testsuite")
@ExcludeTags("slow")
public class JUnitTestExcludeTagsSuite {
// runs ClassOneUnitTest, ClassTwoUnitTest
}

View File

@ -0,0 +1,12 @@
package com.baeldung.testsuite.suites;
import org.junit.platform.suite.api.IncludePackages;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.platform.suite.api.Suite;
@Suite
@SelectPackages("com.baeldung.testsuite")
@IncludePackages("com.baeldung.testsuite.subpackage")
public class JUnitTestIncludePackagesSuite {
// runs ClassTwoUnitTest
}

View File

@ -0,0 +1,12 @@
package com.baeldung.testsuite.suites;
import org.junit.platform.suite.api.IncludeTags;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.platform.suite.api.Suite;
@Suite
@SelectPackages("com.baeldung.testsuite")
@IncludeTags("slow")
public class JUnitTestIncludeTagsSuite {
// runs ClassTwoUnitTest
}