本文整理汇总了Java中junit.framework.TestResult.errors方法的典型用法代码示例。如果您正苦于以下问题:Java TestResult.errors方法的具体用法?Java TestResult.errors怎么用?Java TestResult.errors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类junit.framework.TestResult
的用法示例。
在下文中一共展示了TestResult.errors方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: executeTest
import junit.framework.TestResult; //导入方法依赖的package包/类
protected void executeTest(Class test, Permission missingPermission) {
TestSuite suite = new TestSuite();
suite.addTestSuite(test);
TestResult result = new TestResult();
suite.run(result);
if (result.wasSuccessful()) {
if (missingPermission == null) {
return;
} else {
fail("Security test expected an AccessControlException on " + missingPermission + ", but did not receive one");
}
} else {
if (missingPermission == null) {
new SecurityTestResultPrinter(System.out).print(result);
fail("Security test was expected to run successfully, but failed (results on System.out)");
} else {
//There may be more than 1 failure: iterate to ensure that they all match the missingPermission.
boolean otherFailure = false;
for (Enumeration e = result.errors(); e.hasMoreElements();) {
TestFailure failure = (TestFailure) e.nextElement();
if (failure.thrownException() instanceof AccessControlException) {
AccessControlException ace = (AccessControlException) failure.thrownException();
if (missingPermission.implies(ace.getPermission())) {
continue;
}
}
otherFailure = true;
break;
}
if (otherFailure) {
new SecurityTestResultPrinter(System.out).print(result);
fail("Security test expected an AccessControlException on " + missingPermission + ", but failed for other reasons (results on System.out)");
}
}
}
}