Introduction and features list

Created by Yuval Shavit
Keywords:

NamedParameterizedRunner is a replacement for JUnit's built-in @RunWith(Parameterized.class). At the core of things, it replaces numerical indexes with a name of your choosing.

For instance, let's say you want to test your (very!) simple calculator class:

public interface Calculator {
    long add(long one, long two);
}

You've come up with the following test cases:
 1 + 1 = 2
40 + 2 = 42
-1 + 1 = 0

For each test case, you have an Object[] of three elements: Long firstOperand, Long secondOperand, Long expectedResult. In the standard parameterized runner, you would see something like:

    [0] testAdd PASSED
    [1] testAdd PASSED
    [2] testAdd FAILED

With the NamedParameterizedRunner, you would see:

    "1 + 1 = 2" testAdd PASSED
    "40 + 2 = 42" testAdd PASSED
    "-1 + 1 = 0" testAdd FAILED

Along with this come some other useful features:
    - you can run just one test, or all tests that match a regular expression (useful for debugging!)
    - fine-grained control over JUnit's @Ignore. You can ignore all test method for a given parameterization, or you can ignore only certain parameterizations for a given @Test method
    - you can have certain @Test methods run only when conditions are met -- that is, only for certain parameterizations

These features will be documented in other FAQs.