use of junit.framework.TestFailure in project tomee by apache.
the class ResultPrinter method printFailures.
public void printFailures(final TestResult result) {
if (result.failureCount() != 0) {
writer().println("\n~~ Failure Results ~~~~~~~~~\n");
if (result.failureCount() == 1)
writer().println("There was " + result.failureCount() + " failure:");
else
writer().println("There were " + result.failureCount() + " failures:");
int i = 1;
writer().println("\nFailure Summary:");
for (final Enumeration e = result.failures(); e.hasMoreElements(); i++) {
final TestFailure failure = (TestFailure) e.nextElement();
writer().println(i + ") " + failure.failedTest());
}
i = 1;
writer().println("\nFailure Details:");
for (final Enumeration e = result.failures(); e.hasMoreElements(); i++) {
final TestFailure failure = (TestFailure) e.nextElement();
writer().println("\n" + i + ") " + failure.failedTest());
final Throwable t = failure.thrownException();
if (t.getMessage() != null)
writer().println("\t\"" + t.getMessage() + "\"");
else {
writer().println();
failure.thrownException().printStackTrace();
}
}
}
}
use of junit.framework.TestFailure in project groovy-core by groovy.
the class SecurityTestSupport method executeTest.
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)");
}
}
}
}
use of junit.framework.TestFailure in project jna by java-native-access.
the class WebStartTest method runTestCaseTest.
private static Throwable runTestCaseTest(String testClass, String method, int port) throws Exception {
TestCase test = (TestCase) Class.forName(testClass).newInstance();
test.setName(method);
TestResult result = new TestResult();
test.run(result);
if (result.failureCount() != 0) {
Enumeration<TestFailure> e = result.failures();
return e.nextElement().thrownException();
} else if (result.errorCount() != 0) {
Enumeration<TestFailure> e = result.errors();
return e.nextElement().thrownException();
}
return null;
}
use of junit.framework.TestFailure in project junit4 by junit-team.
the class ForwardCompatibilityTest method testInvalidMethod.
public void testInvalidMethod() {
TestResult result = new TestResult();
junit.framework.Test adapter = new JUnit4TestAdapter(InvalidMethodTest.class);
adapter.run(result);
assertEquals(1, result.errorCount());
TestFailure failure = result.errors().nextElement();
assertTrue(failure.exceptionMessage().contains("Method shouldBeStatic() should be static"));
}
use of junit.framework.TestFailure in project nutz by nutzam.
the class AdvancedTestAll method test.
public static TestResult test(List<Request> reqs, String name, Map<Request, Method> reqMap) {
// TODO 根据order文件还原测试顺序
try {
FileWriter fw = new FileWriter("./test_order_" + name + ".txt");
for (Request request : reqs) {
fw.write(reqMap.get(request).toString());
fw.write("\n");
}
fw.flush();
fw.close();
} catch (IOException e) {
}
final TestResult result = new TestResult();
RunNotifier notifier = new RunNotifier();
notifier.addListener(new RunListener() {
public void testFailure(Failure failure) throws Exception {
result.addError(asTest(failure.getDescription()), failure.getException());
}
public void testFinished(Description description) throws Exception {
result.endTest(asTest(description));
}
public void testStarted(Description description) throws Exception {
result.startTest(asTest(description));
}
public junit.framework.Test asTest(Description description) {
return new junit.framework.Test() {
public void run(TestResult result) {
throw Lang.noImplement();
}
public int countTestCases() {
return 1;
}
};
}
});
for (Request request : reqs) {
request.getRunner().run(notifier);
}
return result;
}
Aggregations