use of com.google.testing.junit.runner.model.TestSuiteModel in project bazel by bazelbuild.
the class JUnit4TestXmlListenerTest method signalHandlerWritesXml.
@Test
public void signalHandlerWritesXml() 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(PassingTest.class);
Description suiteDescription = request.getRunner().getDescription();
when(mockModelSupplier.get()).thenReturn(mockModel);
listener.testRunStarted(suiteDescription);
assertEquals(1, fakeSignalHandlers.handlers.size());
fakeSignalHandlers.handlers.get(0).handle(new Signal("TERM"));
String errOutput = errStream.toString(CHARSET);
assertTrue("expected signal name in stderr", errOutput.contains("SIGTERM"));
assertTrue("expected message in stderr", errOutput.contains("Done writing test XML"));
InOrder inOrder = inOrder(mockRequestFactory, mockModel);
inOrder.verify(mockRequestFactory).cancelRun();
inOrder.verify(mockModel).testRunInterrupted();
inOrder.verify(mockModel).writeAsXml(mockXmlStream);
}
use of com.google.testing.junit.runner.model.TestSuiteModel 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 com.google.testing.junit.runner.model.TestSuiteModel in project bazel by bazelbuild.
the class JUnit4TestXmlListenerTest method assumptionViolationsAreReportedAsSkippedTests.
@Test
public void assumptionViolationsAreReportedAsSkippedTests() 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(TestWithAssumptionViolation.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).testSkipped(testDescription);
inOrder.verify(mockModel).writeAsXml(mockXmlStream);
verify(mockRequestFactory, never()).cancelRun();
}
use of com.google.testing.junit.runner.model.TestSuiteModel in project bazel by bazelbuild.
the class JUnit4TestXmlListenerTest method assumptionViolationsAtSuiteLevelAreReportedAsSkippedSuite.
@Test
public void assumptionViolationsAtSuiteLevelAreReportedAsSkippedSuite() 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(TestWithAssumptionViolationOnTheSuiteLevel.class);
Description suiteDescription = request.getRunner().getDescription();
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).testSkipped(suiteDescription);
inOrder.verify(mockModel).writeAsXml(mockXmlStream);
verify(mockRequestFactory, never()).cancelRun();
}
use of com.google.testing.junit.runner.model.TestSuiteModel 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