标签:cobertura oid lin mojo data location oal for private
1. 目的:
<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.dalong.demoapp</groupId>
<artifactId>junitdemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.5.release</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.5.release</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<formats>
<format>xml</format>
</formats>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>cobertura</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
package junitdemo;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class UserOperator {
@Bean
public UserService userService() {
UserService info = new UserService();
return info;
}
}
package junitdemo;
import java.util.Date;
public class UserService {
public UserInfo userInfo() {
UserInfo info = new UserInfo();
info.setDate(new Date());
info.setAge(333);
info.setInfo("dddddd");
return info;
}
}
package junitdemo;
import java.util.Date;
public class UserInfo {
private Date date;
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
private String info;
private int age;
}
package junitdemo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = UserOperator.class)
public class UserOperatorTest {
@Autowired
public UserService userService;
@Test()
public void testUserOperator() {
for (int i = 0; i < 100; i++) {
UserInfo info = userService.userInfo();
System.out.println(info.toString());
}
}
}
mvn cobertura:cobertura
spring && Cobertura && maven &&junit 单元测试以及测试覆盖率
标签:cobertura oid lin mojo data location oal for private
原文地址:http://www.cnblogs.com/rongfengliang/p/6260183.html