Exemple #1
0
  /** Starts a test run. Analyzes the command line arguments and runs the given test suite. */
  public TestResult start(String args[]) throws Exception {
    String testCase = "";
    String method = "";
    boolean wait = false;

    for (int i = 0; i < args.length; i++) {
      if (args[i].equals("-wait")) wait = true;
      else if (args[i].equals("-c")) testCase = extractClassName(args[++i]);
      else if (args[i].equals("-m")) {
        String arg = args[++i];
        int lastIndex = arg.lastIndexOf('.');
        testCase = arg.substring(0, lastIndex);
        method = arg.substring(lastIndex + 1);
      } else if (args[i].equals("-v"))
        System.err.println("JUnit " + Version.id() + " by Kent Beck and Erich Gamma");
      else testCase = args[i];
    }

    if (testCase.equals(""))
      throw new Exception(
          "Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class");

    try {
      if (!method.equals("")) return runSingleMethod(testCase, method, wait);
      Test suite = getTest(testCase);
      return doRun(suite, wait);
    } catch (Exception e) {
      throw new Exception("Could not create and run test suite: " + e);
    }
  }
  /**
   * Starts a test run. Analyzes the command line arguments and runs the given test suite.
   *
   * @param args The command line arguments.
   * @return The test results.
   * @throws Exception Any exceptions falling through the tests are wrapped in Exception and
   *     rethrown.
   */
  protected TestResult start(String[] args) throws Exception {
    String testCase = "";
    boolean wait = false;

    for (int i = 0; i < args.length; i++) {
      if ("-wait".equals(args[i])) {
        wait = true;
      } else if ("-c".equals(args[i])) {
        testCase = extractClassName(args[++i]);
      } else if ("-v".equals(args[i])) {
        System.err.println("JUnit " + Version.id() + " by Kent Beck and Erich Gamma");
      } else {
        testCase = args[i];
      }
    }

    if ("".equals(testCase)) {
      throw new Exception(
          "Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class");
    }

    try {
      Test suite = getTest(testCase);

      return doRun(suite, wait);
    } catch (Exception e) {
      /*log.warn("Got exception whilst creating and running test suite.", e);*/
      throw new Exception("Could not create and run the test suite.", e);
    }
  }
 private static float getJUnitVersion() {
   try {
     return Float.parseFloat(Version.id());
   } catch (NumberFormatException e) {
     // If this happens we revert to JUnit 4.4 runner
     return 4.4f;
   }
 }
 /** Returns a new {@link RunListener} instance for the given {@param outputFormat}. */
 public RunListener newRunListener(OutputFormat outputFormat) {
   switch (outputFormat) {
     case JUNIT:
       out.println("JUnit version " + Version.id());
       return new TextListener(out);
     case GTM_UNIT_TESTING:
       return new GtmUnitTestingTextListener();
     default:
       throw new IllegalArgumentException("outputFormat");
   }
 }
Exemple #5
0
 /**
  * @param system
  * @args args from main()
  */
 private Result runMain(JUnitSystem system, String... args) {
   system.out().println("JUnit version " + Version.id());
   List<Class<?>> classes = new ArrayList<Class<?>>();
   List<Failure> missingClasses = new ArrayList<Failure>();
   for (String each : args)
     try {
       classes.add(Class.forName(each));
     } catch (ClassNotFoundException e) {
       system.out().println("Could not find class: " + each);
       Description description = Description.createSuiteDescription(each);
       Failure failure = new Failure(description, e);
       missingClasses.add(failure);
     }
   RunListener listener = new TextListener(system);
   addListener(listener);
   Result result = run(classes.toArray(new Class[0]));
   for (Failure each : missingClasses) result.getFailures().add(each);
   return result;
 }
Exemple #6
0
 /** @return the version number of this release */
 public String getVersion() {
   return Version.id();
 }