junit.framework.TestResult#addError ( )源码实例Demo

下面列出了junit.framework.TestResult#addError ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: Benchmark.java
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();
    }
}
 
源代码2 项目: netbeans   文件: ExpandFolderTest.java
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);
        }
    }
}
 
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 );
		}
	}
}
 
源代码4 项目: tomee   文件: TestSuite.java
/**
 * 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);
    }
}
 
源代码5 项目: netbeans   文件: TimeOutTest.java
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);
}
 
源代码6 项目: scipio-erp   文件: ServiceTest.java
@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);
}
 
源代码7 项目: scipio-erp   文件: EntityXmlAssertTest.java
@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);
}
 
源代码8 项目: tm4e   文件: RawTestImpl.java
@Override
public void run(TestResult result) {
	try {
		result.startTest(this);
		executeTest(this, testLocation);
	} catch (Throwable e) {
		result.addError(this, e);
	} finally {
		result.endTest(this);
	}
}
 
源代码9 项目: tm4e   文件: MatcherTestImpl.java
@Override
public void run(TestResult result) {
	try {
		result.startTest(this);
		executeTest();
	} catch (Throwable e) {
		result.addError(this, e);
	} finally {
		result.endTest(this);
	}
}
 
源代码10 项目: gemfirexd-oss   文件: JUnitTestSetup.java
/**
 * 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);
      }
    }
  }
}
 
源代码11 项目: gemfirexd-oss   文件: JUnitTestSetup.java
/**
 * 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);
      }
    }
  }
}
 
源代码12 项目: groovy   文件: ScriptTestAdapter.java
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);
    }
}