use of junit.framework.TestResult 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.TestResult in project junit4 by junit-team.
the class TestRunner method main.
public static void main(String[] args) {
TestRunner aTestRunner = new TestRunner();
try {
TestResult r = aTestRunner.start(args);
if (!r.wasSuccessful()) {
System.exit(FAILURE_EXIT);
}
System.exit(SUCCESS_EXIT);
} catch (Exception e) {
System.err.println(e.getMessage());
System.exit(EXCEPTION_EXIT);
}
}
use of junit.framework.TestResult in project junit4 by junit-team.
the class TestCaseTest method verifyError.
void verifyError(TestCase test) {
TestResult result = test.run();
assertTrue(result.runCount() == 1);
assertTrue(result.failureCount() == 0);
assertTrue(result.errorCount() == 1);
}
use of junit.framework.TestResult in project junit4 by junit-team.
the class TestCaseTest method verifySuccess.
void verifySuccess(TestCase test) {
TestResult result = test.run();
assertTrue(result.runCount() == 1);
assertTrue(result.failureCount() == 0);
assertTrue(result.errorCount() == 0);
}
use of junit.framework.TestResult in project junit4 by junit-team.
the class TextFeedbackTest method testFailure.
public void testFailure() {
String expected = expected(new String[] { ".F", "Time: 0", "Failures here", "", "FAILURES!!!", "Tests run: 1, Failures: 1, Errors: 0", "" });
ResultPrinter printer = new TestResultPrinter(new PrintStream(output)) {
@Override
public void printFailures(TestResult result) {
getWriter().println("Failures here");
}
};
runner.setPrinter(printer);
TestSuite suite = new TestSuite();
suite.addTest(new TestCase() {
@Override
public void runTest() {
throw new AssertionFailedError();
}
});
runner.doRun(suite);
assertEquals(expected, output.toString());
}
Aggregations