Search in sources :

Example 1 with TestSuiteModel

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);
}
Also used : Signal(sun.misc.Signal) Description(org.junit.runner.Description) InOrder(org.mockito.InOrder) TestSuiteModel(com.google.testing.junit.runner.model.TestSuiteModel) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Request(org.junit.runner.Request) Test(org.junit.Test)

Example 2 with TestSuiteModel

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);
    }
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Filter(org.junit.runner.manipulation.Filter) RegExTestCaseFilter(com.google.testing.junit.junit4.runner.RegExTestCaseFilter) SuiteTrimmingFilter(com.google.testing.junit.junit4.runner.SuiteTrimmingFilter) TestSuiteModel(com.google.testing.junit.runner.model.TestSuiteModel) Request(org.junit.runner.Request) File(java.io.File) RunListener(org.junit.runner.notification.RunListener)

Example 3 with TestSuiteModel

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();
}
Also used : Description(org.junit.runner.Description) InOrder(org.mockito.InOrder) JUnitCore(org.junit.runner.JUnitCore) TestSuiteModel(com.google.testing.junit.runner.model.TestSuiteModel) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Request(org.junit.runner.Request) Test(org.junit.Test)

Example 4 with TestSuiteModel

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();
}
Also used : Description(org.junit.runner.Description) InOrder(org.mockito.InOrder) JUnitCore(org.junit.runner.JUnitCore) TestSuiteModel(com.google.testing.junit.runner.model.TestSuiteModel) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Request(org.junit.runner.Request) Test(org.junit.Test)

Example 5 with TestSuiteModel

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();
}
Also used : Description(org.junit.runner.Description) InOrder(org.mockito.InOrder) JUnitCore(org.junit.runner.JUnitCore) TestSuiteModel(com.google.testing.junit.runner.model.TestSuiteModel) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Request(org.junit.runner.Request) Test(org.junit.Test)

Aggregations

TestSuiteModel (com.google.testing.junit.runner.model.TestSuiteModel)9 Test (org.junit.Test)8 Request (org.junit.runner.Request)8 Description (org.junit.runner.Description)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 OutputStream (java.io.OutputStream)6 JUnitCore (org.junit.runner.JUnitCore)6 InOrder (org.mockito.InOrder)5 TestNode (com.google.testing.junit.runner.model.TestNode)2 RegExTestCaseFilter (com.google.testing.junit.junit4.runner.RegExTestCaseFilter)1 SuiteTrimmingFilter (com.google.testing.junit.junit4.runner.SuiteTrimmingFilter)1 File (java.io.File)1 Filter (org.junit.runner.manipulation.Filter)1 RunListener (org.junit.runner.notification.RunListener)1 Signal (sun.misc.Signal)1