FileDocCategorySizeDatePackage
TestResult.javaAPI DocAndroid 1.5 API4118Wed May 06 22:41:02 BST 2009junit.framework

TestResult

public class TestResult extends Object
A TestResult collects the results of executing a test case. It is an instance of the Collecting Parameter pattern. The test framework distinguishes between failures and errors. A failure is anticipated and checked for with assertions. Errors are unanticipated problems like an ArrayIndexOutOfBoundsException.
see
Test

Fields Summary
protected Vector
fFailures
protected Vector
fErrors
protected Vector
fListeners
protected int
fRunTests
private boolean
fStop
Constructors Summary
public TestResult()

		fFailures= new Vector<TestFailure>();
		fErrors= new Vector<TestFailure>();
		fListeners= new Vector<TestListener>();
		fRunTests= 0;
		fStop= false;
	
Methods Summary
public synchronized voidaddError(junit.framework.Test test, java.lang.Throwable t)
Adds an error to the list of errors. The passed in exception caused the error.

		fErrors.addElement(new TestFailure(test, t));
		for (Enumeration e= cloneListeners().elements(); e.hasMoreElements(); ) {
			((TestListener)e.nextElement()).addError(test, t);
		}
	
public synchronized voidaddFailure(junit.framework.Test test, junit.framework.AssertionFailedError t)
Adds a failure to the list of failures. The passed in exception caused the failure.

		fFailures.addElement(new TestFailure(test, t));
		for (Enumeration e= cloneListeners().elements(); e.hasMoreElements(); ) {
			((TestListener)e.nextElement()).addFailure(test, t);
		}
	
public synchronized voidaddListener(junit.framework.TestListener listener)
Registers a TestListener

		fListeners.addElement(listener);
	
private synchronized java.util.VectorcloneListeners()
Returns a copy of the listeners.

		return (Vector)fListeners.clone();
	
public voidendTest(junit.framework.Test test)
Informs the result that a test was completed.

		for (Enumeration e= cloneListeners().elements(); e.hasMoreElements(); ) {
			((TestListener)e.nextElement()).endTest(test);
		}
	
public synchronized interrorCount()
Gets the number of detected errors.

		return fErrors.size();
	
public synchronized java.util.Enumerationerrors()
Returns an Enumeration for the errors

		return fErrors.elements();
	
public synchronized intfailureCount()
Gets the number of detected failures.

		return fFailures.size();
	
public synchronized java.util.Enumerationfailures()
Returns an Enumeration for the failures

		return fFailures.elements();
	
public synchronized voidremoveListener(junit.framework.TestListener listener)
Unregisters a TestListener

		fListeners.removeElement(listener);
	
protected voidrun(junit.framework.TestCase test)
Runs a TestCase.

		startTest(test);
		Protectable p= new Protectable() {
			public void protect() throws Throwable {
				test.runBare();
			}
		};
		runProtected(test, p);

		endTest(test);
	
public synchronized intrunCount()
Gets the number of run tests.

		return fRunTests;
	
public voidrunProtected(junit.framework.Test test, junit.framework.Protectable p)
Runs a TestCase.

		try {
			p.protect();
		} 
		catch (AssertionFailedError e) {
			addFailure(test, e);
		}
		catch (ThreadDeath e) { // don't catch ThreadDeath by accident
			throw e;
		}
		catch (Throwable e) {
			addError(test, e);
		}
	
public synchronized booleanshouldStop()
Checks whether the test run should stop

		return fStop;
	
public voidstartTest(junit.framework.Test test)
Informs the result that a test will be started.

		final int count= test.countTestCases();
		synchronized(this) {
			fRunTests+= count;
		}
		for (Enumeration e= cloneListeners().elements(); e.hasMoreElements(); ) {
			((TestListener)e.nextElement()).startTest(test);
		}
	
public synchronized voidstop()
Marks that the test run should stop.

		fStop= true;
	
public synchronized booleanwasSuccessful()
Returns whether the entire test was successful or not.

		return failureCount() == 0 && errorCount() == 0;