@Override
 public void run(TestResult result) {
   super.run(result);
   if (!result.wasSuccessful()) {
     result.addFailure(this, new AssertionFailedError(mLog.toString()));
   }
 }
 /** this testcase uses the file success.py contained in the same directory as this testcase */
 @Test
 public void testRunSuccessfulTestCase() throws Throwable {
   RuntimeStub runtime = new RuntimeStub();
   MarathonTestCase t = new MarathonTestCase(new File("./success.py"), runtime);
   TestResult result = t.run();
   if (result.errorCount() > 0) {
     TestFailure failure = (TestFailure) result.errors().nextElement();
     throw failure.thrownException();
   }
   assertEquals("failed", true, result.wasSuccessful());
 }
Exemple #3
0
 public static void main(String args[]) {
   TestRunner aTestRunner = new TestRunner();
   try {
     TestResult r = aTestRunner.start(args);
     if (!r.wasSuccessful()) System.exit(FAILURE_EXIT);
     System.exit(SUCCESS_EXIT);
   } catch (Exception e) {
     System.err.println(e.getMessage());
     System.exit(EXCEPTION_EXIT);
   }
 }
  /**
   * This method allows to easily run this unit test independent of the other unit tests, and
   * without dealing with Ant or unrelated test suites.
   */
  public static void main(String[] sa) {
    if (sa.length > 0 && sa[0].startsWith("-g")) {
      junit.swingui.TestRunner.run(OdbcPacketOutputStreamTest.class);
    } else {
      junit.textui.TestRunner runner = new junit.textui.TestRunner();
      junit.framework.TestResult result =
          runner.run(runner.getTest(OdbcPacketOutputStreamTest.class.getName()));

      System.exit(result.wasSuccessful() ? 0 : 1);
    }
  }
 /** this testcase uses the file failure.py contained in the same directory as this testcase */
 @Test
 public void testRunFailingTestCase() throws Exception {
   RuntimeStub runtime = new RuntimeStub();
   runtime.scriptsFail = true;
   MarathonTestCase t = new MarathonTestCase(new File("./failure.py"), runtime);
   TestResult result = t.run();
   assertEquals("test case should have failed", false, result.wasSuccessful());
   assertEquals(
       "each failing testcase should have one failure, and no errors", 1, result.failureCount());
   assertEquals(
       "each failing testcase should have one failure, and no errors", 0, result.errorCount());
 }
Exemple #6
0
 /**
  * Usage: java -cp ... AllTests file.jar [--only-run-slow-tests]
  *
  * <p>--only-run-slow-tests parameter only run test in classes annotated with @SlowTest, else
  * these tests will be skipped.
  *
  * @param args the command line arguments
  */
 public static void main(String[] args) throws Exception {
   if (args.length > 0 && args.length <= 2) {
     jarFile = args[0];
     if (args.length > 1) {
       if (args[1].equalsIgnoreCase("--only-run-slow-tests")) {
         onlyRunSlowTests = true;
       }
     }
     System.out.println("Running all tests in '" + jarFile + "'");
     TestSuite suite = (TestSuite) suite();
     System.out.println("Found '" + suite.testCount() + "' test classes in jar file.");
     TestResult res = junit.textui.TestRunner.run(suite);
     System.exit(res.wasSuccessful() ? 0 : 1);
   } else {
     usage();
   }
 }
  /**
   * This method allows to easily run this unit test independent of the other unit tests, and
   * without dealing with Ant or unrelated test suites.
   *
   * <p>Invoke like this:
   *
   * <PRE><CODE>
   *  public static void main(String[] sa) {
   *      staticRunner(TestOdbcService.class, sa);
   *  }
   * </CODE></PRE>
   *
   * , but give your subclass name in place of <CODE>TestOdbcService</CODE>
   */
  public static void staticRunner(Class c, String[] sa) {
    junit.textui.TestRunner runner = new junit.textui.TestRunner();
    junit.framework.TestResult result = runner.run(runner.getTest(c.getName()));

    System.exit(result.wasSuccessful() ? 0 : 1);
  }
Exemple #8
0
  protected void startTests() {
    final TestSuite suite = new TestSuite();
    final TestResult result = new TestResult();

    final JUnitTest jUnitTest = new JUnitTest("ch.ethz.iks.slp.test");
    jUnitTest.setProperties(System.getProperties());

    // create the xml result formatter
    final JUnitResultFormatter xmlResultFormatter = new XMLJUnitResultFormatter();
    final File file = new File(outputDirectory, "TEST-ch.ethz.iks.slp.test" + ".xml");
    try {
      xmlResultFormatter.setOutput(new FileOutputStream(file));
    } catch (FileNotFoundException e) {
      // may never happen
      e.printStackTrace();
    }
    result.addListener(xmlResultFormatter);
    // create a result formatter that prints to the console
    final JUnitResultFormatter consoleResultFormatter = new BriefJUnitResultFormatter();
    consoleResultFormatter.setOutput(System.out);
    result.addListener(consoleResultFormatter);

    // add the actual tests to the test suite
    Collection collection = new ArrayList();
    collection.add(SelfDiscoveryTest.class);
    for (Iterator iterator = collection.iterator(); iterator.hasNext(); ) {
      Class clazz = (Class) iterator.next();
      // run all methods starting with "test*"
      Method[] methods = clazz.getMethods();
      for (int i = 0; i < methods.length; i++) {
        if (methods[i].getName().startsWith("test")) {
          TestCase testCase;
          try {
            testCase = (TestCase) clazz.newInstance();
            testCase.setName(methods[i].getName());
            suite.addTest(testCase);
          } catch (InstantiationException e) {
            // may never happen
            e.printStackTrace();
          } catch (IllegalAccessException e) {
            // may never happen
            e.printStackTrace();
          }
        }
      }
    }

    // prepare to run tests
    final long start = System.currentTimeMillis();
    xmlResultFormatter.startTestSuite(jUnitTest);
    consoleResultFormatter.startTestSuite(jUnitTest);

    // run tests
    suite.run(result);

    // write stats and close reultformatter
    jUnitTest.setCounts(result.runCount(), result.failureCount(), result.errorCount());
    jUnitTest.setRunTime(System.currentTimeMillis() - start);
    xmlResultFormatter.endTestSuite(jUnitTest);
    consoleResultFormatter.endTestSuite(jUnitTest);

    // print success of failure
    if (result.wasSuccessful()) {
      System.exit(0);
    } else {
      if (result.errorCount() > 0) {
        System.err.println("Errors:");
        for (Enumeration errors = result.errors(); errors.hasMoreElements(); ) {
          TestFailure error = (TestFailure) errors.nextElement();
          System.err.println(error.trace());
        }
      }
      if (result.failureCount() > 0) {
        System.err.println("Failures:");
        for (Enumeration failures = result.failures(); failures.hasMoreElements(); ) {
          TestFailure failure = (TestFailure) failures.nextElement();
          System.err.println(failure.trace());
        }
      }
      System.exit(1);
    }
    ;
  }
  public boolean start() throws ContainerException {
    ContainerConfig.Container jc = ContainerConfig.getContainer("junit-container", configFile);

    // get the tests to run
    Iterator<ContainerConfig.Container.Property> ti = jc.properties.values().iterator();
    if (ti == null) {
      Debug.log("No tests to load", module);
      return true;
    }

    // load the tests into the suite
    TestSuite suite = new TestSuite();
    while (ti.hasNext()) {
      ContainerConfig.Container.Property prop = ti.next();
      Class<?> clz = null;
      try {
        clz = ObjectType.loadClass(prop.value);
        suite.addTestSuite(clz);
      } catch (Exception e) {
        Debug.logError(e, "Unable to load test suite class : " + prop.value, module);
      }
    }

    // holder for the results
    results = new TestResult();

    // run the tests
    suite.run(results);

    // dispay the results
    Debug.log(
        "[JUNIT] Pass: "******" | # Tests: "
            + results.runCount()
            + " | # Failed: "
            + results.failureCount()
            + " # Errors: "
            + results.errorCount(),
        module);
    if (Debug.infoOn()) {
      Debug.log(
          "[JUNIT] ----------------------------- ERRORS ----------------------------- [JUNIT]",
          module);
      Enumeration<?> err = results.errors();
      if (!err.hasMoreElements()) {
        Debug.log("None");
      } else {
        while (err.hasMoreElements()) {
          Debug.log("--> " + err.nextElement(), module);
        }
      }
      Debug.log(
          "[JUNIT] ------------------------------------------------------------------ [JUNIT]",
          module);
      Debug.log(
          "[JUNIT] ---------------------------- FAILURES ---------------------------- [JUNIT]",
          module);
      Enumeration<?> fail = results.failures();
      if (!fail.hasMoreElements()) {
        Debug.log("None");
      } else {
        while (fail.hasMoreElements()) {
          Debug.log("--> " + fail.nextElement(), module);
        }
      }
      Debug.log(
          "[JUNIT] ------------------------------------------------------------------ [JUNIT]",
          module);
    }

    return true;
  }