return Arrays.asList(new Object[][] {
{3, 2, 6 },
{4, 3, 12 },
{21, 5, 105 },
{11, 22, 242 },
{8, 9, 72 }});
}
说明:
需要使用@Parameters标签注解一个静态的返回集合对象的方法
增加成员变量和构造函数:
Java代码
int faciend;
int multiplicator;
int result;
public MathTest(int faciend, int multiplicator, int result) {
this.faciend = faciend;
this.multiplicator = multiplicator;
this.result = result;
}
int faciend;
int multiplicator;
int result;
public MathTest(int faciend, int multiplicator, int result) {
this.faciend = faciend;
this.multiplicator = multiplicator;
this.result = result;
}
最后在给测试类增加如下注释:
Java代码
@RunWith(Parameterized.class)
完整的循环测试代码如下:
Java代码
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;
/**
文章来源于领测软件测试网 https://www.ltesting.net/