Search in sources :

Example 41 with Request

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

the class JUnit4TestXmlListenerTest method ignoredTestAreReportedAsSuppressedTests.

@Test
public void ignoredTestAreReportedAsSuppressedTests() 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(TestWithIgnoredTestCase.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).testSuppressed(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 42 with Request

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

the class JUnit4TestModelBuilderTest method testCreateModel_simpleSuite.

@Test
public void testCreateModel_simpleSuite() throws Exception {
    Class<?> suiteClass = SampleSuite.class;
    Request request = Request.classWithoutSuiteMethod(suiteClass);
    String suiteClassName = suiteClass.getCanonicalName();
    JUnit4TestModelBuilder modelBuilder = builder(request, suiteClassName, stubShardingEnvironment, null, xmlResultWriter);
    Description topSuite = request.getRunner().getDescription();
    Description innerSuite = topSuite.getChildren().get(0);
    Description testOne = innerSuite.getChildren().get(0);
    TestSuiteModel model = modelBuilder.get();
    TestNode topSuiteNode = Iterables.getOnlyElement(model.getTopLevelTestSuites());
    assertEquals(topSuite, topSuiteNode.getDescription());
    TestNode innerSuiteNode = Iterables.getOnlyElement(topSuiteNode.getChildren());
    assertEquals(innerSuite, innerSuiteNode.getDescription());
    TestNode testOneNode = Iterables.getOnlyElement(innerSuiteNode.getChildren());
    assertEquals(testOne, testOneNode.getDescription());
    assertTrue(testOneNode.getChildren().isEmpty());
    assertEquals(1, model.getNumTestCases());
}
Also used : Description(org.junit.runner.Description) TestSuiteModel(com.google.testing.junit.runner.model.TestSuiteModel) Request(org.junit.runner.Request) TestNode(com.google.testing.junit.runner.model.TestNode) Test(org.junit.Test)

Example 43 with Request

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

the class JUnit4TestModelBuilderTest method testCreateModel_singleTestClass.

@Test
public void testCreateModel_singleTestClass() throws Exception {
    Class<?> testClass = SampleTestCaseWithTwoTests.class;
    Request request = Request.classWithoutSuiteMethod(testClass);
    String testClassName = testClass.getCanonicalName();
    JUnit4TestModelBuilder modelBuilder = builder(request, testClassName, stubShardingEnvironment, null, xmlResultWriter);
    Description suite = request.getRunner().getDescription();
    Description testOne = suite.getChildren().get(0);
    Description testTwo = suite.getChildren().get(1);
    TestSuiteModel model = modelBuilder.get();
    TestNode suiteNode = Iterables.getOnlyElement(model.getTopLevelTestSuites());
    assertEquals(suite, suiteNode.getDescription());
    List<TestNode> testCases = suiteNode.getChildren();
    assertEquals(2, testCases.size());
    TestNode testOneNode = testCases.get(0);
    TestNode testTwoNode = testCases.get(1);
    assertEquals(testOne, testOneNode.getDescription());
    assertEquals(testTwo, testTwoNode.getDescription());
    assertTrue(testOneNode.getChildren().isEmpty());
    assertTrue(testTwoNode.getChildren().isEmpty());
    assertEquals(2, model.getNumTestCases());
}
Also used : Description(org.junit.runner.Description) TestSuiteModel(com.google.testing.junit.runner.model.TestSuiteModel) Request(org.junit.runner.Request) TestNode(com.google.testing.junit.runner.model.TestNode) Test(org.junit.Test)

Example 44 with Request

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

the class JUnit4TestModelBuilderTest method testDoesNotTouchShardFileWhenShardingDisabled.

@Test
public void testDoesNotTouchShardFileWhenShardingDisabled() {
    Class<?> testClass = SampleTestCaseWithTwoTests.class;
    Request request = Request.classWithoutSuiteMethod(testClass);
    ShardingEnvironment mockShardingEnvironment = mock(ShardingEnvironment.class);
    ShardingFilters shardingFilters = new ShardingFilters(mockShardingEnvironment, DEFAULT_SHARDING_STRATEGY);
    JUnit4TestModelBuilder modelBuilder = builder(request, testClass.getCanonicalName(), mockShardingEnvironment, shardingFilters, xmlResultWriter);
    when(mockShardingEnvironment.isShardingEnabled()).thenReturn(false);
    modelBuilder.get();
    verify(mockShardingEnvironment, never()).touchShardFile();
}
Also used : Request(org.junit.runner.Request) ShardingFilters(com.google.testing.junit.runner.sharding.ShardingFilters) StubShardingEnvironment(com.google.testing.junit.runner.sharding.testing.StubShardingEnvironment) ShardingEnvironment(com.google.testing.junit.runner.sharding.ShardingEnvironment) Test(org.junit.Test)

Example 45 with Request

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

the class ParentRunnerTest method testMultipleFilters.

@Test
public void testMultipleFilters() throws Exception {
    JUnitCore junitCore = new JUnitCore();
    Request request = Request.aClass(ExampleTest.class);
    Request requestFiltered = request.filterWith(new Exclude("test1"));
    Request requestFilteredFiltered = requestFiltered.filterWith(new Exclude("test2"));
    Result result = junitCore.run(requestFilteredFiltered);
    assertThat(result.getFailures(), isEmpty());
    assertEquals(1, result.getRunCount());
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Request(org.junit.runner.Request) Result(org.junit.runner.Result) Test(org.junit.Test)

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