Samples JDK
SingleJUnitTestRunner.java
1 package com.freemindcafe;
2 
3 import org.junit.internal.TextListener;
4 import org.junit.runner.JUnitCore;
5 import org.junit.runner.Request;
6 import org.junit.runner.Result;
7 import org.junit.runner.notification.RunListener;
8 
9 public class SingleJUnitTestRunner {
10  public static void main(String... args) throws ClassNotFoundException {
11  String[] classAndMethod = args[0].split("#");
12  //if we want to run a single test case. We should provide the TestClass#testMethod
13  if(classAndMethod.length == 2){
14  Request request = Request.method(Class.forName(classAndMethod[0]),
15  classAndMethod[1]);
16  JUnitCore jUnitCore = new JUnitCore();
17  RunListener listener= new TextListener(System.out);
18  jUnitCore.addListener(listener);
19  Result result = jUnitCore.run(request);
20  System.exit(result.wasSuccessful() ? 0 : 1);
21  }
22  //otherwise run the normal Junit core
23  else{
24  JUnitCore.main(args);
25  }
26  }
27 }