use of org.junit.runner.notification.RunListener in project mockito by mockito.
the class ConsoleSpammingMockitoJUnitRunner method run.
@Override
public void run(RunNotifier notifier) {
RunListener listener = new RunListener() {
WarningsCollector warningsCollector;
@Override
public void testStarted(Description description) throws Exception {
warningsCollector = new WarningsCollector();
}
@Override
public void testFailure(Failure failure) throws Exception {
logger.log(warningsCollector.getWarnings());
}
};
notifier.addListener(listener);
runner.run(notifier);
}
use of org.junit.runner.notification.RunListener in project mockito by mockito.
the class VerboseMockitoJUnitRunner method run.
@Override
public void run(RunNotifier notifier) {
//a listener that changes the failure's exception in a very hacky way...
RunListener listener = new RunListener() {
WarningsCollector warningsCollector;
@Override
public void testStarted(Description description) throws Exception {
warningsCollector = new WarningsCollector();
}
@Override
@SuppressWarnings("deprecation")
public void testFailure(final Failure failure) throws Exception {
String warnings = warningsCollector.getWarnings();
new JUnitFailureHacker().appendWarnings(failure, warnings);
}
};
notifier.addFirstListener(listener);
runner.run(notifier);
}
use of org.junit.runner.notification.RunListener in project jena by apache.
the class DBTest method execCmd.
@Override
protected void execCmd(List<String> args) {
if (isVerbose()) {
for (String k : params) System.out.printf("%-20s = %-20s\n", k, params.get(k));
System.out.println();
}
Connection jdbc = getModStore().getConnection().getSqlConnection();
// Hack to pass to calculated parameters to the test subsystem.
sdb.test.Env.set(jdbc, params, false);
JUnitCore x = new org.junit.runner.JUnitCore();
//RunListener listener = new TextListener2() ;
RunListener listener = new TextListener2(System.out);
x.addListener(listener);
//x.run(sdb.test.AllTests.class) ;
System.out.println("String basic");
x.run(TestStringBasic.class);
System.out.println("String I18N");
x.run(TestI18N.class);
// Better way of having parameters for a class than a @Parameterised test of one thing?
// Request request = Request.aClass(sdb.test.T.class) ;
// x.run(request) ;
}
use of org.junit.runner.notification.RunListener in project bazel by bazelbuild.
the class JUnit4Runner method run.
/**
* Runs the JUnit4 test.
*
* @return Result of running the test
*/
public Result run() {
testRunnerOut.println("JUnit4 Test Runner");
checkJUnitRunnerApiVersion();
for (Initializer init : initializers) {
init.initialize();
}
// Sharding
TestSuiteModel model = modelSupplier.get();
Filter shardingFilter = model.getShardingFilter();
Request filteredRequest = applyFilters(request, shardingFilter, config.getTestIncludeFilterRegexp(), config.getTestExcludeFilterRegexp());
JUnitCore core = new JUnitCore();
for (RunListener runListener : runListeners) {
core.addListener(runListener);
}
File exitFile = getExitFile();
exitFileActive(exitFile);
try {
try {
if (config.shouldInstallSecurityManager()) {
installSecurityManager();
}
Request cancellableRequest = requestFactory.createRequest(filteredRequest);
return core.run(cancellableRequest);
} finally {
disableSecurityManager();
}
} finally {
exitFileInactive(exitFile);
}
}
use of org.junit.runner.notification.RunListener in project buck by facebook.
the class TimeoutTest method doTestUsingThreadGuardedTestClass.
private void doTestUsingThreadGuardedTestClass() throws InitializationError {
Class<?> testClass = ThreadGuardedTest.class;
RunnerBuilder builder = new RunnerBuilder() {
@Override
public Runner runnerForClass(Class<?> clazz) throws Throwable {
return new BuckBlockJUnit4ClassRunner(clazz, /* defaultTestTimeoutMillis */
500);
}
};
Runner suite = new Computer().getSuite(builder, new Class<?>[] { testClass });
Request request = Request.runner(suite);
final Set<Result> results = Sets.newHashSet();
JUnitCore core = new JUnitCore();
core.addListener(new RunListener() {
@Override
public void testRunFinished(Result result) throws Exception {
results.add(result);
}
});
core.run(request);
Result result = Iterables.getOnlyElement(results);
assertEquals(3, result.getRunCount());
assertEquals(2, result.getFailureCount());
// The order in which the tests were run doesn't matter. What matters is that we see our
// expected messages.
Set<String> messages = result.getFailures().stream().map(Failure::getMessage).collect(MoreCollectors.toImmutableSet());
assertEquals("Should contain explicit call to fail() from failingTestsAreReported() and " + "the timeout message from testsMayTimeOut().", ImmutableSet.of("This is expected", "test testsMayTimeOut timed out after 500 milliseconds"), messages);
}
Aggregations