您的位置:首页 > 编程语言 > Java开发

[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);


}




}



测试结果

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: