use of org.junit.runner.Request in project bazel by bazelbuild.
the class JUnit4RunnerTest method getExpectedOutput.
private ByteArrayOutputStream getExpectedOutput(Class<?> testClass) {
JUnitCore core = new JUnitCore();
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(byteStream);
printStream.println("JUnit4 Test Runner");
RunListener listener = new TextListener(printStream);
core.addListener(listener);
Request request = Request.classWithoutSuiteMethod(testClass);
core.run(request);
printStream.close();
return byteStream;
}
use of org.junit.runner.Request in project bazel by bazelbuild.
the class TestRunner method main.
public static void main(String[] args) throws ClassNotFoundException {
if (args.length == 0) {
throw new IllegalArgumentException("Must specify at least one argument (source files of the tests to run)!");
}
JUnitCore junitCore = new JUnitCore();
junitCore.addListener(new TestListener());
SecurityManager previousSecurityManager = setGoogleTestSecurityManager();
Request request = createRequest(args);
Result result = junitCore.run(request);
restorePreviousSecurityManager(previousSecurityManager);
System.exit(result.wasSuccessful() ? 0 : 1);
}
use of org.junit.runner.Request in project bazel by bazelbuild.
the class CancellableRequestFactoryTest method testCancelRunBeforeStarting.
@Test
public void testCancelRunBeforeStarting() throws Exception {
final AtomicBoolean testRan = new AtomicBoolean(false);
// A runner that should never run its test
FakeRunner runner = new FakeRunner("shouldNotRun", new Runnable() {
@Override
public void run() {
testRan.set(true);
}
});
Request request = cancellableRequestFactory.createRequest(Request.runner(runner));
cancellableRequestFactory.cancelRun();
JUnitCore core = new JUnitCore();
try {
core.run(request);
fail("exception expected");
} catch (RuntimeException e) {
assertEquals("Test run interrupted", e.getMessage());
assertTrue(e.getCause() instanceof StoppedByUserException);
}
assertFalse(testRan.get());
}
use of org.junit.runner.Request in project bazel by bazelbuild.
the class CancellableRequestFactoryTest method testNormalRun.
@Test
public void testNormalRun() {
final AtomicBoolean testRan = new AtomicBoolean(false);
// A runner that should run its test
FakeRunner runner = new FakeRunner("shouldRun", new Runnable() {
@Override
public void run() {
testRan.set(true);
}
});
Request request = cancellableRequestFactory.createRequest(Request.runner(runner));
JUnitCore core = new JUnitCore();
Result result = core.run(request);
assertTrue(testRan.get());
assertEquals(1, result.getRunCount());
assertEquals(0, result.getFailureCount());
}
use of org.junit.runner.Request in project bazel by bazelbuild.
the class JUnit4TestXmlListenerTest method failuresAreReported.
@Test
public void failuresAreReported() throws Exception {
TestSuiteModelSupplier mockModelSupplier = mock(TestSuiteModelSupplier.class);
TestSuiteModel mockModel = mock(TestSuiteModel.class);
CancellableRequestFactory mockRequestFactory = mock(CancellableRequestFactory.class);
OutputStream mockXmlStream = mock(OutputStream.class);
JUnit4TestXmlListener listener = new JUnit4TestXmlListener(mockModelSupplier, mockRequestFactory, fakeSignalHandlers, mockXmlStream, errPrintStream);
Request request = Request.classWithoutSuiteMethod(FailingTest.class);
Description suiteDescription = request.getRunner().getDescription();
Description testDescription = suiteDescription.getChildren().get(0);
when(mockModelSupplier.get()).thenReturn(mockModel);
JUnitCore core = new JUnitCore();
core.addListener(listener);
core.run(request);
assertEquals("no output to stderr expected", 0, errStream.size());
InOrder inOrder = inOrder(mockModel);
inOrder.verify(mockModel).testFailure(eq(testDescription), any(Throwable.class));
inOrder.verify(mockModel).writeAsXml(mockXmlStream);
verify(mockRequestFactory, never()).cancelRun();
}
Aggregations