Search in sources :

Example 6 with TestFailure

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();
            }
        }
    }
}
Also used : Enumeration(java.util.Enumeration) TestFailure(junit.framework.TestFailure)

Example 7 with TestFailure

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)");
            }
        }
    }
}
Also used : Enumeration(java.util.Enumeration) TestSuite(junit.framework.TestSuite) TestFailure(junit.framework.TestFailure) TestResult(junit.framework.TestResult)

Example 8 with TestFailure

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;
}
Also used : Enumeration(java.util.Enumeration) TestCase(junit.framework.TestCase) TestFailure(junit.framework.TestFailure) TestResult(junit.framework.TestResult)

Example 9 with TestFailure

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"));
}
Also used : TestFailure(junit.framework.TestFailure) TestResult(junit.framework.TestResult) JUnit4TestAdapter(junit.framework.JUnit4TestAdapter)

Example 10 with TestFailure

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;
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) Description(org.junit.runner.Description) FileWriter(java.io.FileWriter) Request(org.junit.runner.Request) TestResult(junit.framework.TestResult) IOException(java.io.IOException) IOException(java.io.IOException) RunListener(org.junit.runner.notification.RunListener) Test(org.junit.Test) TestFailure(junit.framework.TestFailure) Failure(org.junit.runner.notification.Failure)

Aggregations

TestFailure (junit.framework.TestFailure)11 TestResult (junit.framework.TestResult)8 Enumeration (java.util.Enumeration)5 TestCase (junit.framework.TestCase)2 TestSuite (junit.framework.TestSuite)2 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 AssertionFailedError (junit.framework.AssertionFailedError)1 JUnit4TestAdapter (junit.framework.JUnit4TestAdapter)1 Test (junit.framework.Test)1 SampleResult (org.apache.jmeter.samplers.SampleResult)1 Test (org.junit.Test)1 Description (org.junit.runner.Description)1 Request (org.junit.runner.Request)1 Failure (org.junit.runner.notification.Failure)1 RunListener (org.junit.runner.notification.RunListener)1 RunNotifier (org.junit.runner.notification.RunNotifier)1