Code example for TestResult

Methods: errorCount, failureCount, runCount

0
		result = new TestResult();
	} 
 
	public void testAssertionPass() { 
		executeTest("testAssertionPass"); 
		assertEquals(0, result.errorCount());
		assertEquals(0, result.failureCount());
	} 
 
	public void testAssertionFailure() { 
		executeTest("testAssertionFailure"); 
		assertEquals("failure counted as error", 0, result.errorCount());
		assertEquals("failure ignored", 1, result.failureCount());
 
	} 
 
	public void testFailure() { 
		executeTest("testFailure"); 
		assertEquals("failure counted as error", 0, result.errorCount());
		assertEquals("failure ignored", 1, result.failureCount());
	} 
 
	public void testException() { 
		executeTest("testException"); 
		assertEquals("error not considered", 1, result.errorCount());
		assertEquals("error considered failure", 0, result.failureCount());
	} 
 
	public void testExceptionClass() throws Exception { 
		executeTest("testException"); 
		TestFailure failure = (TestFailure) result.errors().nextElement();
		assertTrue(failure.thrownException() instanceof RuntimeException);
	} 
 
	public void testError() { 
		executeTest("testError"); 
		assertEquals("error not considered", 1, result.errorCount());
		assertEquals("error considered failure", 0, result.failureCount());
	} 
 
	public void testErrorClass() throws Exception { 
		executeTest("testError"); 
		TestFailure failure = (TestFailure) result.errors().nextElement();
		assertTrue(failure.thrownException() instanceof Error);
	} 
 
	private void executeTest(String testMethod) {
		test.setName(testMethod);
		test.run(result);
		assertEquals(1, result.runCount());
	} 
}