本文整理汇总了Java中junit.framework.TestResult.addError方法的典型用法代码示例。如果您正苦于以下问题:Java TestResult.addError方法的具体用法?Java TestResult.addError怎么用?Java TestResult.addError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类junit.framework.TestResult
的用法示例。
在下文中一共展示了TestResult.addError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: iterateTests
import junit.framework.TestResult; //导入方法依赖的package包/类
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);
}
}
}
示例2: cloneTestResults
import junit.framework.TestResult; //导入方法依赖的package包/类
/**
* Clones the test result from a TestResult loaded through a different
* classloader.
*
* @param source test result loaded through a different classloader
* @param destination test result reported to the outside framework
* @param test initial test used for bootstrapping the integration framework
* @return cloned test result
*/
public static TestResult cloneTestResults(OsgiTestInfoHolder source, TestResult destination, Test test) {
// get errors
for (Throwable throwable : source.getTestErrors()) {
destination.addError(test, throwable);
}
// get failures
// since failures are a special JUnit error, we have to clone the stack
for (Throwable originalFailure : source.getTestFailures()) {
AssertionFailedError clonedFailure = new AssertionFailedError(originalFailure.getMessage());
clonedFailure.setStackTrace(originalFailure.getStackTrace());
destination.addFailure(test, clonedFailure);
}
return destination;
}
示例3: runTest
import junit.framework.TestResult; //导入方法依赖的package包/类
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: cloneTestResults
import junit.framework.TestResult; //导入方法依赖的package包/类
/**
* Clones the test result from a TestResult loaded through a different
* classloader.
*
* @param source test result loaded through a different classloader
* @param destination test result reported to the outside framework
* @param test initial test used for bootstrapping the integration framework
* @return cloned test result
*/
public static TestResult cloneTestResults(OsgiTestInfoHolder source, TestResult destination, Test test) {
// get errors
for (Iterator iter = source.getTestErrors().iterator(); iter.hasNext();) {
destination.addError(test, (Throwable) iter.next());
}
// get failures
// since failures are a special JUnit error, we have to clone the stack
for (Iterator iter = source.getTestFailures().iterator(); iter.hasNext();) {
Throwable originalFailure = (Throwable) iter.next();
AssertionFailedError clonedFailure = new AssertionFailedError(originalFailure.getMessage());
clonedFailure.setStackTrace(originalFailure.getStackTrace());
destination.addFailure(test, clonedFailure);
}
return destination;
}
示例5: run
import junit.framework.TestResult; //导入方法依赖的package包/类
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: run
import junit.framework.TestResult; //导入方法依赖的package包/类
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();
}
}
示例7: run
import junit.framework.TestResult; //导入方法依赖的package包/类
@Override
public void run(TestResult result)
{
try
{
setUp();
super.run(result);
tearDown();
}
catch (Exception e)
{
result.addError(this, e);
}
}
示例8: runTest
import junit.framework.TestResult; //导入方法依赖的package包/类
/**
* Run fixture setup, test from the given test case and fixture teardown.
*
* @param osgiTestExtensions
* @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(rawTest, ex);
}
return result;
}
示例9: run
import junit.framework.TestResult; //导入方法依赖的package包/类
@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);
}
示例10: run
import junit.framework.TestResult; //导入方法依赖的package包/类
@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);
}
示例11: run
import junit.framework.TestResult; //导入方法依赖的package包/类
@Override
public void run(TestResult result) {
try {
result.startTest(this);
executeTest(this, testLocation);
} catch (Throwable e) {
result.addError(this, e);
} finally {
result.endTest(this);
}
}
示例12: run
import junit.framework.TestResult; //导入方法依赖的package包/类
@Override
public void run(TestResult result) {
try {
result.startTest(this);
executeTest();
} catch (Throwable e) {
result.addError(this, e);
} finally {
result.endTest(this);
}
}
示例13: callCaseMethods
import junit.framework.TestResult; //导入方法依赖的package包/类
/**
* 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);
}
}
}
}
示例14: run
import junit.framework.TestResult; //导入方法依赖的package包/类
public void run(TestResult result) {
try {
result.startTest(this);
// lets run the script
InvokerHelper.runScript(scriptClass, arguments);
result.endTest(this);
}
catch (Exception e) {
result.addError(this, e);
}
}
示例15: run
import junit.framework.TestResult; //导入方法依赖的package包/类
@Override
public void run(TestResult result) {
result.startTest(this);
TypeScriptGenerator gents;
try {
gents = new TypeScriptGenerator(this.testOptions);
String basename = gents.pathUtil.getFilePathWithoutExtension(sourceFile.getName());
String sourceText = getFileText(sourceFile);
String goldenText = getFileText(goldenFile);
ByteArrayOutputStream errStream = new ByteArrayOutputStream();
gents.setErrorStream(new PrintStream(errStream));
GentsResult gentsResult =
gents.generateTypeScript(
Collections.singleton(sourceFile.getName()),
Collections.singletonList(SourceFile.fromCode(sourceFile.getName(), sourceText)),
Collections.<SourceFile>emptyList());
Map<String, String> transpiledSource = gentsResult.sourceFileMap;
String errors = new String(errStream.toByteArray(), StandardCharsets.UTF_8);
assertThat(errors).isEmpty();
assertThat(gents.hasErrors()).isFalse();
assertThat(transpiledSource).hasSize(1);
assertThat(transpiledSource).containsKey(basename);
assertThat(transpiledSource.get(basename)).isEqualTo(goldenText);
} catch (Throwable t) {
result.addError(this, t);
} finally {
result.endTest(this);
}
}