[java]junit4的参数化测试
2008-04-17 19:59
295 查看
//要测试的类
package junit;
public class Unit4 ...{
public int add(int a, int b)...{
return a+b;
}
}
//测试类(参数化测试的要求看代码中的注释)
package junit;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;
import org.junit.runner.*;
import org.junit.runners.*;
import java.util.*;
//1.测试类由@RunWith(Parameterized.class)修饰
@RunWith(Parameterized.class)
public class Unit4Test ...{
private int d1,d2;
private int result;
public Unit4Test(int d1, int d2, int result)...{
this.d1 = d1;
this.d2 = d2;
this.result = result;
}
//2.提供一个由@Parameters修饰的,方法原型为
// public static Collection methodName(/*no parameters*/)的
// 的一个提供参数的方法
@Parameters
@SuppressWarnings("unchecked")
public static Collection getParamters()...{
/**//*Object*/Integer [][] object = ...{...{1,2,3},...{0,0,0},...{-1,1,0},...{-1,-2,-3}};
return Arrays.asList(object);
}
@Test
public void testAdd() ...{
//fail("Not yet implemented");
Unit4 u = new Unit4();
int result = u.add(this.d1, this.d2);
assertEquals(this.result, result);
}
}
测试结果
package junit;
public class Unit4 ...{
public int add(int a, int b)...{
return a+b;
}
}
//测试类(参数化测试的要求看代码中的注释)
package junit;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;
import org.junit.runner.*;
import org.junit.runners.*;
import java.util.*;
//1.测试类由@RunWith(Parameterized.class)修饰
@RunWith(Parameterized.class)
public class Unit4Test ...{
private int d1,d2;
private int result;
public Unit4Test(int d1, int d2, int result)...{
this.d1 = d1;
this.d2 = d2;
this.result = result;
}
//2.提供一个由@Parameters修饰的,方法原型为
// public static Collection methodName(/*no parameters*/)的
// 的一个提供参数的方法
@Parameters
@SuppressWarnings("unchecked")
public static Collection getParamters()...{
/**//*Object*/Integer [][] object = ...{...{1,2,3},...{0,0,0},...{-1,1,0},...{-1,-2,-3}};
return Arrays.asList(object);
}
@Test
public void testAdd() ...{
//fail("Not yet implemented");
Unit4 u = new Unit4();
int result = u.add(this.d1, this.d2);
assertEquals(this.result, result);
}
}
测试结果
相关文章推荐
- Java单元测试工具:JUnit4(四)——JUnit测试套件使用及参数化设置
- Java JUnit 调用Excel表中数据 参数化测试 JUnit4
- Java单元测试工具:JUnit4——JUnit测试套件使用及参数化设置
- Java单元测试工具:JUnit4(四)——JUnit测试套件使用及参数化设置
- Java单元测试工具:JUnit4(四)——JUnit测试套件使用及参数化设置
- Java单元测试工具:JUnit4(四)——JUnit测试套件使用及参数化设置
- Junit4进行参数化测试
- 行为驱动:Cucumber + Selenium + Java(四) - 实现测试用例的参数化
- 参数化的java性能测试,几组实验
- 用JUnit4进行参数化测试
- 【Java开发技术之程序测试】Junit4 新功能学习总结
- Junit4 参数化测试 判断三角形的例子
- Junit4——测试套件的使用和参数化测试
- Java开发测试工具用法简略记录——Junit4 And EasyMock
- Junit4测试错误解决java.lang.IllegalStateException: Failed to load ApplicationContext
- 【Java开发技术之程序测试】Junit4 新功能学习总结
- junit4 参数化测试 (惭愧,工作了这么多年都没用过这功能!)
- JUnit4笔记(三)---JUnit的测试套件和参数化设置
- Java-测试框架之JUnit3和JUnit4使用区别的总结
- Junit4进行参数化测试