Search in sources :

Example 1 with KanonizoTestFailure

use of org.kanonizo.junit.KanonizoTestFailure in project kanonizo by kanonizo.

the class JUnit4TestRunner method runTest.

@Override
public KanonizoTestResult runTest(TestCase tc) {
    Request request = getRequest(tc);
    Runner testRunner = request.getRunner();
    Result testResult = runner.run(testRunner);
    List<KanonizoTestFailure> failures = testResult.getFailures().stream().map(failure -> new KanonizoTestFailure(failure.getException(), failure.getTrace())).collect(Collectors.toList());
    return new KanonizoTestResult(tc.getTestClass(), tc.getMethod(), testResult.wasSuccessful(), failures, testResult.getRunTime());
}
Also used : Arrays(java.util.Arrays) JUnitCore(org.junit.runner.JUnitCore) Result(org.junit.runner.Result) Request(org.junit.runner.Request) RunWith(org.junit.runner.RunWith) ArrayList(java.util.ArrayList) TestCase(org.kanonizo.framework.objects.TestCase) BlockJUnit4ClassRunner(org.junit.runners.BlockJUnit4ClassRunner) Runner(org.junit.runner.Runner) ClassRequest(org.junit.internal.requests.ClassRequest) KanonizoTestFailure(org.kanonizo.junit.KanonizoTestFailure) Method(java.lang.reflect.Method) Parameterized(org.junit.runners.Parameterized) KanonizoTestResult(org.kanonizo.junit.KanonizoTestResult) ParameterisedTestCase(org.kanonizo.framework.objects.ParameterisedTestCase) AssumptionViolatedException(org.junit.AssumptionViolatedException) BlockJUnit4ClassRunnerWithParameters(org.junit.runners.parameterized.BlockJUnit4ClassRunnerWithParameters) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Iterator(java.util.Iterator) EachTestNotifier(org.junit.internal.runners.model.EachTestNotifier) Filter(org.junit.runner.manipulation.Filter) Description(org.junit.runner.Description) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Ignore(org.junit.Ignore) RunNotifier(org.junit.runner.notification.RunNotifier) LogManager(org.apache.logging.log4j.LogManager) BlockJUnit4ClassRunner(org.junit.runners.BlockJUnit4ClassRunner) Runner(org.junit.runner.Runner) KanonizoTestFailure(org.kanonizo.junit.KanonizoTestFailure) Request(org.junit.runner.Request) ClassRequest(org.junit.internal.requests.ClassRequest) KanonizoTestResult(org.kanonizo.junit.KanonizoTestResult) Result(org.junit.runner.Result) KanonizoTestResult(org.kanonizo.junit.KanonizoTestResult)

Example 2 with KanonizoTestFailure

use of org.kanonizo.junit.KanonizoTestFailure in project kanonizo by kanonizo.

the class JUnit3TestRunner method runTest.

@Override
public KanonizoTestResult runTest(TestCase tc) {
    Test test = createMethodSuite(tc.getTestClass(), tc.getMethod());
    if (test == null) {
        logger.error("Unable to create test case");
        throw new RuntimeException();
    }
    long startTime = System.currentTimeMillis();
    TestResult result = doRun(test, false);
    long runTime = System.currentTimeMillis() - startTime;
    List<KanonizoTestFailure> failures = new ArrayList<>();
    Enumeration<TestFailure> testFailures = result.failures();
    Enumeration<TestFailure> errors = result.errors();
    List<TestFailure> allErrors = Util.combine(testFailures, errors);
    for (TestFailure f : allErrors) {
        failures.add(new KanonizoTestFailure(f.thrownException(), f.trace()));
    }
    return new KanonizoTestResult(tc.getTestClass(), tc.getMethod(), result.wasSuccessful(), failures, runTime);
}
Also used : Test(junit.framework.Test) KanonizoTestFailure(org.kanonizo.junit.KanonizoTestFailure) TestFailure(junit.framework.TestFailure) KanonizoTestFailure(org.kanonizo.junit.KanonizoTestFailure) ArrayList(java.util.ArrayList) TestResult(junit.framework.TestResult) KanonizoTestResult(org.kanonizo.junit.KanonizoTestResult) KanonizoTestResult(org.kanonizo.junit.KanonizoTestResult)

Aggregations

ArrayList (java.util.ArrayList)2 KanonizoTestFailure (org.kanonizo.junit.KanonizoTestFailure)2 KanonizoTestResult (org.kanonizo.junit.KanonizoTestResult)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Arrays (java.util.Arrays)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Test (junit.framework.Test)1 TestFailure (junit.framework.TestFailure)1 TestResult (junit.framework.TestResult)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 AssumptionViolatedException (org.junit.AssumptionViolatedException)1 Ignore (org.junit.Ignore)1 ClassRequest (org.junit.internal.requests.ClassRequest)1 EachTestNotifier (org.junit.internal.runners.model.EachTestNotifier)1 Description (org.junit.runner.Description)1 JUnitCore (org.junit.runner.JUnitCore)1