一只斗牛犬
此功能使其成为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)。