3 回答

TA貢獻1784條經驗 獲得超2個贊
此功能使其成為JUnit 4.11的一部分。
要使用更改參數化測試的名稱,請說:
@Parameters(name="namestring")
namestring 是一個字符串,可以具有以下特殊占位符:
{index}-這組參數的索引。默認namestring值為{index}。
{0} -此測試調用的第一個參數值。
{1} -第二個參數值
等等
測試的最終名稱將是測試方法的名稱,后跟namestring方括號,如下所示。
例如(從單元測試改編為Parameterized注釋):
@RunWith(Parameterized.class)
static public class FibonacciTest {
@Parameters( name = "{index}: fib({0})={1}" )
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][] { { 0, 0 }, { 1, 1 }, { 2, 1 },
{ 3, 2 }, { 4, 3 }, { 5, 5 }, { 6, 8 } });
}
private final int fInput;
private final int fExpected;
public FibonacciTest(int input, int expected) {
fInput= input;
fExpected= expected;
}
@Test
public void testFib() {
assertEquals(fExpected, fib(fInput));
}
private int fib(int x) {
// TODO: actually calculate Fibonacci numbers
return 0;
}
}
將命名為testFib[1: fib(1)=1]和testFib[4: fib(4)=3]。(testFib名稱的一部分是的方法名稱@Test)。
添加回答
舉報