Search in sources :

Example 1 with RunNotifier

use of org.junit.runner.notification.RunNotifier in project mockito by mockito.

the class ConsoleSpammingMockitoJUnitRunnerTest method setup.

@Before
public void setup() throws InitializationError {
    loggerStub = new MockitoLoggerStub();
    notifier = new RunNotifier();
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) Before(org.junit.Before)

Example 2 with RunNotifier

use of org.junit.runner.notification.RunNotifier in project gradle by gradle.

the class JUnitTestClassExecuter method runTestClass.

private void runTestClass(String testClassName) throws ClassNotFoundException {
    final Class<?> testClass = Class.forName(testClassName, false, applicationClassLoader);
    List<Filter> filters = new ArrayList<Filter>();
    if (options.hasCategoryConfiguration()) {
        verifyJUnitCategorySupport();
        Transformer<Class<?>, String> transformer = new Transformer<Class<?>, String>() {

            public Class<?> transform(final String original) {
                try {
                    return applicationClassLoader.loadClass(original);
                } catch (ClassNotFoundException e) {
                    throw new InvalidUserDataException(String.format("Can't load category class [%s].", original), e);
                }
            }
        };
        filters.add(new CategoryFilter(CollectionUtils.collect(options.getIncludeCategories(), transformer), CollectionUtils.collect(options.getExcludeCategories(), transformer)));
    }
    Request request = Request.aClass(testClass);
    Runner runner = request.getRunner();
    if (!options.getIncludedTests().isEmpty()) {
        TestSelectionMatcher matcher = new TestSelectionMatcher(options.getIncludedTests());
        // matches the filter, run the entire suite instead of filtering away its contents.
        if (!runner.getDescription().isSuite() || !matcher.matchesTest(testClassName, null)) {
            filters.add(new MethodNameFilter(matcher));
        }
    }
    if (runner instanceof Filterable) {
        Filterable filterable = (Filterable) runner;
        for (Filter filter : filters) {
            try {
                filterable.filter(filter);
            } catch (NoTestsRemainException e) {
                // Ignore
                return;
            }
        }
    } else if (allTestsFiltered(runner, filters)) {
        return;
    }
    RunNotifier notifier = new RunNotifier();
    notifier.addListener(listener);
    runner.run(notifier);
}
Also used : Runner(org.junit.runner.Runner) Transformer(org.gradle.api.Transformer) RunNotifier(org.junit.runner.notification.RunNotifier) ArrayList(java.util.ArrayList) Request(org.junit.runner.Request) NoTestsRemainException(org.junit.runner.manipulation.NoTestsRemainException) TestSelectionMatcher(org.gradle.api.internal.tasks.testing.filter.TestSelectionMatcher) Filter(org.junit.runner.manipulation.Filter) InvalidUserDataException(org.gradle.api.InvalidUserDataException) Filterable(org.junit.runner.manipulation.Filterable)

Example 3 with RunNotifier

use of org.junit.runner.notification.RunNotifier in project drools by kiegroup.

the class ScenarioRunner4JUnitTest method testBasic.

@Test
public void testBasic() throws Exception {
    HashMap<String, KieSession> ksessions = new HashMap<String, KieSession>();
    ksessions.put("someId", ksession);
    Scenario scenario = new Scenario();
    scenario.getKSessions().add("someId");
    ScenarioRunner4JUnit runner4JUnit = new ScenarioRunner4JUnit(scenario, ksessions);
    RunNotifier notifier = new RunNotifier();
    RunListener runListener = spy(new RunListener());
    notifier.addListener(runListener);
    runner4JUnit.run(notifier);
    verify(runListener, never()).testFailure(any(Failure.class));
    verify(runListener).testFinished(any(Description.class));
    verify(ksession).reset();
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) Description(org.junit.runner.Description) HashMap(java.util.HashMap) KieSession(org.kie.api.runtime.KieSession) Failure(org.junit.runner.notification.Failure) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) RunListener(org.junit.runner.notification.RunListener) Test(org.junit.Test)

Example 4 with RunNotifier

use of org.junit.runner.notification.RunNotifier in project drools by kiegroup.

the class ScenarioRunner4JUnitTest method testIDNotSet.

@Test
public void testIDNotSet() throws Exception {
    HashMap<String, KieSession> ksessions = new HashMap<String, KieSession>();
    ksessions.put(null, ksession);
    ScenarioRunner4JUnit runner4JUnit = new ScenarioRunner4JUnit(new Scenario(), ksessions);
    RunNotifier notifier = new RunNotifier();
    RunListener runListener = spy(new RunListener());
    notifier.addListener(runListener);
    runner4JUnit.run(notifier);
    verify(runListener, never()).testFailure(any(Failure.class));
    verify(runListener).testFinished(any(Description.class));
    verify(ksession).reset();
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) Description(org.junit.runner.Description) HashMap(java.util.HashMap) KieSession(org.kie.api.runtime.KieSession) Failure(org.junit.runner.notification.Failure) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) RunListener(org.junit.runner.notification.RunListener) Test(org.junit.Test)

Example 5 with RunNotifier

use of org.junit.runner.notification.RunNotifier in project drools by kiegroup.

the class ScenarioRunner4JUnitTest method testNoKieSession.

@Test
public void testNoKieSession() throws Exception {
    ScenarioRunner4JUnit runner4JUnit = new ScenarioRunner4JUnit(new Scenario(), new HashMap<String, KieSession>());
    RunNotifier notifier = new RunNotifier();
    RunListener runListener = spy(new RunListener());
    notifier.addListener(runListener);
    runner4JUnit.run(notifier);
    verify(runListener).testFailure(any(Failure.class));
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) KieSession(org.kie.api.runtime.KieSession) Failure(org.junit.runner.notification.Failure) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) RunListener(org.junit.runner.notification.RunListener) Test(org.junit.Test)

Aggregations

RunNotifier (org.junit.runner.notification.RunNotifier)53 Failure (org.junit.runner.notification.Failure)16 Description (org.junit.runner.Description)15 Test (org.junit.Test)14 RunListener (org.junit.runner.notification.RunListener)13 Test (org.junit.jupiter.api.Test)9 Runner (org.junit.runner.Runner)9 InOrder (org.mockito.InOrder)7 Feature (io.cucumber.core.gherkin.Feature)5 ArrayList (java.util.ArrayList)5 Before (org.junit.Before)5 Request (org.junit.runner.Request)5 Result (org.junit.runner.Result)5 ParentRunner (org.junit.runners.ParentRunner)4 HashMap (java.util.HashMap)3 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)3 BlockJUnit4ClassRunner (org.junit.runners.BlockJUnit4ClassRunner)3 KieSession (org.kie.api.runtime.KieSession)3 Match (gherkin.formatter.model.Match)2 Scenario (gherkin.formatter.model.Scenario)2