SurefireSensor implements Sensor { protected void collect(SensorContext context, List<File> reportsDirs) { LOGGER.info("parsing {}", reportsDirs); surefireJavaParser.collect(context, reportsDirs, settings.hasKey(SurefireUtils.SUREFIRE_REPORT_PATHS_PROPERTY)); } SurefireSensor(SurefireJavaParser surefireJavaParser, Configuration settings, FileSystem fs, PathResolver pathResolver); @Override void describe(SensorDescriptor descriptor); @Override void execute(SensorContext context); @Override String toString();  }
@Test void shouldHandleTestSuiteDetails() throws URISyntaxException { SensorContextTester context = SensorContextTester.create(new File("")); context.fileSystem() .add(resource("org.sonar.core.ExtensionsFinderTest")) .add(resource("org.sonar.core.ExtensionsFinderTest2")) .add(resource("org.sonar.core.ExtensionsFinderTest3")); collect(context, "/org/sonar/plugins/surefire/SurefireSensorTest/shouldHandleTestSuiteDetails/"); assertThat(context.measures(":org.sonar.core.ExtensionsFinderTest")).hasSize(5); assertThat(context.measures(":org.sonar.core.ExtensionsFinderTest2")).hasSize(5); assertThat(context.measures(":org.sonar.core.ExtensionsFinderTest3")).hasSize(5); 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(111L); 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()).isZero(); 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()).isZero(); assertThat(context.measure(":org.sonar.core.ExtensionsFinderTest2", CoreMetrics.TEST_ERRORS).value()).isZero(); assertThat(context.measure(":org.sonar.core.ExtensionsFinderTest2", CoreMetrics.SKIPPED_TESTS).value()).isZero(); 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()).isZero(); assertThat(context.measure(":org.sonar.core.ExtensionsFinderTest3", CoreMetrics.TEST_ERRORS).value()).isZero(); assertThat(context.measure(":org.sonar.core.ExtensionsFinderTest3", CoreMetrics.SKIPPED_TESTS).value()).isEqualTo(1); }
@Test void shouldSaveErrorsAndFailuresInXML() throws URISyntaxException { SensorContextTester context = SensorContextTester.create(new File("")); context.fileSystem() .add(resource("org.sonar.core.ExtensionsFinderTest")) .add(resource("org.sonar.core.ExtensionsFinderTest2")) .add(resource("org.sonar.core.ExtensionsFinderTest3")); collect(context, "/org/sonar/plugins/surefire/SurefireSensorTest/shouldSaveErrorsAndFailuresInXML/"); assertThat(context.measures(":org.sonar.core.ExtensionsFinderTest")).hasSize(5); 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); }
@Test void shouldSupportLongAttributeValues() throws URISyntaxException { SensorContextTester context = SensorContextTester.create(new File("")); collect(context, "/org/sonar/plugins/surefire/SurefireSensorTest/should_support_long_attribute_values/"); assertThat(context.allAnalysisErrors()).isEmpty(); }
@Test void shouldManageClassesWithDefaultPackage() throws URISyntaxException { SensorContextTester context = SensorContextTester.create(new File("")); context.fileSystem() .add(resource("NoPackagesTest")); collect(context, "/org/sonar/plugins/surefire/SurefireSensorTest/shouldManageClassesWithDefaultPackage/"); assertThat(context.measure(":NoPackagesTest", CoreMetrics.TESTS).value()).isEqualTo(2); }
@Test void successRatioIsZeroWhenAllTestsFail() throws URISyntaxException { SensorContextTester context = SensorContextTester.create(new File("")); context.fileSystem() .add(resource("org.sonar.Foo")); collect(context, "/org/sonar/plugins/surefire/SurefireSensorTest/successRatioIsZeroWhenAllTestsFail/"); 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); }
@Test void measuresShouldNotIncludeSkippedTests() throws URISyntaxException { SensorContextTester context = SensorContextTester.create(new File("")); context.fileSystem() .add(resource("org.sonar.Foo")); collect(context, "/org/sonar/plugins/surefire/SurefireSensorTest/measuresShouldNotIncludeSkippedTests/"); 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()).isZero(); assertThat(context.measure(":org.sonar.Foo", CoreMetrics.SKIPPED_TESTS).value()).isEqualTo(1); }
@Test void noSuccessRatioIfNoTests() throws URISyntaxException { SensorContextTester context = SensorContextTester.create(new File("")); context.fileSystem() .add(resource("org.sonar.Foo")); collect(context, "/org/sonar/plugins/surefire/SurefireSensorTest/noSuccessRatioIfNoTests/"); assertThat(context.measure(":org.sonar.Foo", CoreMetrics.TESTS).value()).isZero(); assertThat(context.measure(":org.sonar.Foo", CoreMetrics.TEST_FAILURES).value()).isZero(); assertThat(context.measure(":org.sonar.Foo", CoreMetrics.TEST_ERRORS).value()).isZero(); assertThat(context.measure(":org.sonar.Foo", CoreMetrics.SKIPPED_TESTS).value()).isEqualTo(2); }
@Test void should_support_reportNameSuffix() throws URISyntaxException { SensorContextTester context = SensorContextTester.create(new File("")); context.fileSystem() .add(resource("org.sonar.Foo")); collect(context, "/org/sonar/plugins/surefire/SurefireSensorTest/should_support_reportNameSuffix/"); assertThat(context.measure(":org.sonar.Foo", CoreMetrics.TESTS).value()).isEqualTo(4); assertThat(context.measure(":org.sonar.Foo", CoreMetrics.TEST_FAILURES).value()).isEqualTo(2); assertThat(context.measure(":org.sonar.Foo", CoreMetrics.TEST_ERRORS).value()).isZero(); assertThat(context.measure(":org.sonar.Foo", CoreMetrics.SKIPPED_TESTS).value()).isEqualTo(2); }