use of org.junit.runner.notification.RunListener 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.RunListener 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.RunListener in project randomizedtesting by randomizedtesting.
the class RandomizedRunner method subscribeListeners.
/**
* Subscribe annotation listeners to the notifier.
*/
private void subscribeListeners(RunNotifier notifier) {
for (Listeners ann : getAnnotationsFromClassHierarchy(suiteClass, Listeners.class)) {
for (Class<? extends RunListener> clazz : ann.value()) {
try {
RunListener listener = clazz.newInstance();
autoListeners.add(listener);
notifier.addListener(listener);
} catch (Throwable t) {
throw new RuntimeException("Could not initialize suite class: " + suiteClass.getName() + " because its @Listener is not instantiable: " + clazz.getName(), t);
}
}
}
}
use of org.junit.runner.notification.RunListener in project randomizedtesting by randomizedtesting.
the class RandomizedRunner method runSuite.
/**
* Test execution logic for the entire suite, executing under designated
* {@link RunnerThreadGroup}.
*/
private void runSuite(final RandomizedContext context, final RunNotifier notifier) {
final Result result = new Result();
final RunListener accounting = result.createListener();
notifier.addListener(accounting);
final Randomness classRandomness = runnerRandomness.clone(Thread.currentThread());
context.push(classRandomness);
try {
// Check for automatically hookable listeners.
subscribeListeners(notifier);
// Fire a synthetic "suite started" event.
for (RunListener r : autoListeners) {
try {
r.testRunStarted(suiteDescription);
} catch (Throwable e) {
logger.log(Level.SEVERE, "Panic: RunListener hook shouldn't throw exceptions.", e);
}
}
final List<TestCandidate> tests = testCandidates;
if (!tests.isEmpty()) {
Map<TestCandidate, Boolean> ignored = determineIgnoredTests(tests);
if (ignored.size() == tests.size()) {
// All tests ignored, ignore class hooks but report all the ignored tests.
for (TestCandidate c : tests) {
if (ignored.get(c)) {
reportAsIgnored(notifier, groupEvaluator, c);
}
}
} else {
ThreadLeakControl threadLeakControl = new ThreadLeakControl(notifier, this);
Statement s = runTestsStatement(threadLeakControl.notifier(), tests, ignored, threadLeakControl);
s = withClassBefores(s);
s = withClassAfters(s);
s = withClassRules(s);
s = withCloseContextResources(s, LifecycleScope.SUITE);
s = threadLeakControl.forSuite(s, suiteDescription);
try {
s.evaluate();
} catch (Throwable t) {
t = augmentStackTrace(t, runnerRandomness);
if (isAssumptionViolated(t)) {
// Fire assumption failure before method ignores. (GH-103).
notifier.fireTestAssumptionFailed(new Failure(suiteDescription, t));
// see Rants#RANT_3
for (final TestCandidate c : tests) {
notifier.fireTestIgnored(c.description);
}
} else {
fireTestFailure(notifier, suiteDescription, t);
}
}
}
}
} catch (Throwable t) {
notifier.fireTestFailure(new Failure(suiteDescription, t));
}
// Fire a synthetic "suite ended" event and unsubscribe listeners.
for (RunListener r : autoListeners) {
try {
r.testRunFinished(result);
} catch (Throwable e) {
logger.log(Level.SEVERE, "Panic: RunListener hook shouldn't throw exceptions.", e);
}
}
// Final cleanup.
notifier.removeListener(accounting);
unsubscribeListeners(notifier);
context.popAndDestroy();
}
use of org.junit.runner.notification.RunListener in project randomizedtesting by randomizedtesting.
the class TestSeedParameterOptional method checkNames.
@Test
public void checkNames() {
final HashSet<String> tests = new HashSet<String>();
JUnitCore junit = new JUnitCore();
junit.addListener(new RunListener() {
@Override
public void testStarted(Description description) throws Exception {
tests.add(description.getMethodName());
}
});
junit.run(Nested.class);
// Single repetitions, no seed parameter in test name.
Assert.assertTrue(tests.contains("method2"));
Assert.assertTrue(tests.contains("method3"));
// Method 1 has 2x3 repetitions.
int count = 0;
for (String s : tests) {
if (s.startsWith("method1")) {
count++;
}
}
Assert.assertEquals(6, count);
}
Aggregations