Java Code Examples for junit.framework.Test#run()

The following examples show how to use junit.framework.Test#run() . 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: TestSuite.java    From tomee with Apache License 2.0 6 votes vote down vote up
/**
 * Runs the tests and collects their result in a TestResult.
 */
public void run(final TestResult result) {
    try {
        final List<Test> tests = getTests();
        if (tests.size() == 0) return;

        setUp();

        try {
            for (final Test test : tests) {
                if (result.shouldStop()) break;
                test.run(result);
            }
        } finally {
            tearDown();
        }

    } catch (final Exception e) {
        result.addError(this, e);
    }
}
 
Example 2
Source File: SuiteTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testNoTestCases() {
	Test t= new TestSuite(NoTestCases.class);
	t.run(fResult);
	assertTrue(fResult.runCount() == 1);  // warning test
	assertTrue(fResult.failureCount() == 1);
	assertTrue(! fResult.wasSuccessful());
}
 
Example 3
Source File: ActiveTestTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testActiveTest() {		
	Test test= createActiveTestSuite(); 
	TestResult result= new TestResult();
	test.run(result);
	assertEquals(100, result.runCount());
	assertEquals(0, result.failureCount());
	assertEquals(0, result.errorCount());
}
 
Example 4
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 5
Source File: RepeatedTestTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testRepeatedMoreThanOnce() {
	Test test= new RepeatedTest(fSuite, 3);
	assertEquals(6, test.countTestCases());
	TestResult result= new TestResult();
	test.run(result);
	assertEquals(6, result.runCount());
}
 
Example 6
Source File: ActiveTestTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testActiveRepeatedTest0() {		
	Test test= new RepeatedTest(createActiveTestSuite(), 0);
	TestResult result= new TestResult();
	test.run(result);
	assertEquals(0, result.runCount());
	assertEquals(0, result.failureCount());
	assertEquals(0, result.errorCount());
}
 
Example 7
Source File: NullableUniqueConstraintTest.java    From gemfirexd-oss with Apache License 2.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 8
Source File: JUnitServlet.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
void runTestSuite( String testClassName ) {
    Test suite = getTest( testClassName );

    if (suite != null) {
        TestResult testResult = new TestResult();
        testResult.addListener( this );
        long startTime= System.currentTimeMillis();
        suite.run( testResult );
        long endTime= System.currentTimeMillis();
        _formatter.displayResults( _writer, testClassName, elapsedTimeAsString( endTime-startTime ), testResult );
    }
}
 
Example 9
Source File: J2eeTestCaseGlassfishTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testCreateAllModulesServerSuiteWithoutFiles() throws IOException {
    setGlassfishHome(true);
    Test t = J2eeTestCase.createAllModulesServerSuite(ANY, TD.class);
    t.run(new TestResult());
    assertEquals("both tests", 3, t.countTestCases());
    assertEquals("testA was running", "AAA", System.getProperty("testA"));
}
 
Example 10
Source File: J2eeTestCaseGlassfishTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testGlassfishWithDomain() throws IOException {
    setGlassfishHome(true);
    Configuration conf = NbModuleSuite.createConfiguration(TD.class);
    conf = J2eeTestCase.addServerTests(GLASSFISH, conf, "testA", "testB").gui(false);
    Test t = conf.suite();
    t.run(new TestResult());
    assertEquals("both tests", 2, t.countTestCases());
}
 
Example 11
Source File: SuiteTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testOneTestCase() {
	Test t= new TestSuite(OneTestCase.class);
	t.run(fResult);
	assertTrue(fResult.runCount() == 1);  
	assertTrue(fResult.failureCount() == 0);
	assertTrue(fResult.errorCount() == 0);
	assertTrue(fResult.wasSuccessful());
}
 
Example 12
Source File: NbModuleSuite2Test.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testServices() throws Exception{
    Configuration conf = NbModuleSuite.createConfiguration(NbModuleSuiteMeta.class).gui(false);
    Test test = conf.suite();
    test.run(new TestResult());
    assertNotNull("The test was running", System.getProperty("meta"));
    assertEquals("result" + System.getProperty("meta"), "ok", System.getProperty("meta"));
}
 
Example 13
Source File: NullableUniqueConstraintTest.java    From gemfirexd-oss with Apache License 2.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 14
Source File: J2eeTestCaseTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testAnyServerByNames() {
    System.setProperty("jboss.home", getDataDir().getPath());
    Configuration conf = NbModuleSuite.createConfiguration(TD.class);
    conf = J2eeTestCase.addServerTests(conf, "testA", "testB").gui(false);
    Test t = NbModuleSuite.create(conf);
    t.run(new TestResult());
    assertEquals("both TD tests and emptyTest", 2, t.countTestCases());
}
 
Example 15
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 16
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 17
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 18
Source File: ActiveTestTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testActiveRepeatedTest() {		
	Test test= new RepeatedTest(createActiveTestSuite(), 5);
	TestResult result= new TestResult();
	test.run(result);
	assertEquals(500, result.runCount());
	assertEquals(0, result.failureCount());
	assertEquals(0, result.errorCount());
}
 
Example 19
Source File: ActiveTestTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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());
}
 
Example 20
Source File: SuiteTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void testNoTestCaseClass() {
	Test t= new TestSuite(NoTestCaseClass.class);
	t.run(fResult);
	assertEquals(1, fResult.runCount());  // warning test
	assertTrue(! fResult.wasSuccessful());
}