title: Running Parameterized Tests with JUnitCore
body: <p>Is it possible to run a parameterized test class with JUnitCore API?</p>
  
  <p>I've a class under test called <em>Fibonacci</em>, a parameterized test class called <em>TestFibonacci</em>, and a simple Java class (<em>JUnitParameterized</em>) which executes the <em>TestFibonacci</em> class using JUnitCore API. If I execute <em>TestFibonacci</em> with JUnit plugin or command line, it passes. However, when I execute it with my <em>JUnitParameterized</em> class it fails.</p>
  
  <p>Class Under Test</p>
  
  <pre><code>public class Fibonacci {
  
    public static int compute(int n) {
      if (n &lt;= 1) {
        return n;
      }
      return compute(n-1) + compute(n-2);
    }
  }
  </code></pre>
  
  <p>Test Class</p>
  
  <pre><code>import static org.junit.Assert.assertEquals;
  
  import org.junit.Test;
  import org.junit.runner.RunWith;
  import org.junit.runners.Parameterized;
  import org.junit.runners.Parameterized.Parameters;
  
  import java.util.Arrays;
  
  @RunWith(Parameterized.class)
  public class TestFibonacci {
  
    @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 int input;
    private int expected;
  
    public TestFibonacci(int input, int expected) {
      this.input = input;
      this.expected = expected;
    }
  
    @Test
    public void test() {
      assertEquals(expected, Fibonacci.compute(input));
    }
  }
  </code></pre>
  
  <p>Java program</p>
  
  <pre><code>import org.junit.runner.JUnitCore;
  import org.junit.runner.Request;
  import org.junit.runner.Result;
  
  public class JUnitParameterized {
  
    public static void main(String[] args) throws ClassNotFoundException {
  
      Class&lt;?&gt; testClass = JUnitParameterized.class.getClassLoader().loadClass(TestFibonacci.class.getCanonicalName());
  
      Result result = (new JUnitCore()).run(Request.method(testClass, "test"));
      System.out.println("Number of tests run: " + result.getRunCount());
      System.out.println("The number of tests that failed during the run: " + result.getFailureCount());
      System.out.println("The number of milliseconds it took to run the entire suite to run: " + result.getRunTime());
      System.out.println("" + (result.wasSuccessful() == true ? "Passed :)" : "Failed :("));
    }
  }
  </code></pre>