@Override
 public void run(TestResult result) {
   super.run(result);
   if (!result.wasSuccessful()) {
     result.addFailure(this, new AssertionFailedError(mLog.toString()));
   }
 }
Beispiel #2
0
  public static void main(String[] args) throws Exception {
    checkForCompileErrors();
    checkClassHasNoMutableStaticFields(Winner.class);
    checkClassHasNoMutableStaticFields(QuizMaster.class);
    checkClassHasNoMutableStaticFields(Factorial.class);

    TestRunner runner = new TestRunner();
    TestSuite suite = new TestSuite();

    suite.addTestSuite(QuizMasterTest.class);
    suite.addTestSuite(WinnerTest.class);
    suite.addTestSuite(FactorialTest.class);

    TestResult result = runner.doRun(suite, false);

    int passed = result.runCount() - result.errorCount() - result.failureCount();
    int total = result.runCount();
    int max = 100;
    try {
      if (args.length > 0) max = Integer.parseInt(args[0]);
    } catch (Exception inogred) {

    }
    int score = (int) ((max * passed) / total);

    System.out.println(passed + " passed out of " + total);
    System.out.println("Score=" + score);
    System.exit(score);
  }
Beispiel #3
0
  /** Runs the tests and collects their result in a TestResult. */
  public void run(TestResult result) {
    // it probably make some sense to call result.run(this),
    // but, to avoid the suite being counted we try/catch ourselves
    try {
      setUp();
    } catch (AssertionFailedError e) {
      result.addFailure(this, e);
      return;
    } catch (ThreadDeath e) { // don't catch ThreadDeath by accident
      throw e;
    } catch (Throwable e) {
      result.addError(this, e);
      return;
    }

    for (Enumeration e = tests(); e.hasMoreElements(); ) {
      if (result.shouldStop()) break;
      Test test = (Test) e.nextElement();
      runTest(test, result);
    }

    try {
      tearDown();
    } catch (AssertionFailedError e) {
      result.addFailure(this, e);
      return;
    } catch (ThreadDeath e) { // don't catch ThreadDeath by accident
      throw e;
    } catch (Throwable e) {
      result.addError(this, e);
      return;
    }
  }
Beispiel #4
0
 @SuppressWarnings("unchecked")
 @Override
 public void run(TestResult result) {
   result.startTest(this);
   ScriptRuntime runtime =
       new ScriptRuntime(script, environment, false, new HashMap<String, Object>());
   runtime.setLabelEvaluator(new EnvironmentLabelEvaluator(label));
   runtime.run();
   // map the exception (if any)
   if (runtime.getException() != null) {
     result.addError(this, runtime.getException());
   }
   // check all the validations that occurred
   List<Validation<?>> validations = (List<Validation<?>>) runtime.getContext().get("$validation");
   for (Validation<?> validation : validations) {
     if (validation.getSeverity() == Severity.ERROR
         || validation.getSeverity() == Severity.CRITICAL) {
       result.addFailure(this, new AssertionFailedError(validation.toString()));
       if (!addAllFailures) {
         break;
       }
     }
   }
   result.endTest(this);
 }
  public static void main(String[] args) throws Exception {
    checkForCompileErrors();

    TestRunner runner = new TestRunner();
    TestSuite suite = new TestSuite();
    suite.addTestSuite(KeyValueMapTest.class);
    suite.addTestSuite(QueueTest.class);
    suite.addTestSuite(CallAStaticMethodTest.class);
    suite.addTestSuite(StaticMethodsAreEasyTest.class);
    suite.addTestSuite(UsingPublicFieldsIsEasyTest.class);
    suite.addTestSuite(GeocacheTest.class);
    suite.addTestSuite(StackTest.class);
    suite.addTestSuite(GeocacheListTest.class);

    TestResult result = runner.doRun(suite, false);

    int passed = result.runCount() - result.errorCount() - result.failureCount();
    int total = result.runCount();
    int max = 100;
    try {
      if (args.length > 0) max = Integer.parseInt(args[0]);
    } catch (Exception ignored) {

    }
    int score = (int) ((max * passed) / total);

    System.out.println(passed + " passed out of " + total);
    System.out.println("Score=" + score);
    System.exit(score);
  }
Beispiel #6
0
 public void testNoArgTestCasePasses() {
   Test t = new TestSuite(NoArgTestCaseTest.class);
   TestResult result = new TestResult();
   t.run(result);
   assertTrue(result.runCount() == 1);
   assertTrue(result.failureCount() == 0);
   assertTrue(result.errorCount() == 0);
 }
 public static void main(String[] args) {
   junit.framework.TestResult tr = junit.textui.TestRunner.run(suite());
   if (tr.errorCount() > 0 || tr.failureCount() > 0) {
     System.exit(1);
   } else {
     System.exit(0);
   }
 }
Beispiel #8
0
 public void testActiveRepeatedTest1() {
   Test test = new RepeatedTest(createActiveTestSuite(), 1);
   TestResult result = new TestResult();
   test.run(result);
   assertEquals(100, result.runCount());
   assertEquals(0, result.failureCount());
   assertEquals(0, result.errorCount());
 }
Beispiel #9
0
 private static List<TestFailure> createTestFailures(
     @NotNull InMemoryJavaGenerationHandler generationHandler, List<SModel> models) {
   List<TestFailure> testFailures = new ArrayList<TestFailure>();
   junit.framework.TestResult result = new junit.framework.TestResult();
   invokeTests(generationHandler, models, result, null);
   testFailures.addAll(Collections.list(result.failures()));
   testFailures.addAll(Collections.list(result.errors()));
   return testFailures;
 }
Beispiel #10
0
  public static void main(String[] argv) {

    TestResult result = new TestResult();
    TestCase testC = new TestSqlPersistent("testInsertObject");
    TestCase testD = new TestSqlPersistent("testSelectObject");

    testC.run(result);
    testD.run(result);
    System.out.println("TestSqlPersistent error count: " + result.failureCount());
  }
Beispiel #11
0
 private void addErrorMessage(TestResult testResult, String message) {
   String processedTestsMessage =
       myRunTests <= 0 ? "None of tests was run" : myRunTests + " tests processed";
   try {
     testResult.startTest(this);
     testResult.addError(this, new Throwable(processedTestsMessage + " before: " + message));
     testResult.endTest(this);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  /**
   * 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 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());
 }
Beispiel #14
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);
   }
 }
Beispiel #15
0
  public TestResult doRun(Test suite, boolean wait) {
    TestResult result = createTestResult();
    result.addListener(fPrinter);
    long startTime = System.currentTimeMillis();
    suite.run(result);
    long endTime = System.currentTimeMillis();
    long runTime = endTime - startTime;
    fPrinter.print(result, runTime);

    pause(wait);
    return result;
  }
  public static void main(String[] argv) {

    TestResult result = new TestResult();
    TestCase testA = new TestSql("testMetaData");
    TestCase testB = new TestSql("testDoubleNaN");
    TestCase testC = new TestSql("testAny");

    testA.run(result);
    testB.run(result);
    testC.run(result);
    System.out.println("TestSql error count: " + result.failureCount());
  }
 /** 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());
 }
Beispiel #18
0
 public void testExceptionRunningAndTearDown() {
   // This test documents the current behavior. With 1.4, we should
   // wrap the exception thrown while running with the exception thrown
   // while tearing down
   Test t =
       new TornDown() {
         public void tearDown() {
           throw new Error("tearDown");
         }
       };
   TestResult result = new TestResult();
   t.run(result);
   TestFailure failure = (TestFailure) result.errors().nextElement();
   assertEquals("tearDown", failure.thrownException().getMessage());
 }
 /* Run a single test and decide whether the test was
  * successful, meaningless, or a failure.  This is the
  * Template Method pattern abstraction of the inner loop in a
  * JML/JUnit test. */
 public void runTest() throws java.lang.Throwable {
   try {
     // The call being tested!
     doCall();
   } catch (org.jmlspecs.jmlrac.runtime.JMLEntryPreconditionError e) {
     // meaningless test input
     addMeaningless();
   } catch (org.jmlspecs.jmlrac.runtime.JMLAssertionError e) {
     // test failure
     int l = org.jmlspecs.jmlrac.runtime.JMLChecker.getLevel();
     org.jmlspecs.jmlrac.runtime.JMLChecker.setLevel(org.jmlspecs.jmlrac.runtime.JMLOption.NONE);
     try {
       java.lang.String failmsg = this.failMessage(e);
       junit.framework.AssertionFailedError err =
           new junit.framework.AssertionFailedError(failmsg);
       err.setStackTrace(new java.lang.StackTraceElement[] {});
       err.initCause(e);
       result.addFailure(this, err);
     } finally {
       org.jmlspecs.jmlrac.runtime.JMLChecker.setLevel(l);
     }
   } catch (java.lang.Throwable e) {
     // test success
   }
 }
Beispiel #20
0
  private void doRun(final Test testSuite) {
    setButtonLabel(fRun, "Stop");
    fRunner =
        new Thread("TestRunner-Thread") {
          public void run() {
            UnitTestRunner.this.start(testSuite);
            postInfo("Running...");

            long startTime = System.currentTimeMillis();
            testSuite.run(fTestResult);

            if (fTestResult.shouldStop()) {
              postInfo("Stopped");
            } else {
              long endTime = System.currentTimeMillis();
              long runTime = endTime - startTime;
              postInfo("Finished: " + elapsedTimeAsString(runTime) + " seconds");
            }
            runFinished(testSuite);
            setButtonLabel(fRun, "Run");
            showIDE(true);
            fRunner = null;
            System.gc();
          }
        };
    // make sure that the test result is created before we start the
    // test runner thread so that listeners can register for it.
    fTestResult = createTestResult();
    fTestResult.addListener(UnitTestRunner.this);
    aboutToStart(testSuite);

    fRunner.start();
  }
 /**
  * Runs the tests and collects their result in a TestResult.
  *
  * <p>We must override this method in order to run against JUnit4 which doesn't invoke tests().
  */
 public void run(TestResult result) {
   for (Enumeration e = tests(); e.hasMoreElements(); ) {
     Test each = (Test) e.nextElement();
     if (result.shouldStop()) break;
     runTest(each, result);
   }
 }
Beispiel #22
0
 @Override
 public void run(TestResult result) {
   for (int i = 0; i < fTimesRepeat; i++) {
     if (result.shouldStop()) break;
     super.run(result);
   }
 }
  /**
   * Handles test fail.
   *
   * @param result Test result.
   * @param origTest Original JUnit test.
   * @param e Exception thrown from grid.
   */
  private void handleFail(TestResult result, GridJunit3SerializableTest origTest, Throwable e) {
    // Simulate that all tests were run.
    origTest.getTest().run(result);

    // For the tests suite we assume that all tests failed because
    // entire test suite execution failed and there is no way to get
    // broken tests.
    if (origTest.getTest() instanceof GridJunit3TestSuiteProxy) {
      TestSuite suite = (((TestSuite) origTest.getTest()));

      for (int j = 0; j < suite.testCount(); j++) {
        result.addError(suite.testAt(j), e);
      }
    } else if (origTest.getTest() instanceof GridJunit3TestCaseProxy) {
      result.addError(origTest.getTest(), e);
    }
  }
Beispiel #24
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();
   }
 }
  public void executeAllReleaseTest(File releaseTestDirectory) {
    info("Execution des test contenus dans " + releaseTestDirectory.getAbsolutePath());

    SuiteBuilder suiteBuilder = new SuiteBuilder();
    XTest testSuite = suiteBuilder.createSuite(new File("."), releaseTestDirectory);

    info("" + testSuite.countTestCases() + " tests release trouvés ! ");

    TestResult testResult = junit.textui.TestRunner.run(testSuite);

    out.print(buildMessageIgnoredTests(testSuite));

    int errorCount = testResult.errorCount();
    if (errorCount != 0) {
      System.exit(-errorCount);
    }
  }
  @Override
  public void endTestSuite(TestResult result, long runTime) throws IOException {
    println("\ntests run: " + result.runCount());
    println("errors: " + result.errorCount());
    println("failures: " + result.failureCount());
    println("total run time: " + (runTime / 1000.0) + " seconds");
    println("test lengths in ascending order:");
    for (long duration : testTimes.keySet())
      println(testTimes.get(duration) + " - " + (duration / 1000.0) + " seconds");

    if (exception != null) {
      throw exception;
    }
    if ((out != System.out) && (out != System.err) && (out != null)) {
      out.close();
    }
  }
 public SuiteInfo(TestSuite suite) {
   this.suite = suite;
   name = suite.getName();
   name = name.substring(name.lastIndexOf('.') + 1);
   className = suite.getName();
   testCount = suite.countTestCases();
   result = new TestResult();
   result.addListener(this);
 }
Beispiel #28
0
 @Override
 public void run(final TestResult testResult) {
   List<Class> classes = myTestCaseLoader.getClasses();
   int totalTests = classes.size();
   for (final Class aClass : classes) {
     runNextTest(testResult, totalTests, aClass);
     if (testResult.shouldStop()) break;
   }
   tryGc(10);
 }
 /**
  * Report results as error, failure, or success (ignored), differently if result is null
  *
  * @param description the String description of the result
  * @param isError if true, report as failure
  * @param isFailure if true and not isError, report as failure
  * @param test the Test case
  * @param result the TestResult sink - ignored if null
  * @return 0
  */
 private static int reportResultToJUnit(
     String description, boolean isError, boolean isFailure, Test test, TestResult result) {
   if (null != result) {
     if (isError) {
       result.addError(test, new AssertionFailedError(description));
     } else if (isFailure) {
       result.addFailure(test, new AssertionFailedError(description));
     } // no need to log success
   } else { // have to throw failure
     if (isError) {
       String m = safeTestName(test) + " " + description;
       throw new Error(m);
     } else if (isFailure) {
       //                String m = safeTestName(test) + " " + description;
       throw new AssertionFailedError(description);
     } // no need to log success
   }
   return 0;
 }
 public void run(final TestResult result) {
   Protectable p =
       new Protectable() {
         public void protect() throws Exception {
           setUp();
           basicRun(result);
           tearDown();
         }
       };
   result.runProtected(this, p);
 }