Code example for TestResult

Methods: addError, runProtected

0
	 * @param testName 
	 */ 
	protected TestResult runTest(final OsgiJUnitTest osgiTestExtensions, String testName) {
		if (log.isDebugEnabled())
			log.debug("Running test [" + testName + "] on testCase " + osgiTestExtensions);
		final TestResult result = new TestResult();
		TestCase rawTest = osgiTestExtensions.getTestCase();
 
		rawTest.setName(testName);
 
		try { 
			osgiTestExtensions.osgiSetUp();
 
			try { 
				// use TestResult method to bypass the setUp/tearDown methods 
				result.runProtected(rawTest, new Protectable() {
 
					public void protect() throws Throwable { 
						osgiTestExtensions.osgiRunTest();
					} 
 
				}); 
			} 
			finally { 
				osgiTestExtensions.osgiTearDown();
			} 
 
		} 
		// exceptions thrown by osgiSetUp/osgiTearDown 
		catch (Exception ex) {
			log.error("test exception threw exception ", ex);
			result.addError((Test) rawTest, ex);
		} 
		return result;
	} 
}