Search in sources :

Example 31 with Request

use of org.junit.runner.Request in project junit4 by junit-team.

the class CategoryTest method testCountWithExplicitExcludeFilter_usingConstructor.

@Test
public void testCountWithExplicitExcludeFilter_usingConstructor() throws Throwable {
    CategoryFilter include = new CategoryFilter(null, SlowTests.class);
    Request baseRequest = Request.aClass(TestSuiteWithNoCategories.class);
    Result result = new JUnitCore().run(baseRequest.filterWith(include));
    assertEquals(2, result.getFailureCount());
    assertEquals(2, result.getRunCount());
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Request(org.junit.runner.Request) CategoryFilter(org.junit.experimental.categories.Categories.CategoryFilter) Result(org.junit.runner.Result) PrintableResult.testResult(org.junit.experimental.results.PrintableResult.testResult) Test(org.junit.Test)

Example 32 with Request

use of org.junit.runner.Request in project junit4 by junit-team.

the class CategoryTest method testCountWithMultipleIncludeFilter.

@Test
public void testCountWithMultipleIncludeFilter() throws Throwable {
    CategoryFilter exclude = CategoryFilter.include(true, SlowTests.class, FastTests.class);
    Request baseRequest = Request.aClass(OneOfEach.class);
    Result result = new JUnitCore().run(baseRequest.filterWith(exclude));
    assertTrue(result.wasSuccessful());
    assertEquals(2, result.getRunCount());
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Request(org.junit.runner.Request) CategoryFilter(org.junit.experimental.categories.Categories.CategoryFilter) Result(org.junit.runner.Result) PrintableResult.testResult(org.junit.experimental.results.PrintableResult.testResult) Test(org.junit.Test)

Example 33 with Request

use of org.junit.runner.Request 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 34 with Request

use of org.junit.runner.Request 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 35 with Request

use of org.junit.runner.Request in project bazel by bazelbuild.

the class MemoizingRequestTest method testOverridingCreateRunner.

public void testOverridingCreateRunner() {
    final Runner stubRunner = mock(Runner.class);
    MemoizingRequest memoizingRequest = new MemoizingRequest(mockRequestDelegate) {

        @Override
        protected Runner createRunner(Request delegate) {
            return stubRunner;
        }
    };
    Runner firstRunner = memoizingRequest.getRunner();
    Runner secondRunner = memoizingRequest.getRunner();
    assertSame(stubRunner, firstRunner);
    assertSame(firstRunner, secondRunner);
    verifyZeroInteractions(mockRequestDelegate);
}
Also used : Runner(org.junit.runner.Runner) Request(org.junit.runner.Request)

Aggregations

Request (org.junit.runner.Request)56 Test (org.junit.Test)37 JUnitCore (org.junit.runner.JUnitCore)33 Result (org.junit.runner.Result)23 Description (org.junit.runner.Description)20 Runner (org.junit.runner.Runner)9 TestSuiteModel (com.google.testing.junit.runner.model.TestSuiteModel)8 PrintableResult.testResult (org.junit.experimental.results.PrintableResult.testResult)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Filter (org.junit.runner.manipulation.Filter)6 Failure (org.junit.runner.notification.Failure)6 RunListener (org.junit.runner.notification.RunListener)6 OutputStream (java.io.OutputStream)5 CategoryFilter (org.junit.experimental.categories.Categories.CategoryFilter)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 InOrder (org.mockito.InOrder)4 Computer (org.junit.runner.Computer)3 RunNotifier (org.junit.runner.notification.RunNotifier)3