spring && Cobertura && maven &&junit 单元测试以及测试覆盖率
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;@ConfigurationpublicclassUserOperator{@BeanpublicUserService userService(){UserService info =newUserService();return info;}}
package junitdemo;import java.util.Date;publicclassUserService{publicUserInfo userInfo(){UserInfo info =newUserInfo();info.setDate(newDate());info.setAge(333);info.setInfo("dddddd");return info;}}
package junitdemo;import java.util.Date;publicclassUserInfo{privateDate date;publicDate getDate(){return date;}publicvoid setDate(Date date){this.date = date;}publicString getInfo(){return info;}publicvoid setInfo(String info){this.info = info;}publicint getAge(){return age;}publicvoid setAge(int age){this.age = age;}privateString info;privateint 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)publicclassUserOperatorTest{@AutowiredpublicUserService userService;@Test()publicvoid testUserOperator(){for(int i =0; i <100; i++){UserInfo info = userService.userInfo();System.out.println(info.toString());}}}
mvn cobertura:cobertura
spring && Cobertura && maven &&junit 单元测试以及测试覆盖率的更多相关文章
- 白盒测试笔记之:Junit 单元测试以及测试覆盖率
单元测试: 单元测试是从代码层面验证代码的正确性. 一般考虑接口中的数据结构是否正确,变量的临界条件,如空字符串,空集合等. Junit入门 参考: Junit 入门教程: https://ww ...
- Maven单元测试报告及测试覆盖率
对junit单元测试的报告:类似这样的结果 ------------------------------------------------------- T E S T S ----------- ...
- [Java] Spring + SpringMVC + Maven + JUnit 搭建
示例项目下载: https://github.com/yangyxd/SpringDemo 利用前面 SpringMVC 项目的配置方式,完成初步的项目创建.下面只讲一些不同之处. 传送门: [Jav ...
- maven junit 单元测试插件配置
单元测试插件配置 pom.xml中增加 <dependency> <groupId>junit</groupId> <artifactId>junit& ...
- Spring框架整合JUnit单元测试
1. 为了简化了JUnit的测试,使用Spring框架也可以整合测试 2. 具体步骤 * 要求:必须先有JUnit的环境(即已经导入了JUnit4的开发环境)!! * 步骤一:在程序中引入:sprin ...
- springboot利用mock进行junit单元测试,测试controller
1 spring-boot-starter-test内置mockito,添加pom依赖 <dependency> <groupId>org.springframework.b ...
- junit 单元测试 - 参数化测试
junit4.x版本需要引入如下jar包: hamcrest-core-1.3.jar junit-4.12-beta-3.jar 新建一个计算器类,如下: package com.pt; publi ...
- Spring 框架整合JUnit单元测试
// 整合之前 public class Demo{ @Test public void fun(){ // 获取工厂,加载配置文件 ApplicationContext ac = new Class ...
- 测试覆盖率 之 Cobertura的使用
什么是代码覆盖率? 代码覆盖率是对整个测试过程中被执行的代码的衡量,它能测量源代码中的哪些语句在测试中被执行,哪些语句尚未被执行. 为什么要测量代码覆盖率? 众所周知,测试可以提高软件版本的质量和可预 ...
随机推荐
- Mac下使用firefoxdriver
Mac使用Firefox浏览器只需要设置WebDriver driver = new FirefoxDriver(),不需要安装firefoxdriver,前提是你的Firefox被安装在默认的位置. ...
- apt-get install *** 出现 软件包***没有提供可供安装的候选者
今天,重新安装Ubuntu13.04后,在命令行输入 sudo apt-get install aptitude 提示: 软件包 aptitude 没有提供可供安装的候选者 sudo apt-get ...
- 使用恶意USB设备解锁 Windows & Mac 锁屏状态
NSA专业物理入侵设备——USB Armory,可解锁任意锁屏状态的下的Windows和Mac操作系统,含最新发布的Windows10.及较早的Mac OSX El Capitan / Maveric ...
- html5 请求的URL转成 OC可用属性字符串显示
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:helpUrlStr]]; NSString *string = [ ...
- Java数组和C++异同
一.定义和初始化 1.Jave定义和初始化: Java:两种方式 Type[] A; Type A[]; 定义时不能指定数组的长度 静态初始化: A = new Type[][Ele1,Ele2 ...
- HTML教程-各窗口间相互操作(Frame Target)
由Frames分出来的几个窗口的内容并不是静止不变的,往往一个窗口的内容随着另一个窗口的要求而不断变化,这就提高了Frames的利用价值.为了完成各窗口之间的相互操作,我们必须为每一个窗口起一个名字, ...
- C# 属性和字段的区别
属性和字段的区别 在C#中,我们可以非常自由的.毫无限制的访问公有字段, 但在一些场合中,我们可能希望限制只能给字段赋于某个范围的值.或是要求字段只能读或只能写, 或是在改变字段时能改变对象的其他一些 ...
- 黑马.net12期视频教程
完整高清视频http://www.ggfenxiang8.com/?p=301
- thinkphp 介绍
一.ThinkPHP的介绍 MVC M - Model 模型 工作:负责数据的操作 V - View 视图(模板) 工作:负责 ...
- matlab 批量提取CNN特征
无类别,图像混合放置: clear close all addpath ./matlab model= './models/bvlc_reference_caffenet/deploy.prototx ...