GroovySurefireSensor implements Sensor { protected void collect(SensorContext context, File reportsDir) { LOGGER.info("parsing {}", reportsDir); groovySurefireParser.collect(context, reportsDir); } GroovySurefireSensor(GroovySurefireParser groovySurefireParser, Settings settings, FileSystem fs, PathResolver pathResolver); @Override void describe(SensorDescriptor descriptor); @Override void execute(SensorContext context); @Override String toString();  }
@Test public void shouldHandleTestSuiteDetails() throws URISyntaxException { SensorContextTester context = SensorContextTester.create(new File("")); context.fileSystem() .add(inputFile("org.sonar.core.ExtensionsFinderTest")) .add(inputFile("org.sonar.core.ExtensionsFinderTest2")) .add(inputFile("org.sonar.core.ExtensionsFinderTest3")); surefireSensor.collect(context, new File(getClass().getResource( "/org/sonar/plugins/groovy/surefire/SurefireSensorTest/shouldHandleTestSuiteDetails/").toURI())); assertThat(context.measures(":org.sonar.core.ExtensionsFinderTest")).hasSize(6); assertThat(context.measures(":org.sonar.core.ExtensionsFinderTest2")).hasSize(6); assertThat(context.measures(":org.sonar.core.ExtensionsFinderTest3")).hasSize(6); assertThat(context.measure(":org.sonar.core.ExtensionsFinderTest", CoreMetrics.TESTS).value()).isEqualTo(4); assertThat(context.measure(":org.sonar.core.ExtensionsFinderTest", CoreMetrics.TEST_EXECUTION_TIME).value()).isEqualTo(111); assertThat(context.measure(":org.sonar.core.ExtensionsFinderTest", CoreMetrics.TEST_FAILURES).value()).isEqualTo(1); assertThat(context.measure(":org.sonar.core.ExtensionsFinderTest", CoreMetrics.TEST_ERRORS).value()).isEqualTo(1); assertThat(context.measure(":org.sonar.core.ExtensionsFinderTest", CoreMetrics.SKIPPED_TESTS).value()).isEqualTo(0); assertThat(context.measure(":org.sonar.core.ExtensionsFinderTest2", CoreMetrics.TESTS).value()).isEqualTo(2); assertThat(context.measure(":org.sonar.core.ExtensionsFinderTest2", CoreMetrics.TEST_EXECUTION_TIME).value()).isEqualTo(2); assertThat(context.measure(":org.sonar.core.ExtensionsFinderTest2", CoreMetrics.TEST_FAILURES).value()).isEqualTo(0); assertThat(context.measure(":org.sonar.core.ExtensionsFinderTest2", CoreMetrics.TEST_ERRORS).value()).isEqualTo(0); assertThat(context.measure(":org.sonar.core.ExtensionsFinderTest2", CoreMetrics.SKIPPED_TESTS).value()).isEqualTo(0); assertThat(context.measure(":org.sonar.core.ExtensionsFinderTest3", CoreMetrics.TESTS).value()).isEqualTo(1); assertThat(context.measure(":org.sonar.core.ExtensionsFinderTest3", CoreMetrics.TEST_EXECUTION_TIME).value()).isEqualTo(16); assertThat(context.measure(":org.sonar.core.ExtensionsFinderTest3", CoreMetrics.TEST_FAILURES).value()).isEqualTo(0); assertThat(context.measure(":org.sonar.core.ExtensionsFinderTest3", CoreMetrics.TEST_ERRORS).value()).isEqualTo(0); assertThat(context.measure(":org.sonar.core.ExtensionsFinderTest3", CoreMetrics.SKIPPED_TESTS).value()).isEqualTo(1); }
@Test public void shouldSaveErrorsAndFailuresInXML() throws URISyntaxException { SensorContextTester context = SensorContextTester.create(new File("")); context.fileSystem() .add(inputFile("org.sonar.core.ExtensionsFinderTest")) .add(inputFile("org.sonar.core.ExtensionsFinderTest2")) .add(inputFile("org.sonar.core.ExtensionsFinderTest3")); surefireSensor.collect(context, new File(getClass().getResource( "/org/sonar/plugins/groovy/surefire/SurefireSensorTest/shouldSaveErrorsAndFailuresInXML/").toURI())); assertThat(context.measure(":org.sonar.core.ExtensionsFinderTest", CoreMetrics.SKIPPED_TESTS).value()).isEqualTo(1); assertThat(context.measure(":org.sonar.core.ExtensionsFinderTest", CoreMetrics.TESTS).value()).isEqualTo(7); assertThat(context.measures(":org.sonar.core.ExtensionsFinderTest")).hasSize(6); }
@Test public void shouldManageClassesWithDefaultPackage() throws URISyntaxException { SensorContextTester context = SensorContextTester.create(new File("")); context.fileSystem().add(inputFile("NoPackagesTest")); surefireSensor.collect(context, new File(getClass().getResource( "/org/sonar/plugins/groovy/surefire/SurefireSensorTest/shouldManageClassesWithDefaultPackage/").toURI())); assertThat(context.measure(":NoPackagesTest", CoreMetrics.TESTS).value()).isEqualTo(2); }
@Test public void successRatioIsZeroWhenAllTestsFail() throws URISyntaxException { SensorContextTester context = SensorContextTester.create(new File("")); context.fileSystem().add(inputFile("org.sonar.Foo")); surefireSensor.collect(context, new File(getClass().getResource( "/org/sonar/plugins/groovy/surefire/SurefireSensorTest/successRatioIsZeroWhenAllTestsFail/").toURI())); assertThat(context.measure(":org.sonar.Foo", CoreMetrics.TESTS).value()).isEqualTo(2); assertThat(context.measure(":org.sonar.Foo", CoreMetrics.TEST_FAILURES).value()).isEqualTo(1); assertThat(context.measure(":org.sonar.Foo", CoreMetrics.TEST_ERRORS).value()).isEqualTo(1); assertThat(context.measure(":org.sonar.Foo", CoreMetrics.TEST_SUCCESS_DENSITY).value()).isEqualTo(0); }
@Test public void measuresShouldNotIncludeSkippedTests() throws URISyntaxException { SensorContextTester context = SensorContextTester.create(new File("")); context.fileSystem().add(inputFile("org.sonar.Foo")); surefireSensor.collect(context, new File(getClass().getResource( "/org/sonar/plugins/groovy/surefire/SurefireSensorTest/measuresShouldNotIncludeSkippedTests/").toURI())); assertThat(context.measure(":org.sonar.Foo", CoreMetrics.TESTS).value()).isEqualTo(2); assertThat(context.measure(":org.sonar.Foo", CoreMetrics.TEST_FAILURES).value()).isEqualTo(1); assertThat(context.measure(":org.sonar.Foo", CoreMetrics.TEST_ERRORS).value()).isEqualTo(0); assertThat(context.measure(":org.sonar.Foo", CoreMetrics.SKIPPED_TESTS).value()).isEqualTo(1); assertThat(context.measure(":org.sonar.Foo", CoreMetrics.TEST_SUCCESS_DENSITY).value()).isEqualTo(50); }
@Test public void noSuccessRatioIfNoTests() throws URISyntaxException { SensorContextTester context = SensorContextTester.create(new File("")); context.fileSystem().add(inputFile("org.sonar.Foo")); surefireSensor.collect(context, new File(getClass().getResource( "/org/sonar/plugins/groovy/surefire/SurefireSensorTest/noSuccessRatioIfNoTests/").toURI())); assertThat(context.measure(":org.sonar.Foo", CoreMetrics.TESTS).value()).isEqualTo(0); assertThat(context.measure(":org.sonar.Foo", CoreMetrics.TEST_FAILURES).value()).isEqualTo(0); assertThat(context.measure(":org.sonar.Foo", CoreMetrics.TEST_ERRORS).value()).isEqualTo(0); assertThat(context.measure(":org.sonar.Foo", CoreMetrics.SKIPPED_TESTS).value()).isEqualTo(2); assertThat(context.measure(":org.sonar.Foo", CoreMetrics.TEST_SUCCESS_DENSITY)).isNull(); }
@Test public void ignoreSuiteAsInnerClass() throws URISyntaxException { SensorContextTester context = SensorContextTester.create(new File("")); context.fileSystem().add(inputFile("org.sonar.Foo")); surefireSensor.collect(context, new File(getClass().getResource( "/org/sonar/plugins/groovy/surefire/SurefireSensorTest/ignoreSuiteAsInnerClass/").toURI())); assertThat(context.measure(":org.apache.shindig.protocol.TestHandler", CoreMetrics.TESTS).value()).isEqualTo(0); assertThat(context.measure(":org.apache.shindig.protocol.TestHandler", CoreMetrics.SKIPPED_TESTS).value()).isEqualTo(1); }