1. 创建一个maven项目
2. 创建com.CoberturaStart.java
package com;
public class CoberturaStart {
public void helloEveryone(){
System.out.println("============================================================");
System.out.println("hello everyone!!!");
System.out.println("============================================================");
}
public void goodMorningGentleman(){
System.out.println("============================================================");
System.out.println("good morning,gentleman!!!");
System.out.println("============================================================");
}
}
3. 创建以下测试类
com.HelloEveryoneTest.java
package com;
import org.junit.Test;
import junit.framework.Assert;
public class HelloEveryoneTest {
@Test
public void testHelloEveryone(){
CoberturaStart coberturaStart = new CoberturaStart();
coberturaStart.helloEveryone();
Assert.assertTrue(true);
}
}
com.GoodMorningGentlemanTest.java
package useless;
import junit.framework.Assert;
import org.junit.Test;
import com.CoberturaStart;
public class GoodMorningGentlemanTest {
@Test
public void testGoodMorningGentleman(){
CoberturaStart coberturaStart = new CoberturaStart();
coberturaStart.goodMorningGentleman();
Assert.assertTrue(true);
}
}
4. pom.xml
<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>MavenProject</groupId> <artifactId>MavenProject</artifactId> <version>0.0.1-SNAPSHOT</version> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <excludes> <exclude>useless/CoberturaStartTest.class</exclude> </excludes> </configuration> </plugin> </plugins> </build> <reporting> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.5.1</version> </plugin> </plugins> </reporting> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.0</version> <scope>test</scope> </dependency> </dependencies> </project>
maven-surefire-plugin 指明了哪些测试类我们将使用或不使用。(上面案例指明useless/CoberturaStartTest将不被使用)