Commits

Micha Kops committed 591ede5

Initial import, examples for category selection by maven profile added.

  • Participants

Comments (0)

Files changed (7)

+.project
+.classpath
+.settings
+target
+infinitest.filters
+# JUnit Categories Maven Integration
+
+Examples how to run specific test categories from your Mavenized environment.
+
+Please feel free to take a look at [my blog] for the full tutorial.
+
+---
+
+**2012 Micha Kops / hasCode.com**
+
+   [my blog]:http://www.hascode.com
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" 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>
+	<groupId>com.hascode.tutorial</groupId>
+	<artifactId>junit-categories-maven</artifactId>
+	<version>0.0.1</version>
+	<url>http://www.hascode.com/</url>
+
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+	</properties>
+
+	<dependencies>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>4.11</version>
+			<scope>test</scope>
+		</dependency>
+	</dependencies>
+
+
+	<build>
+		<plugins>
+			<plugin>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>1.6</source>
+					<target>1.6</target>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-surefire-plugin</artifactId>
+				<version>2.12.4</version>
+			</plugin>
+		</plugins>
+	</build>
+
+	<profiles>
+		<profile>
+			<id>fastTests</id>
+			<activation>
+				<activeByDefault>true</activeByDefault>
+			</activation>
+			<build>
+				<plugins>
+					<plugin>
+						<groupId>org.apache.maven.plugins</groupId>
+						<artifactId>maven-surefire-plugin</artifactId>
+						<configuration>
+							<groups>com.hascode.tutorial.test.group.FastTests</groups>
+						</configuration>
+					</plugin>
+				</plugins>
+			</build>
+		</profile>
+		<profile>
+			<id>slowTests</id>
+			<build>
+				<plugins>
+					<plugin>
+						<groupId>org.apache.maven.plugins</groupId>
+						<artifactId>maven-surefire-plugin</artifactId>
+						<configuration>
+							<groups>com.hascode.tutorial.test.group.SlowTests</groups>
+						</configuration>
+					</plugin>
+				</plugins>
+			</build>
+		</profile>
+	</profiles>
+</project>

src/test/java/com/hascode/tutorial/test/FirstTest.java

+package com.hascode.tutorial.test;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.hascode.tutorial.test.group.FastTests;
+
+@Category({ FastTests.class })
+public class FirstTest {
+	@Test
+	public void testSth() throws Exception {
+		System.out.println("FirstTest.testSth run");
+		assertTrue(true);
+	}
+
+	@Test
+	public void testAnotherThing() throws Exception {
+		System.out.println("FirstTest.testAnotherThing run");
+		assertTrue(true);
+	}
+}

src/test/java/com/hascode/tutorial/test/SecondTest.java

+package com.hascode.tutorial.test;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.hascode.tutorial.test.group.FastTests;
+import com.hascode.tutorial.test.group.SlowTests;
+
+public class SecondTest {
+	@Test
+	@Category({ FastTests.class, SlowTests.class })
+	public void testSth() throws Exception {
+		System.out.println("SecondTest.testSth run");
+		assertTrue(true);
+	}
+
+	@Test
+	@Category({ SlowTests.class })
+	public void testAnotherThing() throws Exception {
+		System.out.println("SecondTest.testAnotherThing run");
+		assertTrue(true);
+	}
+}

src/test/java/com/hascode/tutorial/test/group/FastTests.java

+package com.hascode.tutorial.test.group;
+
+/**
+ * Marker interface for fast-running tests.
+ */
+public interface FastTests {
+}

src/test/java/com/hascode/tutorial/test/group/SlowTests.java

+package com.hascode.tutorial.test.group;
+
+/**
+ * Marker interface for slow-running tests.
+ */
+public interface SlowTests {
+
+}