CuppaRunner extends Runner { @Override public void run(RunNotifier notifier) { runner.run(rootBlock, new ReportJUnitAdapter(notifier)); } CuppaRunner(Class<?> annotatedClass); @Override Description getDescription(); @Override void run(RunNotifier notifier);  }
@Test public void shouldReportCorrectDescriptionsOfSuite() { JUnitCore jUnit = new JUnitCore(); jUnit.addListener(new RunListener() { @Override public void testRunStarted(Description description) throws Exception { suiteDescription = description; } }); jUnit.run(CuppaRunnerTest.PassingTest.class); assertThat(suiteDescription).isNotNull(); assertThat(suiteDescription.isSuite()).isTrue(); assertThat(suiteDescription.getChildren()).hasSize(1); Description cuppaDescription = suiteDescription.getChildren().get(0); assertThat(cuppaDescription.isSuite()).isTrue(); assertThat(cuppaDescription.getDisplayName()).isEqualTo(CuppaRunnerTest.PassingTest.class.getName()); assertThat(cuppaDescription.getChildren()).hasSize(1); Description describeDescription = cuppaDescription.getChildren().get(0); assertThat(describeDescription.isSuite()).isTrue(); assertThat(describeDescription.getDisplayName()).isEqualTo("Cuppa"); assertThat(describeDescription.getChildren()).hasSize(1); Description whenDescription = describeDescription.getChildren().get(0); assertThat(whenDescription.isSuite()).isTrue(); assertThat(whenDescription.getDisplayName()).isEqualTo("when running with CuppaRunner"); assertThat(whenDescription.getChildren()).hasSize(1); Description testDescription = whenDescription.getChildren().get(0); assertThat(testDescription.isTest()).isTrue(); assertThat(testDescription.getDisplayName()).isEqualTo("shows a passing test as passing(" + CuppaRunnerTest.PassingTest.class.getName() + ")"); assertThat(testDescription.getTestClass()).isEqualTo(CuppaRunnerTest.PassingTest.class); }
@Test public void shouldReportSameTestDescriptionsAsGivenBeforeStart() { List<Description> testDescriptions = new ArrayList<>(); JUnitCore jUnit = new JUnitCore(); jUnit.addListener(new RunListener() { @Override public void testRunStarted(Description description) throws Exception { suiteDescription = description; } @Override public void testStarted(Description description) throws Exception { testDescriptions.add(description); } }); jUnit.run(CuppaRunnerTest.PassingTest.class); Description testDescription = suiteDescription.getChildren().get(0) .getChildren().get(0) .getChildren().get(0) .getChildren().get(0); assertThat(testDescriptions).hasSize(1); assertThat(testDescriptions.get(0)).isEqualTo(testDescription); }
@Test public void shouldReportDistinctDescriptionsForTestsWithSameName() { List<Description> testDescriptions = new ArrayList<>(); JUnitCore jUnit = new JUnitCore(); jUnit.addListener(new RunListener() { @Override public void testRunStarted(Description description) throws Exception { suiteDescription = description; } @Override public void testStarted(Description description) throws Exception { testDescriptions.add(description); } }); jUnit.run(CuppaRunnerTest.DuplicateTests.class); Description describeDescription = suiteDescription.getChildren().get(0) .getChildren().get(0); Description test1Description = describeDescription.getChildren().get(0).getChildren().get(0); Description test2Description = describeDescription.getChildren().get(1).getChildren().get(0); assertThat(test1Description).isNotEqualTo(test2Description); assertThat(testDescriptions).hasSize(2); assertThat(testDescriptions.get(0)).isNotEqualTo(testDescriptions.get(1)); assertThat(testDescriptions.get(0)).isEqualTo(test1Description); assertThat(testDescriptions.get(1)).isEqualTo(test2Description); }
@Test public void shouldReportDistinctDescriptionsForTestBlocksWithSameName() { List<Description> testDescriptions = new ArrayList<>(); JUnitCore jUnit = new JUnitCore(); jUnit.addListener(new RunListener() { @Override public void testRunStarted(Description description) throws Exception { suiteDescription = description; } @Override public void testStarted(Description description) throws Exception { testDescriptions.add(description); } }); jUnit.run(CuppaRunnerTest.DuplicateTestBlocks.class); Description when1Description = suiteDescription.getChildren().get(0) .getChildren().get(0) .getChildren().get(0); Description when2Description = suiteDescription.getChildren().get(0) .getChildren().get(1) .getChildren().get(0); assertThat(when1Description).isNotEqualTo(when2Description); }
@Test public void shouldReportDescriptionsinCorrectOrder() { JUnitCore jUnit = new JUnitCore(); jUnit.addListener(new RunListener() { @Override public void testRunStarted(Description description) throws Exception { suiteDescription = description; } }); jUnit.run(CuppaRunnerTest.TestsAndTestBlocks.class); List<Description> rootDescriptionChildren = suiteDescription .getChildren().get(0).getChildren().get(0).getChildren(); assertThat(rootDescriptionChildren).hasSize(3); assertThat(rootDescriptionChildren.get(0).getDisplayName()).startsWith("a"); assertThat(rootDescriptionChildren.get(1).getDisplayName()).startsWith("b"); assertThat(rootDescriptionChildren.get(2).getDisplayName()).startsWith("when c"); assertThat(rootDescriptionChildren.get(2).getChildren().get(0).getDisplayName()).startsWith("d"); }