自分の4番目のjunitの例(パラメータ多重テスト)
2508 ワード
package com.xinnuo.daos;
/**
* @author bimingwei
* @ :
*/
public class Math {
public static int divide(int x,int y) {
try{ return x/y; }
catch (Exception e) {
// TODO: handle exception
System.out.println(" ");
}
return x/y;
}
public static int multiple(int x,int y) {
return x*y;
}
}
package com.xinnuo.daos;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Collection;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
/**
* @author bimingwei
* @ :
*/
@RunWith(Parameterized.class)
public class MathTest {
int faciend;
int multiplicator;
int result;
public MathTest(int faciend, int multiplicator, int result) {
this.faciend = faciend;
this.multiplicator = multiplicator;
this.result = result;
}
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
@Test(expected=ArithmeticException.class)
public void testDivide() {
assertEquals(3,Math.divide(9,3));
assertEquals(3,Math.divide(10,3));
Math.divide(10,0);// 0,
}
//@Ignore(" ")
@Test
public void testMultiple() {
assertEquals(result,Math.multiple(faciend,multiplicator));
}
@Parameters
public static Collection multipleValues() {
return Arrays.asList(new Object[][] {
{3, 2, 6 },
{4, 3, 12 },
{21, 5, 105 },
{11, 22, 242 },
{8, 9, 72 }});
}
}