Java Code Examples for junit.framework.TestResult#addError()

The following examples show how to use junit.framework.TestResult#addError() . 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: Benchmark.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public final void run( TestResult result ) {
    try {
        Method testMethod = getClass().getMethod( name, emptyClassArray );
        for( int a=0; a<arguments.length; a++ ) {
            
            result.startTest( this );
            
            try {
                doOneArgument( testMethod, arguments[a] );
            } catch( AssertionFailedError err ) {
                result.addFailure( this, err );
            } catch( ThreadDeath td ) {
                throw td;                  // need to propagate this
            } catch( Throwable t ) {
                result.addError( this, t );
            }
            
            result.endTest( this );
        }
    } catch ( Exception e ) {
        e.printStackTrace();
    }
}
 
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: 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 4
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 5
Source File: TimeOutTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void run(TestResult result) {
    if (!canRun()) {
        return;
    }
    this.main = Thread.currentThread();
    
    TestResult mine = new TestResult();
    result.startTest(this);
    super.run(mine);
    
    if (mine.errorCount() != 0) {
        Enumeration en = mine.errors();
        while(en.hasMoreElements()) {
            TestFailure f = (TestFailure)en.nextElement();
            result.addError(this, f.thrownException());
        }
        return;
    }
    if (expectedResult != (mine.failureCount() == 0)) {
        result.addFailure(this, 
            new AssertionFailedError(
                "expectedResult: " + expectedResult + "failureCount: " + mine.failureCount() + " for " + getName()
            )
        );
        return;
    }
    
    result.endTest(this);
}
 
Example 6
Source File: ServiceTest.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
@Override
public void run(TestResult result) {
    result.startTest(this);

    try {

        Map<String, Object> serviceResult = dispatcher.runSync(serviceName, UtilMisc.toMap("test", this, "testResult", result));

        // do something with the errorMessage
        String errorMessage = (String) serviceResult.get(ModelService.ERROR_MESSAGE);
        if (UtilValidate.isNotEmpty(errorMessage)) {
            result.addFailure(this, new AssertionFailedError(errorMessage));
        }

        // do something with the errorMessageList
        List<Object> errorMessageList = UtilGenerics.checkList(serviceResult.get(ModelService.ERROR_MESSAGE_LIST));
        if (UtilValidate.isNotEmpty(errorMessageList)) {
            for (Object message: errorMessageList) {
                result.addFailure(this, new AssertionFailedError(message.toString()));
            }
        }

        // do something with the errorMessageMap
        Map<String, Object> errorMessageMap = UtilGenerics.cast(serviceResult.get(ModelService.ERROR_MESSAGE_MAP));
        if (!UtilValidate.isEmpty(errorMessageMap)) {
            for (Map.Entry<String, Object> entry: errorMessageMap.entrySet()) {
                result.addFailure(this, new AssertionFailedError(entry.getKey() + ": " + entry.getValue()));
            }
        }

    } catch (GenericServiceException e) {
        result.addError(this, e);
    }

    result.endTest(this);
}
 
Example 7
Source File: EntityXmlAssertTest.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
@Override
public void run(TestResult result) {
    result.startTest(this);

    try {
        URL entityXmlURL = FlexibleLocation.resolveLocation(entityXmlUrlString);
        List<Object> errorMessages = new LinkedList<Object>();

        if ("assert".equals(this.action)) {
            EntityDataAssert.assertData(entityXmlURL, delegator, errorMessages);
        } else if ("load".equals(this.action)) {
            EntitySaxReader reader = new EntitySaxReader(delegator);
            reader.parse(entityXmlURL);
        } else {
            // uh oh, bad value
            result.addFailure(this, new AssertionFailedError("Bad value [" + this.action + "] for action attribute of entity-xml element"));
        }

        if (UtilValidate.isNotEmpty(errorMessages)) {
            for (Object failureMessage: errorMessages) {
                result.addFailure(this, new AssertionFailedError(failureMessage.toString()));
            }
        }
    } catch (Exception e) {
        result.addError(this, e);
    }

    result.endTest(this);
}
 
Example 8
Source File: RawTestImpl.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run(TestResult result) {
	try {
		result.startTest(this);
		executeTest(this, testLocation);
	} catch (Throwable e) {
		result.addError(this, e);
	} finally {
		result.endTest(this);
	}
}
 
Example 9
Source File: MatcherTestImpl.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run(TestResult result) {
	try {
		result.startTest(this);
		executeTest();
	} catch (Throwable e) {
		result.addError(this, e);
	} finally {
		result.endTest(this);
	}
}
 
Example 10
Source File: JUnitTestSetup.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Used to invoke a caseSetUp method once, if one exists,
 * before all the test methods have been invoked
 */
private void callCaseMethods(ArrayList l, TestResult result) {
  if (l != null) {
    for (int i=0; i < l.size(); i++) {
      try {
        Method m = (Method)l.get(i);
        m.invoke(null, new Object[]{});
      } catch (Exception ex) {
        result.addError(this, ex);
      }
    }
  }
}
 
Example 11
Source File: JUnitTestSetup.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Used to invoke a caseSetUp method once, if one exists,
 * before all the test methods have been invoked
 */
private void callCaseMethods(ArrayList l, TestResult result) {
  if (l != null) {
    for (int i=0; i < l.size(); i++) {
      try {
        Method m = (Method)l.get(i);
        m.invoke(null, new Object[]{});
      } catch (Exception ex) {
        result.addError(this, ex);
      }
    }
  }
}
 
Example 12
Source File: ScriptTestAdapter.java    From groovy with Apache License 2.0 5 votes vote down vote up
public void run(TestResult result) {
    try {
        result.startTest(this);

        // let's run the script
        InvokerHelper.runScript(scriptClass, arguments);
        result.endTest(this);
    } catch (Exception e) {
        result.addError(this, e);
    }
}