org.junit.runners

Class Parameterized


public class Parameterized
extends org.junit.internal.runners.TestClassRunner

The custom runner Parameterized implements parameterized tests. When running a parameterized test class, instances are created for the cross-product of the test methods and the test data elements. For example, to test a Fibonacci function, write:
 @RunWith(Parameterized.class)
 public class FibonacciTest {
    @Parameters
    public static Collection data() {
          return Arrays.asList(new Object[][] { { 0, 0 }, { 1, 1 }, { 2, 1 },
             { 3, 2 }, { 4, 3 }, { 5, 5 }, { 6, 8 } });
    }

    private int fInput;
    private int fExpected;

    public FibonacciTest(int input, int expected) {
       fInput= input;
       fExpected= expected;
    }

    @Test public void test() {
       assertEquals(fExpected, Fibonacci.compute(fInput));
    }
 }
 

Each instance of FibonacciTest will be constructed using the two-argument constructor and the data values in the @Parameters method.

Nested Class Summary

static class
Parameterized.RunAllParameterMethods

Constructor Summary

Parameterized(Class klass)

Method Summary

static Collection
> eachOne(Object... params)
protected @Override
void validate(org.junit.internal.runners.MethodValidator methodValidator)

Constructor Details

Parameterized

public Parameterized(Class klass)
            throws Exception

Method Details

> eachOne

public static Collection eachOne(Object... params)

void validate

protected @Override void validate(org.junit.internal.runners.MethodValidator methodValidator)