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());
}
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);
}
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);
}
Aggregations