junit高级篇(参数化、打包测试)-实例代码
工程目录:

参数化测试,SquareTest.java:
import static org.junit.Assert.*; import java.util.Arrays;
import java.util.Collection; import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class)
public class SquareTest {
private static Calculator calculator = new Calculator();
private int param;
private int result; @Parameters
public static Collection data(){
return Arrays.asList(new Object[][]{
{2,4},
{0,0},
{-3,9},
});
} //构造函数,对变量进行初始化
public SquareTest(int param,int result){
this.param = param;
this.result = result;
} @Test
public void square(){
calculator.square(param);
assertEquals(result,calculator.getResult());
} }
打包测试,AllCalculatorTests.java:
import org.junit.runner.RunWith;
import org.junit.runners.Suite; @RunWith(Suite.class)
@Suite.SuiteClasses({
CalculatorTest.class,
SquareTest.class
})
public class AllCalculatorTests { }
执行AllCalculatorTests.java的结果

junit高级篇(参数化、打包测试)-实例代码的更多相关文章
- iOS开发——高级篇——iOS 强制退出程序APP代码
1.先po代码 UIAlertView* alert = [[UIAlertView alloc] initWithTitle:self.exitapplication message:@" ...
- Monkey框架(测试方法篇) - monkey测试实例
一.常规的稳定性测试 测试背景: 这是一个海外的合作项目,被测程序是Android应用(App).测试希望通过Monkey来模拟用户长时间的随机操作,检查被测应用是否会出现异常(应用崩溃或者无响应). ...
- Junit初级篇
@Test介绍 @Test是我们在写测试脚本时最常用到的,大部分情况下如果没用这个注解,一个方法就不能成为测试用例.如下代码是一个最普通的测试脚本: import org.junit.Assert; ...
- junit基础篇、中级篇-实例代码
学习文章: http://blog.csdn.net/andycpp/article/details/1327147 http://wenku.baidu.com/link?url=C27gDEj0l ...
- Junit 4.x 单元测试,参数化测试,套件测试 实例
对下面三个类进行单元测试 ,组成套件测试. public class Calculate { public int add(int a, int b) { return a + b; } public ...
- SpringBootTest单元测试实战、SpringBoot测试进阶高级篇之MockMvc讲解
1.@SpringBootTest单元测试实战 简介:讲解SpringBoot的单元测试 1.引入相关依赖 <!--springboot程序测试依赖,如果是自动创建项目默认添加--> &l ...
- JMeter学习-026-JMeter 分布式(远程)参数化测试实例
以前文所述对文章详情的HTTP请求进行性能测试为例.日常实际场景中,不可能所有的人都在同时访问一篇文章,而是多人访问不同的文章,因而需要对文章编号进行参数化,以更好的模拟日常的性能测试场景.同时,因文 ...
- Junit打包测试
在一个项目中,只写一个测试类是不可能的,我们会写出很多很多个测试类.可是这些测试类必须一个一个的执行,也是比较麻烦的事情. 鉴于此, JUnit 为我们提供了打包测试的功能,将所有需要运行的测试类集中 ...
- Linux下简易蜂鸣器驱动代码及测试实例
驱动代码: #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> ...
随机推荐
- c# AES加解密并转ASCII码
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Sec ...
- Comet 反Ajax: jQuery与PHP实现Ajax长轮询
原文地址(http://justcode.ikeepstudying.com/2016/08/comet-%E5%8F%8Dajax-%E5%9F%BA%E4%BA%8Ejquery%E4%B8%8E ...
- Mac下安装UPnP Inspector
由于工作中需要用到UPnP Inspector这个工具,而这个工具在windows下安装非常简单,在Mac下安装却很麻烦,在此记录安装流程. 这个工具依赖于两个其他的库:Coherence(一个DLN ...
- 使用 robotframework 自动化测试系列 一 -----简介
robotframework 是自动化测试框架. Robot Framework是一款python编写的功能自动化测试框架.具备良好的可扩展性,支持关键字驱动,可以同时测试多种类型的客户端或者接口,可 ...
- 。。。珍惜生命,远离Eclipse。。。
今天上午就这么过去了,我的人生中有这样一个半天,献给了一个叫做Eclipse的家伙!!!今天是周末,我本应该休息的,但是又犯贱了!!!我竟然主动要加班!!!本来是个很不错心情,现在很不开心!早上来做了 ...
- Objective-C语言Foundation框架
Mac OS X开发会使用Cocoa框架,它是一种支持应用程序提供丰富用户体验的框架,它实际上由:Foundation和Application Kit(AppKit)框架组成.iOS开发,会使用Coc ...
- Spring 文章推荐
spring mvc 异常统一处理方式:http://www.cnblogs.com/xd502djj/archive/2012/09/24/2700490.html 在springmvc中使用hib ...
- 数据库的点数据根据行政区shp来进行行政区处理,python定时器实现
# -*- coding: utf-8 -*- import struct import decimal import itertools import arcpy import math impor ...
- js !!条件判断或运算的作用
今天看到一个判断语句非常奇怪: if(!!selected){} //为什么是双'!'号呢? 自己查了下资料终于明白了这其中的原理: 原来'!!'会将表达式转为Boolean类型的数据. 如果'!un ...
- Linux系统使用yum安装nodejs
先执行: yum install \ http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm 再执行: su ...