use of org.junit.runner.notification.RunNotifier in project n4js by eclipse.
the class XpectConfigurationDelegate method execute.
/**
* Runs provided File in Engine. Returns output of execution.
*/
public void execute(ILaunch launch, XpectRunConfiguration runConfiguration) throws RuntimeException {
Job job = new Job(launch.getLaunchConfiguration().getName()) {
@Override
protected IStatus run(IProgressMonitor monitor) {
XpectRunner xr;
try {
xr = new XpectRunner(N4IDEXpectTestClass.class);
} catch (InitializationError e) {
N4IDEXpectUIPlugin.logError("cannot initialize xpect runner", e);
return Status.CANCEL_STATUS;
}
// TODO support multiple selection
/*
* if Project provided, or package files should be discovered there. Also multiple selected files
*/
String testFileLocation = runConfiguration.getXtFileToRun();
IXpectURIProvider uriprov = xr.getUriProvider();
if (uriprov instanceof N4IDEXpectTestURIProvider) {
((N4IDEXpectTestURIProvider) uriprov).addTestFileLocation(testFileLocation);
}
Result result = new Result();
RunNotifier notifier = new RunNotifier();
RunListener listener = result.createListener();
N4IDEXpectRunListener n4Listener = new N4IDEXpectRunListener();
notifier.addFirstListener(listener);
notifier.addListener(n4Listener);
try {
notifier.fireTestRunStarted(xr.getDescription());
xr.run(notifier);
notifier.fireTestRunFinished(result);
} finally {
notifier.removeListener(n4Listener);
notifier.removeListener(listener);
}
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
}
use of org.junit.runner.notification.RunNotifier in project ant by apache.
the class CustomJUnit4TestAdapterCache method getNotifier.
public RunNotifier getNotifier(final TestResult result) {
final IgnoredTestResult resultWrapper = (IgnoredTestResult) result;
RunNotifier notifier = new RunNotifier();
notifier.addListener(new RunListener() {
@Override
public void testFailure(Failure failure) throws Exception {
result.addError(asTest(failure.getDescription()), failure.getException());
}
@Override
public void testFinished(Description description) throws Exception {
result.endTest(asTest(description));
}
@Override
public void testStarted(Description description) throws Exception {
result.startTest(asTest(description));
}
@Override
public void testIgnored(Description description) throws Exception {
if (resultWrapper != null) {
resultWrapper.testIgnored(asTest(description));
}
}
@Override
public void testAssumptionFailure(Failure failure) {
if (resultWrapper != null) {
resultWrapper.testAssumptionFailure(asTest(failure.getDescription()), failure.getException());
}
}
});
return notifier;
}
use of org.junit.runner.notification.RunNotifier in project evosuite by EvoSuite.
the class SequenceExtractor method extractSequences.
/**
* Extracts execution sequences from JUnit tests which are located in the given package with respect to the given target classes.
*
* @param packageToBeConsidered package to be scanned for JUnit tests
* @param targetClasses classes for which sequences shall be extracted
*
* @return carved sequences (TestCase)
*/
public static List<TestCase> extractSequences(final String packageToBeConsidered, final Class<?>... targetClasses) {
if (packageToBeConsidered == null) {
throw new NullPointerException("Name of the package to be considered must not be null");
}
if (targetClasses == null || targetClasses.length == 0) {
throw new IllegalArgumentException("No targets for sequence extraction specified");
}
final Collection<String> classes = getPossibleCandidates(packageToBeConsidered);
final ArrayList<TestCase> carvedSequences = new ArrayList<TestCase>();
CarvingTestRunner testRunner;
Class<?> clazz;
TestCase carvedSequence;
for (final String className : classes) {
try {
clazz = Class.forName(Utils.getClassNameFromResourcePath(className));
if (isJUnitTestClass(clazz)) {
try {
testRunner = new CarvingTestRunner(clazz, targetClasses);
// TODO is test result interesting?
testRunner.run(new RunNotifier());
carvedSequence = testRunner.getCarvedTest();
if (carvedSequence == null) {
logger.warn("For some reason, no carving took place for test class " + className);
} else {
carvedSequences.add(carvedSequence);
}
} catch (final InitializationError e) {
logger.error("An error occurred while initializing CarvingTestRunner for test class " + className, e);
}
}
} catch (final Throwable e) {
logger.error("Couldn't get class instance of class " + className, e);
}
}
return carvedSequences;
}
use of org.junit.runner.notification.RunNotifier in project cucumber-jvm by cucumber.
the class FeatureRunnerTest method step_notification_can_be_turned_on_scenario_outline_with_two_examples_table_and_background.
@Test
void step_notification_can_be_turned_on_scenario_outline_with_two_examples_table_and_background() {
Feature feature = TestPickleBuilder.parseFeature("path/test.feature", "" + "Feature: feature name\n" + " Background: background\n" + " Given step #1\n" + " Scenario Outline: scenario <id>\n" + " When step #2 \n" + " Then step #3 \n" + " Examples: examples 1 name\n" + " | id | \n" + " | #1 |\n" + " | #2 |\n" + " Examples: examples 2 name\n" + " | id |\n" + " | #3 |\n");
JUnitOptions junitOption = new JUnitOptionsBuilder().setStepNotifications(true).build();
RunNotifier notifier = runFeatureWithNotifier(feature, junitOption);
InOrder order = inOrder(notifier);
order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario #1")));
order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #1(scenario #1)")));
order.verify(notifier).fireTestFailure(argThat(new FailureMatcher("step #1(scenario #1)")));
order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #1(scenario #1)")));
order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #2(scenario #1)")));
order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #2(scenario #1)")));
order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #2(scenario #1)")));
order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #3(scenario #1)")));
order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #3(scenario #1)")));
order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #3(scenario #1)")));
order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario #1")));
order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario #2")));
order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #1(scenario #2)")));
order.verify(notifier).fireTestFailure(argThat(new FailureMatcher("step #1(scenario #2)")));
order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #1(scenario #2)")));
order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #2(scenario #2)")));
order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #2(scenario #2)")));
order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #2(scenario #2)")));
order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #3(scenario #2)")));
order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #3(scenario #2)")));
order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #3(scenario #2)")));
order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario #2")));
order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario #3")));
order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #1(scenario #3)")));
order.verify(notifier).fireTestFailure(argThat(new FailureMatcher("step #1(scenario #3)")));
order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #1(scenario #3)")));
order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #2(scenario #3)")));
order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #2(scenario #3)")));
order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #2(scenario #3)")));
order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #3(scenario #3)")));
order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #3(scenario #3)")));
order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #3(scenario #3)")));
order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario #3")));
}
use of org.junit.runner.notification.RunNotifier in project cucumber-jvm by cucumber.
the class FeatureRunnerTest method should_notify_of_failure_to_create_runners_and_request_test_execution_to_stop.
@Test
void should_notify_of_failure_to_create_runners_and_request_test_execution_to_stop() {
Feature feature = TestPickleBuilder.parseFeature("path/test.feature", "" + "Feature: feature name\n" + " Scenario: scenario_1 name\n" + " Given step #1\n");
Filters filters = new Filters(RuntimeOptions.defaultOptions());
IllegalStateException illegalStateException = new IllegalStateException();
RunnerSupplier runnerSupplier = () -> {
throw illegalStateException;
};
TimeServiceEventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
RuntimeOptions options = RuntimeOptions.defaultOptions();
CucumberExecutionContext context = new CucumberExecutionContext(bus, new ExitStatus(options), runnerSupplier);
FeatureRunner featureRunner = FeatureRunner.create(feature, null, filters, context, new JUnitOptions());
RunNotifier notifier = mock(RunNotifier.class);
PickleRunners.PickleRunner pickleRunner = featureRunner.getChildren().get(0);
featureRunner.runChild(pickleRunner, notifier);
Description description = pickleRunner.getDescription();
ArgumentCaptor<Failure> failureArgumentCaptor = ArgumentCaptor.forClass(Failure.class);
InOrder order = inOrder(notifier);
order.verify(notifier).fireTestStarted(description);
order.verify(notifier).fireTestFailure(failureArgumentCaptor.capture());
assertThat(failureArgumentCaptor.getValue().getException(), is(equalTo(illegalStateException)));
assertThat(failureArgumentCaptor.getValue().getDescription(), is(equalTo(description)));
order.verify(notifier).pleaseStop();
order.verify(notifier).fireTestFinished(description);
}
Aggregations