use of org.junit.runner.notification.RunListener in project cucumber-jvm by cucumber.
the class CucumberTest method cucumber_distinguishes_between_identical_features.
@Test
void cucumber_distinguishes_between_identical_features() throws Exception {
RunNotifier notifier = new RunNotifier();
RunListener listener = Mockito.mock(RunListener.class);
notifier.addListener(listener);
Request.classes(ValidEmpty.class).getRunner().run(notifier);
{
InOrder order = Mockito.inOrder(listener);
order.verify(listener).testStarted(argThat(new DescriptionMatcher("A single scenario(A feature with a single scenario #1)")));
order.verify(listener).testFinished(argThat(new DescriptionMatcher("A single scenario(A feature with a single scenario #1)")));
order.verify(listener).testStarted(argThat(new DescriptionMatcher("A single scenario(A feature with a single scenario #2)")));
order.verify(listener).testFinished(argThat(new DescriptionMatcher("A single scenario(A feature with a single scenario #2)")));
}
}
use of org.junit.runner.notification.RunListener in project randomizedtesting by randomizedtesting.
the class SlaveMain method execute.
/**
* Execute tests.
*/
private void execute(Iterator<String> classNames) throws Throwable {
final RunNotifier fNotifier = new OrderedRunNotifier();
final Result result = new Result();
final Writer debug = debugMessagesFile == null ? new NullWriter() : new OutputStreamWriter(new FileOutputStream(debugMessagesFile), "UTF-8");
fNotifier.addListener(result.createListener());
fNotifier.addListener(new StreamFlusherDecorator(new NoExceptionRunListenerDecorator(new RunListenerEmitter(serializer)) {
@Override
protected void exception(Throwable t) {
warn("Event serializer exception.", t);
}
}));
fNotifier.addListener(new RunListener() {
public void testRunFinished(Result result) throws Exception {
debug(debug, "testRunFinished(T:" + result.getRunCount() + ";F:" + result.getFailureCount() + ";I:" + result.getIgnoreCount() + ")");
serializer.flush();
}
@Override
public void testRunStarted(Description description) throws Exception {
debug(debug, "testRunStarted(" + description + ")");
serializer.flush();
}
@Override
public void testStarted(Description description) throws Exception {
debug(debug, "testStarted(" + description + ")");
serializer.flush();
}
public void testFinished(Description description) throws Exception {
debug(debug, "testFinished(" + description + ")");
serializer.flush();
}
@Override
public void testIgnored(Description description) throws Exception {
debug(debug, "testIgnored(T:" + description + ")");
}
@Override
public void testFailure(Failure failure) throws Exception {
debug(debug, "testFailure(T:" + failure + ")");
}
@Override
public void testAssumptionFailure(Failure failure) {
try {
debug(debug, "testAssumptionFailure(T:" + failure + ")");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
/*
* Instantiate method filter if any.
*/
String methodFilterGlob = Strings.emptyToNull(System.getProperty(SysGlobals.SYSPROP_TESTMETHOD()));
Filter methodFilter = Filter.ALL;
if (methodFilterGlob != null) {
methodFilter = new MethodGlobFilter(methodFilterGlob);
}
/*
* Important. Run each class separately so that we get separate
* {@link RunListener} callbacks for the top extracted description.
*/
debug(debug, "Entering main suite loop.");
try {
while (classNames.hasNext()) {
final String clName = classNames.next();
debug(debug, "Instantiating: " + clName);
Class<?> clazz = instantiate(clName);
if (clazz == null)
continue;
Request request = Request.aClass(clazz);
try {
Runner runner = request.getRunner();
methodFilter.apply(runner);
// New RunListener instances should be added per class and then removed from the RunNotifier
ArrayList<RunListener> runListenerInstances = instantiateRunListeners();
for (RunListener runListener : runListenerInstances) {
fNotifier.addListener(runListener);
}
fNotifier.fireTestRunStarted(runner.getDescription());
debug(debug, "Runner.run(" + clName + ")");
runner.run(fNotifier);
debug(debug, "Runner.done(" + clName + ")");
fNotifier.fireTestRunFinished(result);
for (RunListener runListener : runListenerInstances) {
fNotifier.removeListener(runListener);
}
} catch (NoTestsRemainException e) {
// Don't complain if all methods have been filtered out.
// I don't understand the reason why this exception has been
// built in to filters at all.
}
}
} catch (Throwable t) {
debug(debug, "Main suite loop error: " + t);
throw t;
} finally {
debug(debug, "Leaving main suite loop.");
debug.close();
}
}
use of org.junit.runner.notification.RunListener in project randomizedtesting by randomizedtesting.
the class WithNestedTestClass method runTests.
public static FullResult runTests(final Class<?>... classes) {
try {
final FullResult fullResult = new FullResult();
// Run on a separate thread so that it appears as we're not running in an IDE.
Thread thread = new Thread() {
@Override
public void run() {
final JUnitCore core = new JUnitCore();
core.addListener(new PrintEventListener(sysout));
core.addListener(new RunListener() {
@Override
public void testAssumptionFailure(Failure failure) {
fullResult.assumptionIgnored.incrementAndGet();
}
});
fullResult.result = core.run(classes);
}
};
thread.start();
thread.join();
return fullResult;
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
use of org.junit.runner.notification.RunListener in project junit4 by junit-team.
the class JUnit4TestAdapterCache method getNotifier.
public RunNotifier getNotifier(final TestResult result, final JUnit4TestAdapter adapter) {
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));
}
});
return notifier;
}
use of org.junit.runner.notification.RunListener in project junit4 by junit-team.
the class FailureList method result.
public Result result() {
Result result = new Result();
RunListener listener = result.createListener();
for (Failure failure : failures) {
try {
listener.testFailure(failure);
} catch (Exception e) {
throw new RuntimeException("I can't believe this happened");
}
}
return result;
}
Aggregations