Search in sources :

Example 51 with RunNotifier

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

the class CustomConfigurerTest method runAndGetFailures.

private List<String> runAndGetFailures(Class<TestWithConfig> testClass) throws InitializationError {
    RunNotifier notifier = new RunNotifier();
    FailureListener failureListener = new FailureListener();
    notifier.addListener(failureListener);
    HierarchicalConfigurationStrategy configurationStrategy = new HierarchicalConfigurationStrategy(new ConfigConfigurer(new PackagePropertiesLoader()), new LooperModeConfigurer(new Properties()), new SomeConfigConfigurer());
    SingleSdkRobolectricTestRunner testRunner = new SingleSdkRobolectricTestRunner(testClass, SingleSdkRobolectricTestRunner.defaultInjector().bind(ConfigurationStrategy.class, configurationStrategy).build());
    testRunner.run(notifier);
    return failureListener.failures.stream().map(Failure::getMessage).collect(toList());
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) FailureListener(org.robolectric.android.FailureListener) SingleSdkRobolectricTestRunner(org.robolectric.SingleSdkRobolectricTestRunner) Properties(java.util.Properties)

Example 52 with RunNotifier

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

the class JUnitTestClassExecutor method runTestClass.

private void runTestClass(String testClassName) throws ClassNotFoundException {
    final Class<?> testClass = Class.forName(testClassName, false, applicationClassLoader);
    if (isNestedClassInsideEnclosedRunner(testClass)) {
        return;
    }
    List<Filter> filters = new ArrayList<Filter>();
    if (options.hasCategoryConfiguration()) {
        verifyJUnitCategorySupport();
        filters.add(new CategoryFilter(options.getIncludeCategories(), options.getExcludeCategories(), applicationClassLoader));
    }
    Request request = Request.aClass(testClass);
    Runner runner = request.getRunner();
    if (!options.getIncludedTests().isEmpty() || !options.getIncludedTestsCommandLine().isEmpty() || !options.getExcludedTests().isEmpty()) {
        TestSelectionMatcher matcher = new TestSelectionMatcher(options.getIncludedTests(), options.getExcludedTests(), options.getIncludedTestsCommandLine());
        // 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) TestSelectionMatcher(org.gradle.api.internal.tasks.testing.filter.TestSelectionMatcher) RunNotifier(org.junit.runner.notification.RunNotifier) Filter(org.junit.runner.manipulation.Filter) Filterable(org.junit.runner.manipulation.Filterable) ArrayList(java.util.ArrayList) Request(org.junit.runner.Request) NoTestsRemainException(org.junit.runner.manipulation.NoTestsRemainException)

Example 53 with RunNotifier

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

the class AbstractScenarioRunnerTest method testRun.

@Test
public void testRun() {
    ArgumentCaptor<Failure> failureArgumentCaptor = ArgumentCaptor.forClass(Failure.class);
    doThrow(new ScenarioException("Failed assertion", true)).when(abstractScenarioRunnerLocal).internalRunScenario(eq(scenarioRunnerDTOLocal.getScenarioWithIndices().get(0)), isA(ScenarioRunnerData.class), any(), any());
    doThrow(new ScenarioException("Generic exception")).when(abstractScenarioRunnerLocal).internalRunScenario(eq(scenarioRunnerDTOLocal.getScenarioWithIndices().get(1)), isA(ScenarioRunnerData.class), any(), any());
    doThrow(new ScenarioException(new IllegalArgumentException("Wrong argument"))).when(abstractScenarioRunnerLocal).internalRunScenario(eq(scenarioRunnerDTOLocal.getScenarioWithIndices().get(2)), isA(ScenarioRunnerData.class), any(), any());
    doThrow(new RuntimeException("Unknown exception")).when(abstractScenarioRunnerLocal).internalRunScenario(eq(scenarioRunnerDTOLocal.getScenarioWithIndices().get(3)), isA(ScenarioRunnerData.class), any(), any());
    assertNull(abstractScenarioRunnerLocal.simulationRunMetadataBuilder);
    RunNotifier runNotifier = spy(new RunNotifier());
    abstractScenarioRunnerLocal.run(runNotifier);
    assertNotNull(abstractScenarioRunnerLocal.simulationRunMetadataBuilder);
    verify(runNotifier, times(SCENARIO_DATA + 2)).fireTestStarted(isA(Description.class));
    verify(runNotifier, times(SCENARIO_DATA)).fireTestFailure(failureArgumentCaptor.capture());
    verify(runNotifier, times(SCENARIO_DATA)).fireTestFinished(isA(Description.class));
    List<Failure> capturedFailures = failureArgumentCaptor.getAllValues();
    assertEquals(ScenarioSimulationServerMessages.getIndexedScenarioMessage("Failed assertion", 1, "INDEX-0", "test"), capturedFailures.get(0).getException().getMessage());
    assertTrue(capturedFailures.get(0).getException() instanceof IndexedScenarioAssertionError);
    assertEquals(ScenarioSimulationServerMessages.getIndexedScenarioMessage("Generic exception", 2, "INDEX-1", "test"), capturedFailures.get(1).getException().getMessage());
    assertTrue(capturedFailures.get(1).getException() instanceof IndexedScenarioException);
    assertEquals(ScenarioSimulationServerMessages.getIndexedScenarioMessage("Wrong argument", 3, "INDEX-2", "test"), capturedFailures.get(2).getException().getMessage());
    assertTrue(capturedFailures.get(2).getException() instanceof IndexedScenarioException);
    assertEquals(ScenarioSimulationServerMessages.getIndexedScenarioMessage("Unknown exception", 4, "INDEX-3", "test"), capturedFailures.get(3).getException().getMessage());
    assertTrue(capturedFailures.get(3).getException() instanceof IndexedScenarioException);
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) Description(org.junit.runner.Description) ScenarioRunnerData(org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerData) Failure(org.junit.runner.notification.Failure) 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