Search in sources :

Example 46 with Description

use of org.junit.runner.Description in project verify-hub by alphagov.

the class InfinispanJunitRunner method run.

@Override
public void run(final RunNotifier notifier) {
    notifier.addListener(new RunListener() {

        @Override
        public void testStarted(Description description) throws Exception {
            super.testStarted(description);
        }

        @Override
        public void testFinished(Description description) throws Exception {
            super.testFinished(description);
            EMBEDDED_CACHE_MANAGER.getCache("state_cache").clear();
            EMBEDDED_CACHE_MANAGER.getCache("assertion_id_cache").clear();
        }
    });
    super.run(notifier);
}
Also used : Description(org.junit.runner.Description) InvocationTargetException(java.lang.reflect.InvocationTargetException) RunListener(org.junit.runner.notification.RunListener)

Example 47 with Description

use of org.junit.runner.Description in project gradle by gradle.

the class IgnoredTestDescriptorProvider method getAllDescriptions.

List<Description> getAllDescriptions(Description description, String className) {
    final AllExceptIgnoredTestRunnerBuilder allExceptIgnoredTestRunnerBuilder = new AllExceptIgnoredTestRunnerBuilder();
    try {
        final Class<?> testClass = description.getClass().getClassLoader().loadClass(className);
        Runner runner = allExceptIgnoredTestRunnerBuilder.runnerForClass(testClass);
        if (runner == null) {
            // fall back to default runner
            runner = Request.aClass(testClass).getRunner();
        }
        final Description runnerDescription = runner.getDescription();
        return runnerDescription.getChildren();
    } catch (Throwable throwable) {
        throw new TestSuiteExecutionException(String.format("Unable to process Ignored class %s.", className), throwable);
    }
}
Also used : Runner(org.junit.runner.Runner) Description(org.junit.runner.Description) TestSuiteExecutionException(org.gradle.api.internal.tasks.testing.TestSuiteExecutionException)

Example 48 with Description

use of org.junit.runner.Description in project drools by kiegroup.

the class ScenarioRunner4JUnit method runScenario.

private void runScenario(RunNotifier notifier, Scenario scenario) {
    Description childDescription = Description.createTestDescription(getClass(), scenario.getName());
    descr.addChild(childDescription);
    EachTestNotifier eachNotifier = new EachTestNotifier(notifier, childDescription);
    try {
        eachNotifier.fireTestStarted();
        // If a KieSession is not available, fail fast
        if (ksessions == null || ksessions.values().isEmpty()) {
            eachNotifier.addFailure(new NullKieSessionException("Unable to get a Session to run tests. Check the project for build errors."));
        } else {
            KieSession ksession = getKSession(scenario.getKSessions());
            if (ksession == null) {
                String ksessionName = getKSessionName(scenario.getKSessions());
                if (ksessionName == null) {
                    eachNotifier.addFailure(new NullPointerException("Test scenario runner could not find the default knowledge session."));
                } else {
                    eachNotifier.addFailure(new NullPointerException("Test Scenarios require Stateful KieSession to run."));
                }
            } else {
                final ScenarioRunner runner = new ScenarioRunner(ksession, maxRuleFirings);
                runner.run(scenario);
                if (!scenario.wasSuccessful()) {
                    StringBuilder builder = new StringBuilder();
                    for (String message : scenario.getFailureMessages()) {
                        builder.append(message).append("\n");
                    }
                    eachNotifier.addFailedAssumption(new AssumptionViolatedException(builder.toString()));
                }
                // FLUSSSSSH!
                for (FactHandle factHandle : ksession.getFactHandles()) {
                    ksession.delete(factHandle);
                }
                resetKieSession(ksession);
            }
        }
    } catch (Throwable t) {
        eachNotifier.addFailure(t);
    } finally {
        // has to always be called as per junit docs
        eachNotifier.fireTestFinished();
    }
}
Also used : Description(org.junit.runner.Description) AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) FactHandle(org.kie.api.runtime.rule.FactHandle) EachTestNotifier(org.junit.internal.runners.model.EachTestNotifier) KieSession(org.kie.api.runtime.KieSession)

Example 49 with Description

use of org.junit.runner.Description in project drools by kiegroup.

the class TestServiceImpl method reportUnrecoverableError.

private void reportUnrecoverableError(String message, RunListener listener, Exception e) {
    try {
        Description description = Description.createSuiteDescription(message);
        listener.testFailure(new Failure(description, e));
    } catch (Exception e2) {
    // intentionally left empty as there is nothing to do
    }
}
Also used : Description(org.junit.runner.Description) Failure(org.junit.runner.notification.Failure)

Example 50 with Description

use of org.junit.runner.Description in project serenity-jbehave by serenity-bdd.

the class JUnitDescriptionGenerator method descriptionFor.

private Optional<Description> descriptionFor(PerformableStory performableStory) {
    List<Description> scenarioDescriptions = getScenarioDescriptions(performableStory.getScenarios());
    if (!scenarioDescriptions.isEmpty()) {
        Description storyDescription = createDescriptionForStory(performableStory.getStory());
        addBeforeOrAfterStep(Stage.BEFORE, beforeOrAfterStory, storyDescription, BEFORE_STORY_STEP_NAME);
        for (Description scenarioDescription : scenarioDescriptions) {
            storyDescription.addChild(scenarioDescription);
        }
        addBeforeOrAfterStep(Stage.AFTER, beforeOrAfterStory, storyDescription, AFTER_STORY_STEP_NAME);
        return Optional.of(storyDescription);
    } else {
        return Optional.empty();
    }
}
Also used : Description(org.junit.runner.Description)

Aggregations

Description (org.junit.runner.Description)309 Test (org.junit.Test)119 Failure (org.junit.runner.notification.Failure)57 Result (org.junit.runner.Result)32 ArrayList (java.util.ArrayList)25 RunListener (org.junit.runner.notification.RunListener)23 IOException (java.io.IOException)22 Request (org.junit.runner.Request)21 Method (java.lang.reflect.Method)18 JUnitCore (org.junit.runner.JUnitCore)17 Test (org.junit.jupiter.api.Test)14 Filter (org.junit.runner.manipulation.Filter)14 File (java.io.File)13 Runner (org.junit.runner.Runner)13 Statement (org.junit.runners.model.Statement)13 LoggingListener (org.elasticsearch.test.junit.listeners.LoggingListener)12 RunNotifier (org.junit.runner.notification.RunNotifier)12 JUnit4TestListener (com.intellij.junit4.JUnit4TestListener)10 ComparisonFailure (org.junit.ComparisonFailure)10 Description.createTestDescription (org.junit.runner.Description.createTestDescription)9