Examples of EachTestNotifier


Examples of org.junit.internal.runners.model.EachTestNotifier

        }
    }

    private void runInTransaction(FrameworkMethod method, RunNotifier notifier) {
        UserTransaction tx = null;
        EachTestNotifier eachNotifier = makeNotifier(method, notifier);
        if (method.getAnnotation(Ignore.class) != null) {
            eachNotifier.fireTestIgnored();
            return;
        }

        eachNotifier.fireTestStarted();
        try {
            InitialContext ctx = new InitialContext();
            tx = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
            tx.begin();
            methodBlock(method).evaluate();
        }
        catch (NamingException exc) {
            eachNotifier.addFailure(exc);
        }
        catch (NotSupportedException exc) {
            eachNotifier.addFailure(exc);
        }
        catch (SystemException exc) {
            eachNotifier.addFailure(exc);
        }
        catch (AssumptionViolatedException e) {
            eachNotifier.addFailedAssumption(e);
        }
        // CHECKSTYLE:SKIP : base class API
        catch (Throwable e) {
            eachNotifier.addFailure(e);
        }
        finally {
            rollback(tx, eachNotifier);
            eachNotifier.fireTestFinished();
        }
    }
View Full Code Here

Examples of org.junit.internal.runners.model.EachTestNotifier

        return (method.getAnnotation(Transactional.class) != null) || transactionalClass;
    }

    private EachTestNotifier makeNotifier(FrameworkMethod method, RunNotifier notifier) {
        Description description = describeChild(method);
        return new EachTestNotifier(notifier, description);
    }
View Full Code Here

Examples of org.junit.internal.runners.model.EachTestNotifier

        final Object freshInstance) throws Throwable{

        final RunNotifier testRunNotifier = new RunNotifier();
        final TestRunDurationListener testRunDurationListener = new TestRunDurationListener();
        testRunNotifier.addListener(testRunDurationListener);
        final EachTestNotifier eachRunNotifier = new EachTestNotifier(testRunNotifier, null);
       
        String currentMethodName = method.getMethod().getName();
        TestResultBean testResult = method.getTestResult();
        Map<String, Object> writableRow = method.getTestData();
        Object returnObj = null;
        try {
            final Object[] values = complete.getMethodArguments(true);

            testResult.setInput(method.getTestData());
            // invoke test method
            eachRunNotifier.fireTestStarted();
            LOG.debug("Calling method {} with values {}", method.getName(), values);
            returnObj = method.invokeExplosively(freshInstance, values);
            eachRunNotifier.fireTestFinished();
           
            TestMethodDuration testItemDurationBean = new TestMethodDuration(currentMethodName,
                testRunDurationListener.getStartInNano(), testRunDurationListener.getEndInNano());
            testResult.addTestItemDurationBean(testItemDurationBean);
            testResult.setOutput((returnObj == null) ? "void" : returnObj);
            testResult.setPassed(Boolean.TRUE);
           
            if (writableRow != null) {
                if (returnObj != null) {
                    LOG.debug("Data returned by method {} is {} :", method.getName(), returnObj);
                    writableRow.put(Loader.ACTUAL_RESULT, returnObj);
                    Object expectedResult = writableRow.get(Loader.EXPECTED_RESULT);
                    // if expected result exist in user input test data,
                    // then compare that with actual output result
                    // and write the status back to writable map data.
                    if (expectedResult != null) {
                        LOG.debug("Expected result exists");
                        if (expectedResult.toString().equals(returnObj.toString())) {
                            writableRow.put(Loader.TEST_STATUS, Loader.TEST_PASSED);
                        } else {
                            writableRow.put(Loader.TEST_STATUS, Loader.TEST_FAILED);

                        }
                    }

                }
                LOG.debug("testItemDurationBean:" + testItemDurationBean);
                if (testItemDurationBean != null) {
                    Double testDuration = CommonUtils.getRounded(testItemDurationBean.getRoundedMsDifference()
                        .doubleValue(), 3);
                    LOG.debug("testItemDurationBean.getRoundedMsDifference():" + testDuration);
                    writableRow.put(Loader.DURATION, testDuration);
                }
            }
        } catch (AssumptionViolatedException e) {
            eachRunNotifier.addFailedAssumption(e);
            handleAssumptionViolation(e);
        } catch (Throwable e) {

            if (e instanceof AssertionError) { // Assertion error
                testResult.setPassed(Boolean.FALSE);
                testResult.setResult(e.getMessage());                      

            } else { // Exception
                testResult.setException(Boolean.TRUE);
                testResult.setExceptionResult(e.toString());

            }
            eachRunNotifier.addFailure(e);
            throw e;
        } finally {
            eachRunNotifier.fireTestFinished();
        }
        //The test should fail in case the Actual Result returned by the test method did
        //not match the Expected result specified for the method in the test data file.
        if (writableRow != null && writableRow.get(Loader.TEST_STATUS) != null
            && writableRow.get(Loader.TEST_STATUS).equals(Loader.TEST_FAILED)) {
View Full Code Here

Examples of org.junit.internal.runners.model.EachTestNotifier

    /**
     * Runs a {@link Statement} that represents a leaf (aka atomic) test.
     */
    protected final void runLeaf(Statement statement, Description description,
            RunNotifier notifier) {
        EachTestNotifier eachNotifier = new EachTestNotifier(notifier, description);
        eachNotifier.fireTestStarted();
        try {
            statement.evaluate();
        } catch (AssumptionViolatedException e) {
            eachNotifier.addFailedAssumption(e);
        } catch (Throwable e) {
            eachNotifier.addFailure(e);
        } finally {
            eachNotifier.fireTestFinished();
        }
    }
View Full Code Here

Examples of org.junit.internal.runners.model.EachTestNotifier

        return description;
    }

    @Override
    public void run(final RunNotifier notifier) {
        EachTestNotifier testNotifier = new EachTestNotifier(notifier,
                getDescription());
        try {
            Statement statement = classBlock(notifier);
            statement.evaluate();
        } catch (AssumptionViolatedException e) {
            testNotifier.fireTestIgnored();
        } catch (StoppedByUserException e) {
            throw e;
        } catch (Throwable e) {
            testNotifier.addFailure(e);
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.