Ein JUnit-TestSuite kann z.B. so aussehen:
1 package testproject.tests.dao;
2
3 import org.junit.runner.RunWith;
4 import org.junit.runners.Suite;
5
6 @RunWith(Suite.class)
7 @Suite.SuiteClasses({
8 UserTests.class,
9 FolderTests.class
10 })
11
12 public class DAOTestSuite {
13 // the class remains completely empty,
14 // being used only as a holder for the above annotations
15 }
Erst werden die Tests in der Klasse "UserTests" (Zeile 8) und anschließend die Tests in der Klasse "FolderTests" (Zeile 9) ausgeführt.
In der Maven 2-Konfiguration (pom.xml) kann man dann die Konfiguration für das Surefire-Plugin wie folgt anpassen (Zeile 13-17):
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
4 <!-- ... -->
5
6 <build>
7 <!-- ... -->
8 <plugins>
9 <plugin>
10 <groupId>org.apache.maven.plugins</groupId>
11 <artifactId>maven-surefire-plugin</artifactId>
12 <version>2.4.2</version>
13 <configuration>
14 <includes>
15 <include>**/DAOTestSuite.java</include>
16 </includes>
17 </configuration>
18 </plugin>
19 </plugins>
20 </build>
Keine Kommentare:
Kommentar veröffentlichen