Java Code Examples for org.junit.runner.Request#classWithoutSuiteMethod()
The following examples show how to use
org.junit.runner.Request#classWithoutSuiteMethod() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JUnit4RunnerTest.java From bazel with Apache License 2.0 | 6 votes |
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; }
Example 2
Source File: JUnit4TestModelBuilderTest.java From bazel with Apache License 2.0 | 6 votes |
@Test public void testTouchesShardFileWhenShardingEnabled() { 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(true); when(mockShardingEnvironment.getTotalShards()).thenReturn(2); modelBuilder.get(); verify(mockShardingEnvironment).touchShardFile(); }
Example 3
Source File: JUnit4TestModelBuilderTest.java From bazel with Apache License 2.0 | 6 votes |
@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(); }
Example 4
Source File: JUnit4TestModelBuilderTest.java From bazel with Apache License 2.0 | 6 votes |
@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()); assertThat(suiteNode.getDescription()).isEqualTo(suite); List<TestNode> testCases = suiteNode.getChildren(); assertThat(testCases).hasSize(2); TestNode testOneNode = testCases.get(0); TestNode testTwoNode = testCases.get(1); assertThat(testOneNode.getDescription()).isEqualTo(testOne); assertThat(testTwoNode.getDescription()).isEqualTo(testTwo); assertThat(testOneNode.getChildren()).isEmpty(); assertThat(testTwoNode.getChildren()).isEmpty(); assertThat(model.getNumTestCases()).isEqualTo(2); }
Example 5
Source File: JUnit4TestModelBuilderTest.java From bazel with Apache License 2.0 | 6 votes |
@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()); assertThat(topSuiteNode.getDescription()).isEqualTo(topSuite); TestNode innerSuiteNode = Iterables.getOnlyElement(topSuiteNode.getChildren()); assertThat(innerSuiteNode.getDescription()).isEqualTo(innerSuite); TestNode testOneNode = Iterables.getOnlyElement(innerSuiteNode.getChildren()); assertThat(testOneNode.getDescription()).isEqualTo(testOne); assertThat(testOneNode.getChildren()).isEmpty(); assertThat(model.getNumTestCases()).isEqualTo(1); }
Example 6
Source File: JUnit4TestXmlListenerTest.java From bazel with Apache License 2.0 | 6 votes |
@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); assertWithMessage("no output to stderr expected").that(errStream.size()).isEqualTo(0); InOrder inOrder = inOrder(mockModel); inOrder.verify(mockModel).testSkipped(testDescription); inOrder.verify(mockModel).writeAsXml(mockXmlStream); verify(mockRequestFactory, never()).cancelRun(); }
Example 7
Source File: JUnit4TestXmlListenerTest.java From bazel with Apache License 2.0 | 6 votes |
@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); assertWithMessage("no output to stderr expected").that(errStream.size()).isEqualTo(0); InOrder inOrder = inOrder(mockModel); inOrder.verify(mockModel).testSkipped(suiteDescription); inOrder.verify(mockModel).writeAsXml(mockXmlStream); verify(mockRequestFactory, never()).cancelRun(); }
Example 8
Source File: JUnit4TestXmlListenerTest.java From bazel with Apache License 2.0 | 6 votes |
@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); assertWithMessage("no output to stderr expected").that(errStream.size()).isEqualTo(0); InOrder inOrder = inOrder(mockModel); inOrder.verify(mockModel).testFailure(eq(testDescription), any(Throwable.class)); inOrder.verify(mockModel).writeAsXml(mockXmlStream); verify(mockRequestFactory, never()).cancelRun(); }
Example 9
Source File: JUnit4TestXmlListenerTest.java From bazel with Apache License 2.0 | 6 votes |
@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); assertWithMessage("no output to stderr expected").that(errStream.size()).isEqualTo(0); InOrder inOrder = inOrder(mockModel); inOrder.verify(mockModel).testSuppressed(testDescription); inOrder.verify(mockModel).writeAsXml(mockXmlStream); verify(mockRequestFactory, never()).cancelRun(); }
Example 10
Source File: JUnit4TestModelBuilderTest.java From bazel with Apache License 2.0 | 5 votes |
@Test public void testCreateModel_topLevelIgnore() throws Exception { Class<?> testClass = SampleTestCaseWithTopLevelIgnore.class; Request request = Request.classWithoutSuiteMethod(testClass); String testClassName = testClass.getCanonicalName(); JUnit4TestModelBuilder modelBuilder = builder(request, testClassName, stubShardingEnvironment, null, xmlResultWriter); TestSuiteModel testSuiteModel = modelBuilder.get(); assertThat(testSuiteModel.getNumTestCases()).isEqualTo(0); }
Example 11
Source File: JUnit4TestXmlListenerTest.java From bazel with Apache License 2.0 | 5 votes |
@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); assertThat(fakeSignalHandlers.handlers).hasSize(1); fakeSignalHandlers.handlers.get(0).handle(new Signal("TERM")); String errOutput = errStream.toString(CHARSET); assertWithMessage("expected signal name in stderr") .that(errOutput.contains("SIGTERM")) .isTrue(); assertWithMessage("expected message in stderr") .that(errOutput.contains("Done writing test XML")) .isTrue(); InOrder inOrder = inOrder(mockRequestFactory, mockModel); inOrder.verify(mockRequestFactory).cancelRun(); inOrder.verify(mockModel).testRunInterrupted(); inOrder.verify(mockModel).writeAsXml(mockXmlStream); }