junit.framework.TestResult Java Examples

The following examples show how to use junit.framework.TestResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TimeOutHasToPrintLogTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testThreadDumpPrinted() throws Exception {
    TimeOutHasToPrintLogTest t = new TimeOutHasToPrintLogTest("justTimeOutInOneOfMyMethods");
    
    TestResult res = t.run();
    
    assertEquals("One test has been run", 1, res.runCount());
    TestFailure failure = (TestFailure)res.failures().nextElement();
    String s = failure.exceptionMessage();

    if (s.indexOf("justTimeOutInOneOfMyMethods") == -1) {
        fail("There should be thread dump reported in case of timeout:\n" + s);
    }
    
    assertEquals("No error", 0, res.errorCount());
    assertEquals("One failure", 1, res.failureCount());
}
 
Example #2
Source File: ExpandFolderTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void iterateTests(TestResult result, StringBuffer times, TestSuite suite, AtomicLong min, AtomicLong max) {
    Enumeration en = suite.tests();
    while (en.hasMoreElements()) {
        Test t = (Test)en.nextElement();
        if (t instanceof Callable) {
            try {
                Long v = (Long)((Callable) t).call();
                long time = v.longValue();
                if (time < min.longValue()) {
                    min.set(time);
                }
                if (time > max.longValue()) {
                    max.set(time);
                }
                // append(t.toString()).append(" value: ")
                times.append("Run: ").append(v).append('\n');
            } catch (Exception ex) {
                result.addError(this, ex);
            }
        }
        if (t instanceof TestSuite) {
            iterateTests(result, times, (TestSuite)t, min, max);
        }
    }
}
 
Example #3
Source File: LoggingTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testMyExceptionWithStackTrace() throws Exception {
    LoggingTest inner = new LoggingTest("throwMyThrowable");
    
    class MyEx extends Exception {
    }
    
    inner.toThrow = new MyEx();
    inner.toMsg = new MyEx();
    
    TestResult res = inner.run();
    assertEquals("One error", 1, res.errorCount());
    assertEquals("No failure", 0, res.failureCount());
    
    TestFailure f = (TestFailure)res.errors().nextElement();
    
    if (
        f.exceptionMessage() == null || 
        f.exceptionMessage().indexOf("Going to throw") == -1 ||
        f.exceptionMessage().indexOf("testMyExceptionWithStackTrace") == -1
   ) {
        fail("There should be output of the log:\n" + f.exceptionMessage());
    }
}
 
Example #4
Source File: FunctionalTestClassTestSuite.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void runTest(Test test, TestResult testResult) {
	testPosition++;
	if ( environmentSetupError != null ) {
		testResult.startTest( test );
		testResult.addError( test, environmentSetupError );
		testResult.endTest( test );
		return;
	}
	if ( ! ( test instanceof FunctionalTestCase ) ) {
		super.runTest( test, testResult );
	}
	else {
		FunctionalTestCase functionalTest = ( ( FunctionalTestCase ) test );
		try {
			// disallow rebuilding the schema because this is the last test
			// in this suite, thus it is about to get dropped immediately
			// afterwards anyway...
			environment.setAllowRebuild( testPosition < testCount );
			functionalTest.setEnvironment( environment );
			super.runTest( functionalTest, testResult );
		}
		finally {
			functionalTest.setEnvironment( null );
		}
	}
}
 
Example #5
Source File: NbTestCaseTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testJustRunTestCase() {
    class Fail extends NbTestCase {
        public Fail() {
            super("testFail");
        }

        public void testFail() {
            throw new IllegalStateException();
        }
    }

    Fail f = new Fail();

    TestResult res = new TestResult();
    f.run(res);

    assertEquals("One error", 1, res.errorCount());


}
 
Example #6
Source File: BaseTestSetup.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
   * Setup the security manager for this Derby decorator/TestSetup
   * and then call the part's run method to run the decorator and
   * the test it wraps.
   */
  public final void run(TestResult result)
  {
      // install a default security manager if one has not already been
      // installed
      if ( System.getSecurityManager() == null )
      {
/* gd          if (TestConfiguration.getCurrent().defaultSecurityManagerSetup())
          {
              BaseTestCase.assertSecurityManager();
          }
*/
      }
      
      super.run(result);
  }
 
Example #7
Source File: FunctionalTestClassTestSuite.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void run(TestResult testResult) {
	if ( testCount == 0 ) {
		// might be zero if database-specific...
		return;
	}
	try {
		log.info( "Starting test-suite [" + getName() + "]" );
		setUp();
		testPosition = 0;
		super.run( testResult );
	}
	finally {
		try {
			tearDown();
		}
		catch( Throwable ignore ) {
		}
		log.info( "Completed test-suite [" + getName() + "]" );
	}
}
 
Example #8
Source File: ProfilesTrackerTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void run(TestResult result) {
    for(int i = 0; i < ENV.length; i++) {
        String contents = (String) ENV[i][0];
        String folder = (String) ENV[i][1];
        String type = (String) ENV[i][2];
        
        for(int j = 0; j < testCount(); j++) {
            Test test = testAt(j);
            if (test instanceof ProfilesTrackerTest) {
                ((ProfilesTrackerTest) test).setEnv(type, folder, contents);
            }
        }

        System.out.println("Running tests for: " + type);
        super.run(result);
    }
}
 
Example #9
Source File: GroupedTest.java    From jenkins-test-harness with MIT License 6 votes vote down vote up
@Override
public void run(TestResult result) {
    try {
        setUp();
        try {
            runGroupedTests(result);
        } finally {
            tearDown();
        }
        // everything went smoothly. report a successful test to make the ends meet
        runTest(new FailedTest(getClass(),null),result);
    } catch (Throwable e) {
        // something went wrong
        runTest(new FailedTest(getClass(),e),result);
    }
}
 
Example #10
Source File: ResultPrinter.java    From tomee with Apache License 2.0 6 votes vote down vote up
/**
 * Prints the header of the report
 */
public void printHeader(final TestResult result) {
    if (result.wasSuccessful()) {
        writer().println();
        writer().print("OK");
        writer().println(" (" + result.runCount() + " tests)");

    } else {
        writer().println();
        writer().println("FAILURES!!!");
        writer().println("~~ Test Results ~~~~~~~~~~~~");
        writer().println("      Run: " + result.runCount());
        writer().println(" Failures: " + result.failureCount());
        writer().println("   Errors: " + result.errorCount());
    }
}
 
Example #11
Source File: NbTestCase.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Runs the test case, while conditionally skip some according to result of
 * {@link #canRun} method.
 */
@Override
public void run(final TestResult result) {
    if (canRun()) {
        System.setProperty("netbeans.full.hack", "true"); // NOI18N
        System.setProperty("java.util.prefs.PreferencesFactory",
                MemoryPreferencesFactory.class.getName());//NOI18N
        try {
            Preferences.userRoot().sync();
        } catch(BackingStoreException bex) {}
        Level lev = logLevel();
        if (lev != null) {
            Log.configure(lev, logRoot(), NbTestCase.this);
        }
        super.run(result);
    }
}
 
Example #12
Source File: NullableUniqueConstraintTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void main(String [] args) {
    TestResult tr = new TestResult();
    Test t = suite();
    t.run(tr);
    System.out.println(tr.errorCount());
    Enumeration e = tr.failures();
    while (e.hasMoreElements()) {
        ((TestFailure)e.nextElement ()).thrownException().printStackTrace();
    }
    System.out.println(tr.failureCount());
}
 
Example #13
Source File: TestRequestBuilderTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Override
public void run(TestResult testResult) {
  testResult.startTest(this);
  try {
    fail("broken");
  } finally {
    testResult.endTest(this);
  }
}
 
Example #14
Source File: TestTCK.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Execute the stress tests a couple of times.
 * 
 * @throws Exception
 */
public void test_stressTests() throws Exception {

    for (int i = 0; i < 100; i++) {
        final TestSuite suite = new TestSuite(
            TCKStressTests.class.getSimpleName());

        suite.addTestSuite(TCKStressTests.class);
        suite.run(new TestResult());
    }
}
 
Example #15
Source File: TestCaseTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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);
}
 
Example #16
Source File: TestSqlPersistent.java    From evosql with Apache License 2.0 5 votes vote down vote up
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());
    }
 
Example #17
Source File: AnnotationsTest.java    From annotation-tools with MIT License 5 votes vote down vote up
/**
 * Runs all the tests in {@link #allTests} and displays the failure and error
 * counts.
 */
public static void main(String[] args) {
  TestSuite suite = new TestSuite(AnnotationsTest.class);
  TestResult result = new TestResult();
  suite.run(result);
  System.out.println(
      "AnnotationsTests ran with " + result.failureCount() + " failures and "
      + result.errorCount() + " errors. (" + result.runCount()
      + " successes.)");
}
 
Example #18
Source File: J2eeTestCaseGlassfishTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testAddEmptyTestIntoEmptyConfiguration() {
    Configuration conf = NbModuleSuite.emptyConfiguration();
    conf = J2eeTestCase.addServerTests(ANY, conf, TD.class).gui(false);
    Test t = conf.suite();
    t.run(new TestResult());
    assertEquals("just one empty test", 1, t.countTestCases());
    assertNull("testA was not running", System.getProperty("testA"));
}
 
Example #19
Source File: RunUnitTests.java    From annotation-tools with MIT License 5 votes vote down vote up
public static void main(String[] args) {
    TestSuite suite = new TestSuite(RunUnitTests.class);
    TestResult result = new TestResult();
    suite.run(result);
    System.out.println(
            "AnnotationsTests ran with "
                    + result.failureCount()
                    + " failures and "
                    + result.errorCount()
                    + " errors. ("
                    + result.runCount()
                    + " successes.)");
}
 
Example #20
Source File: J2eeTestCaseTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testAnyServer() {
    System.setProperty("tomcat.home", getDataDir().getPath());
    Configuration conf = NbModuleSuite.createConfiguration(TD.class);
    conf = J2eeTestCase.addServerTests(conf).gui(false);
    Test t = NbModuleSuite.create(conf);
    t.run(new TestResult());
    assertEquals("both TD tests and emptyTest", 3, t.countTestCases());
}
 
Example #21
Source File: LoggingTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testIOExceptionIsWrappedWithLogMsg() throws Exception {
    
    LoggingTest inner = new LoggingTest("throwIOThrowable");
    inner.toThrow = new IOException("Ahoj");
    
    TestResult res = inner.run();
    assertEquals("One error", 1, res.errorCount());
    assertEquals("No failure", 0, res.failureCount());
    
    TestFailure f = (TestFailure)res.errors().nextElement();
    
    if (f.exceptionMessage().indexOf("Going to throw") == -1) {
        fail("There should be output of the log:\n" + f.exceptionMessage());
    }
}
 
Example #22
Source File: MyUiAutomatorTestRunner.java    From PUMA with Apache License 2.0 5 votes vote down vote up
@Override
public void print(TestResult result, long runTime, Bundle testOutput) {
	printHeader(runTime);
	if (mFullOutput) {
		printErrors(result);
		printFailures(result);
	}
	printFooter(result);
}
 
Example #23
Source File: JellyTestSuiteBuilder.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
@Override
protected void runGroupedTests(final TestResult result) throws Exception {
    h.executeOnServer(new Callable<Object>() {
        // this code now inside a request handling thread
        public Object call() throws Exception {
            doTests(result);
            return null;
        }
    });
}
 
Example #24
Source File: JUnitTestSetup.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void run(TestResult result) {
  try {
    callCaseMethods(fCaseSetUp, result);    
    basicRun(result);
    //getTest().run(result);
    //for (Enumeration e= tests(); e.hasMoreElements(); ) {
    //  if (result.shouldStop() )
    //    break;
    //    Test test= (Test)e.nextElement();
    //    test.run(result);
    //  }
  } finally {
    callCaseMethods(fCaseTearDown, result);
  }
}
 
Example #25
Source File: J2eeTestCaseTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testNoServer() {
    Configuration conf = NbModuleSuite.createConfiguration(TD.class);
    conf = J2eeTestCase.addServerTests(conf).gui(false);
    Test t = NbModuleSuite.create(conf);
    t.run(new TestResult());
    assertEquals("just empty test - no server is registered", 1, t.countTestCases());
}
 
Example #26
Source File: RepeatedTestTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testRepeatedOnce() {
	Test test= new RepeatedTest(fSuite, 1);
	assertEquals(2, test.countTestCases());
	TestResult result= new TestResult();
	test.run(result);
	assertEquals(2, result.runCount());
}
 
Example #27
Source File: LinearSpeedTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static Test suite() {
    System.setProperty("ignore.random.failures", "false");
    final Test t = NbTestSuite.linearSpeedSuite(LinearSpeedTest.class, 2,2);

    class ThisHasToFail extends TestCase {
        
        public int countTestCases() {
            return 1;
        }

        public String getName() {
            return "LinearSpeedTest";
        }

        public void run(TestResult testResult) {
            TestResult r = new TestResult();
            t.run(r);
            
            int count = r.errorCount() + r.failureCount();
            if (count == 0) {
                testResult.startTest(this);
                testResult.addFailure(this, new AssertionFailedError("LinearSpeedTest must fail: " + count));
                testResult.endTest(this);
            } else {
                testResult.startTest(this);
                testResult.endTest(this);
            }
        }
    }
    return new ThisHasToFail();
}
 
Example #28
Source File: TestMultiInsert.java    From evosql with Apache License 2.0 5 votes vote down vote up
public static void main(String[] argv) {

        TestResult result = new TestResult();
        TestCase   testA  = new TestMultiInsert("testMultiInsert");

        testA.run(result);
        System.out.println("TestMultiInsert error count: " + result.failureCount());
        Enumeration e = result.failures();
        while(e.hasMoreElements()) System.out.println(e.nextElement());
    }
 
Example #29
Source File: BSFTest.java    From commons-bsf with Apache License 2.0 5 votes vote down vote up
public static void main(String args[]) {
    TestRunner runner = new TestRunner();
    TestSuite suite = (TestSuite) suite();
    TestResult results;

    for (int i = 0; i < suite.testCount(); i++) {
        System.out.print(testNames[i]);
        results = runner.doRun(suite.testAt(i), false);
        System.out.println("Results: " + results.runCount() + 
                           " tests run, " + results.failureCount() +
                           " failures, " + results.errorCount() +
                           " errors.");
        System.out.print("\n----------------------------------------\n");
    }
}
 
Example #30
Source File: JSR166TestCase.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected void printFooter(TestResult result) {
    if (result.wasSuccessful()) {
        getWriter().println("OK (" + result.runCount() + " tests)"
            + "  Time: " + elapsedTimeAsString(runTime));
    } else {
        getWriter().println("Time: " + elapsedTimeAsString(runTime));
        super.printFooter(result);
    }
}