Search in sources :

Example 26 with EachTestNotifier

use of org.junit.internal.runners.model.EachTestNotifier in project java-sdk by watson-developer-cloud.

the class RetryRunner method run.

/*
   * (non-Javadoc)
   *
   * @see org.junit.runners.ParentRunner#run(org.junit.runner.notification.RunNotifier)
   */
@Override
public void run(final RunNotifier notifier) {
    EachTestNotifier testNotifier = new EachTestNotifier(notifier, getDescription());
    Statement statement = classBlock(notifier);
    try {
        statement.evaluate();
    } catch (AssumptionViolatedException ave) {
        testNotifier.fireTestIgnored();
    } catch (StoppedByUserException sbue) {
        throw sbue;
    } catch (Throwable t) {
        LOG.warning("Retry class: " + getDescription().getDisplayName());
        retry(testNotifier, statement, t, getDescription());
    }
}
Also used : AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) Statement(org.junit.runners.model.Statement) EachTestNotifier(org.junit.internal.runners.model.EachTestNotifier) StoppedByUserException(org.junit.runner.notification.StoppedByUserException)

Example 27 with EachTestNotifier

use of org.junit.internal.runners.model.EachTestNotifier in project junit4 by junit-team.

the class ParentRunner method runLeaf.

/**
 * 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();
    }
}
Also used : AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) EachTestNotifier(org.junit.internal.runners.model.EachTestNotifier)

Example 28 with EachTestNotifier

use of org.junit.internal.runners.model.EachTestNotifier in project junit4 by junit-team.

the class ParentRunner method run.

@Override
public void run(final RunNotifier notifier) {
    EachTestNotifier testNotifier = new EachTestNotifier(notifier, getDescription());
    testNotifier.fireTestSuiteStarted();
    try {
        Statement statement = classBlock(notifier);
        statement.evaluate();
    } catch (AssumptionViolatedException e) {
        testNotifier.addFailedAssumption(e);
    } catch (StoppedByUserException e) {
        throw e;
    } catch (Throwable e) {
        testNotifier.addFailure(e);
    } finally {
        testNotifier.fireTestSuiteFinished();
    }
}
Also used : AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) Statement(org.junit.runners.model.Statement) EachTestNotifier(org.junit.internal.runners.model.EachTestNotifier) StoppedByUserException(org.junit.runner.notification.StoppedByUserException)

Example 29 with EachTestNotifier

use of org.junit.internal.runners.model.EachTestNotifier in project hive by apache.

the class RetryTestRunner method run.

// from ParentRunner, retried under exception (notified only after exhausting retryCount)
// invoked for test classes
@Override
public void run(final RunNotifier notifier) {
    final Description description = getDescription();
    final EachTestNotifier testNotifier = new EachTestNotifier(notifier, description);
    final Statement statement = classBlock(notifier);
    try {
        statement.evaluate();
    } catch (AssumptionViolatedException e) {
        testNotifier.fireTestIgnored();
    } catch (StoppedByUserException e) {
        // not retrying when user explicitly stops the test
        throw e;
    } catch (Throwable e) {
        // retry on any other exception
        retry(description, testNotifier, statement, e);
    }
}
Also used : Description(org.junit.runner.Description) AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) Statement(org.junit.runners.model.Statement) EachTestNotifier(org.junit.internal.runners.model.EachTestNotifier) StoppedByUserException(org.junit.runner.notification.StoppedByUserException)

Example 30 with EachTestNotifier

use of org.junit.internal.runners.model.EachTestNotifier in project blueocean-plugin by jenkinsci.

the class ATHJUnitRunner method runTest.

private void runTest(Statement statement, Description description, RunNotifier notifier, Retry retry) {
    logger.info(String.format("Running test: '%s'", description.getMethodName()));
    String buildName = System.getenv("BUILD_TAG");
    if (StringUtils.isEmpty(buildName)) {
        buildName = System.getenv("BUILD_TAG");
    }
    // https://wiki.saucelabs.com/display/DOCS/Annotating+Tests+with+Selenium%27s+JavaScript+Executor
    if (StringUtils.isNotEmpty(buildName)) {
        LocalDriver.executeSauce(String.format("job-build=%s", buildName));
    }
    LocalDriver.executeSauce(String.format("job-name=%s", description.getMethodName()));
    EachTestNotifier eachNotifier = new EachTestNotifier(notifier, description);
    eachNotifier.fireTestStarted();
    List<Throwable> failures = new ArrayList<>();
    try {
        int n = retry == null ? 1 : retry.value();
        for (int i = 0; i < n; i++) {
            try {
                statement.evaluate();
                failures.clear();
                break;
            } catch (AssumptionViolatedException e) {
                throw e;
            } catch (Throwable e) {
                if (n <= 1) {
                    failures.add(e);
                } else {
                    failures.add(new RetryThrowable(i, e));
                }
            }
        }
        for (Throwable failure : failures) {
            eachNotifier.addFailure(failure);
        }
    } catch (AssumptionViolatedException e) {
        eachNotifier.addFailedAssumption(e);
    } catch (Throwable e) {
        eachNotifier.addFailure(e);
    } finally {
        eachNotifier.fireTestFinished();
        LocalDriver.destroy();
    }
}
Also used : AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) EachTestNotifier(org.junit.internal.runners.model.EachTestNotifier) ArrayList(java.util.ArrayList)

Aggregations

EachTestNotifier (org.junit.internal.runners.model.EachTestNotifier)30 AssumptionViolatedException (org.junit.internal.AssumptionViolatedException)12 Test (org.junit.Test)10 Result (gherkin.formatter.model.Result)8 Description (org.junit.runner.Description)6 PendingException (cucumber.api.PendingException)5 StoppedByUserException (org.junit.runner.notification.StoppedByUserException)5 Statement (org.junit.runners.model.Statement)4 Match (gherkin.formatter.model.Match)3 Ignore (org.junit.Ignore)2 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)1 TraceContext (com.navercorp.pinpoint.bootstrap.context.TraceContext)1 Step (gherkin.formatter.model.Step)1 ArrayList (java.util.ArrayList)1 JSONException (org.json.JSONException)1 MultipleFailureException (org.junit.internal.runners.model.MultipleFailureException)1 InitializationError (org.junit.runners.model.InitializationError)1 KieSession (org.kie.api.runtime.KieSession)1 FactHandle (org.kie.api.runtime.rule.FactHandle)1 ProviderDescription (org.mapstruct.itest.testutil.runner.xml.Toolchains.ProviderDescription)1