title: How to programmatically execute a test suite using JUnit4?
body: <p>I am trying to invoke a JUnit Test suite using the API. I know that you can suite up test classes using the following:</p>
  
  <pre><code>@RunWith(Suite.class)
  @Suite.SuiteClasses({
    Test1.class,
    Test2.class, ...
  })
  </code></pre>
  
  <p>But, is there a way to trigger the entire suite using the Java API, using JUnitCore for example?</p>
  
  <p>For example, you can trigger a test by using the following code:</p>
  
  <pre><code>Runner r = 
  try {
    r = new BlockJUnit4ClassRunner(Class.forName(testClass));
  } catch (ClassNotFoundException | InitializationError e) {
    // handle
  }
  JUnitCore c = new JUnitCore();
  c.run(Request.runner(r));
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p>From the API, it seems that the Suite class itself is a runner, hence the following code seems to work:</p>
  
  <pre><code>Suite suite = new Suite(klass, new RunnerBuilder() {
  ... // Implement methods
  });
  JUnitCore c = new JUnitCore();
  c.run(Request.runner(suite));
  </code></pre>
  
  <p>But I am not sure if this is a recommended approach or if there is any downside to writing the above code.</p>