当前位置: 首页>>代码示例>>Java>>正文


Java TestResult.addFailure方法代码示例

本文整理汇总了Java中junit.framework.TestResult.addFailure方法的典型用法代码示例。如果您正苦于以下问题:Java TestResult.addFailure方法的具体用法?Java TestResult.addFailure怎么用?Java TestResult.addFailure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在junit.framework.TestResult的用法示例。


在下文中一共展示了TestResult.addFailure方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkFailures

import junit.framework.TestResult; //导入方法依赖的package包/类
public static void checkFailures(TestCase test, TestResult res, String workDirPath) {
    StringBuffer t = text;
    if (t == null) {
        return;
    }
    synchronized (t) {
        if (t.length() > 0) {
            StringBuilder sb = new StringBuilder();
            sb.append("NbModuleSuite has been started with failOnMessage(");
            sb.append(msg);
            sb.append(") and failOnException(").append(exc);
            sb.append("). The following failures have been captured:\n");
            sb.append(normalize(text, workDirPath));
            res.addFailure(test, new AssertionFailedError(sb.toString()));
            t.setLength(0);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:NbModuleLogHandler.java

示例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;
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:26,代码来源:TestUtils.java

示例3: 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;
}
 
开发者ID:BeamFoundry,项目名称:spring-osgi,代码行数:27,代码来源:TestUtils.java

示例4: 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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:TimeOutTest.java

示例5: suite

import junit.framework.TestResult; //导入方法依赖的package包/类
public static Test suite() {
    System.setProperty("ignore.random.failures", "false");
    final Test t = NbTestSuite.linearSpeedSuite(LinearSpeedTest.class, 2,2);

    class ThisHasToFail extends TestCase {
        
        public int countTestCases() {
            return 1;
        }

        public String getName() {
            return "LinearSpeedTest";
        }

        public void run(TestResult testResult) {
            TestResult r = new TestResult();
            t.run(r);
            
            int count = r.errorCount() + r.failureCount();
            if (count == 0) {
                testResult.startTest(this);
                testResult.addFailure(this, new AssertionFailedError("LinearSpeedTest must fail: " + count));
                testResult.endTest(this);
            } else {
                testResult.startTest(this);
                testResult.endTest(this);
            }
        }
    }
    return new ThisHasToFail();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:LinearSpeedTest.java

示例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();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:Benchmark.java

示例7: run

import junit.framework.TestResult; //导入方法依赖的package包/类
@Override
public void run(TestResult result) {
    result.startTest(this);
    StringBuffer times = new StringBuffer("\n");
    AtomicLong min = new AtomicLong(Long.MAX_VALUE);
    AtomicLong max = new AtomicLong(Long.MIN_VALUE);
    iterateTests(result, times, suite, min, max);
    
    System.err.println(times.toString());
    
    if (max.longValue() > 3 * min.longValue()) {
        result.addFailure(this, new AssertionFailedError(times.toString()));
    }
    result.endTest(this);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:ExpandFolderTest.java

示例8: 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);
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:37,代码来源:ServiceTest.java

示例9: 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);
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:30,代码来源:EntityXmlAssertTest.java

示例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 = FastList.newInstance();

        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);
}
 
开发者ID:gildaslemoal,项目名称:elpi,代码行数:30,代码来源:EntityXmlAssertTest.java

示例11: runTest

import junit.framework.TestResult; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public void runTest(final Test test, final TestResult result) {
	final Thread waitingThread = Thread.currentThread();
	Thread thread = new Thread(test.toString()) {
		@Override
		public void run() {
			boolean timed_out = false;
			try {
				TimeoutTestSuite.super.runTest(test, result);
			} catch (ThreadDeath td) {
				timed_out = true;
			} finally {
				if (!timed_out) {
					waitingThread.interrupt();
				}
			}
		}
	};
	try {
		thread.start();
		Thread.sleep(DEFAULT_TIMEOUT_IN_MILLISECONDS);
		AssertionFailedError error = new AssertionFailedError(test.toString() + " failed to finish within " + timeoutInMilliseconds + " milliseconds.");
		error.setStackTrace(thread.getStackTrace());
		result.addFailure(test, error);
		thread.stop();
	} catch (InterruptedException e) {
		// ignore it, this means success
	}
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:31,代码来源:TimeoutTestSuite.java


注:本文中的junit.framework.TestResult.addFailure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。