org.junit.runners
Class Parameterized

java.lang.Object
  extended by org.junit.runner.Runner
      extended by org.junit.internal.runners.CompositeRunner
          extended by org.junit.runners.Parameterized
All Implemented Interfaces:
Filterable, Sortable

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

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 interface Parameterized.Parameters
           
 
Constructor Summary
Parameterized(java.lang.Class<?> klass)
           
 
Method Summary
static java.util.Collection<java.lang.Object[]> eachOne(java.lang.Object... params)
           
 void run(RunNotifier notifier)
          Run the tests for this runner.
 
Methods inherited from class org.junit.internal.runners.CompositeRunner
add, addAll, filter, getDescription, getName, getRunners, runChildren, sort
 
Methods inherited from class org.junit.runner.Runner
testCount
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Parameterized

public Parameterized(java.lang.Class<?> klass)
              throws java.lang.Exception
Throws:
java.lang.Exception
Method Detail

run

public void run(RunNotifier notifier)
Description copied from class: Runner
Run the tests for this runner.

Overrides:
run in class org.junit.internal.runners.CompositeRunner
Parameters:
notifier - will be notified of events while tests are being run--tests being started, finishing, and failing

eachOne

public static java.util.Collection<java.lang.Object[]> eachOne(java.lang.Object... params)