Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>This feature has made it into <a href="https://github.com/junit-team/junit/wiki/Download-and-Install" rel="noreferrer">JUnit 4.11</a>.</strong></p> <p>To use change the name of parameterized tests, you say:</p> <pre><code>@Parameters(name="namestring") </code></pre> <p><em><code>namestring</code></em> is a string, which can have the following special placeholders:</p> <ul> <li><code>{index}</code> - the index of this set of arguments. The default <em><code>namestring</code></em> is <code>{index}</code>.</li> <li><code>{0}</code> - the first parameter value from this invocation of the test.</li> <li><code>{1}</code> - the second parameter value</li> <li>and so on</li> </ul> <p>The final name of the test will be the name of the test method, followed by the <em><code>namestring</code></em> in brackets, as shown below.</p> <p>For example (adapted from the unit test for the <code>Parameterized</code> annotation):</p> <pre><code>@RunWith(Parameterized.class) static public class FibonacciTest { @Parameters( name = "{index}: fib({0})={1}" ) public static Iterable&lt;Object[]&gt; 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; } } </code></pre> <p>will give names like <code>testFib[1: fib(1)=1]</code> and <code>testFib[4: fib(4)=3]</code>. (The <code>testFib</code> part of the name is the method name of the <code>@Test</code>).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload