}
@Test
- public void unit_test_coverage() throws Exception {
+ public void coverage() throws Exception {
orchestrator.executeBuilds(SonarScanner.create(projectDir("testing/xoo-sample-ut-coverage")));
Resource project = orchestrator.getServer().getWsClient().find(ResourceQuery.createForMetrics("sample-ut-coverage", ALL_COVERAGE_METRICS));
}
@Test
- public void unit_test_coverage_no_condition() throws Exception {
+ public void coverage_no_condition() throws Exception {
orchestrator.executeBuilds(SonarScanner.create(projectDir("testing/xoo-sample-ut-coverage-no-condition")));
Resource project = orchestrator.getServer().getWsClient().find(ResourceQuery.createForMetrics("sample-ut-coverage", ALL_COVERAGE_METRICS));
}
@Test
- public void it_coverage() throws Exception {
+ public void it_coverage_imported_as_coverage() throws Exception {
orchestrator.executeBuilds(SonarScanner.create(projectDir("testing/xoo-sample-it-coverage")));
Resource project = orchestrator.getServer().getWsClient().find(ResourceQuery.createForMetrics("sample-it-coverage", ALL_COVERAGE_METRICS));
- assertThat(project.getMeasureValue("coverage")).isNull();
- assertThat(project.getMeasureValue("it_line_coverage")).isEqualTo(50.0);
- assertThat(project.getMeasureValue("it_lines_to_cover")).isEqualTo(4);
- assertThat(project.getMeasureValue("it_uncovered_lines")).isEqualTo(2);
- assertThat(project.getMeasureValue("it_branch_coverage")).isEqualTo(50.0);
- assertThat(project.getMeasureValue("it_conditions_to_cover")).isEqualTo(2);
- assertThat(project.getMeasureValue("it_uncovered_conditions")).isEqualTo(1);
- assertThat(project.getMeasureValue("it_coverage")).isEqualTo(50.0);
+ // Since SQ 6.2 all coverage reports are merged as coverage
+
+ assertThat(project.getMeasureValue("line_coverage")).isEqualTo(50.0);
+ assertThat(project.getMeasureValue("lines_to_cover")).isEqualTo(4);
+ assertThat(project.getMeasureValue("uncovered_lines")).isEqualTo(2);
+ assertThat(project.getMeasureValue("branch_coverage")).isEqualTo(50.0);
+ assertThat(project.getMeasureValue("conditions_to_cover")).isEqualTo(2);
+ assertThat(project.getMeasureValue("uncovered_conditions")).isEqualTo(1);
+ assertThat(project.getMeasureValue("coverage")).isEqualTo(50.0);
+
+ assertThat(project.getMeasureValue("it_coverage")).isNull();
assertThat(project.getMeasureValue("overall_coverage")).isNull();
}
@Test
- public void ut_and_it_coverage() throws Exception {
+ public void ut_and_it_coverage_merged_in_coverage() throws Exception {
orchestrator.executeBuilds(SonarScanner.create(projectDir("testing/xoo-sample-overall-coverage")));
+ // Since SQ 6.2 all coverage reports are merged as coverage
+
Resource project = orchestrator.getServer().getWsClient().find(ResourceQuery.createForMetrics("sample-overall-coverage", ALL_COVERAGE_METRICS));
assertThat(project.getMeasureValue("line_coverage")).isEqualTo(50.0);
assertThat(project.getMeasureValue("lines_to_cover")).isEqualTo(4);
assertThat(project.getMeasureValue("uncovered_conditions")).isEqualTo(3);
assertThat(project.getMeasureValue("coverage")).isEqualTo(37.5);
- assertThat(project.getMeasureValue("it_line_coverage")).isEqualTo(50.0);
- assertThat(project.getMeasureValue("it_lines_to_cover")).isEqualTo(4);
- assertThat(project.getMeasureValue("it_uncovered_lines")).isEqualTo(2);
- assertThat(project.getMeasureValue("it_branch_coverage")).isEqualTo(25.0);
- assertThat(project.getMeasureValue("it_conditions_to_cover")).isEqualTo(4);
- assertThat(project.getMeasureValue("it_uncovered_conditions")).isEqualTo(3);
- assertThat(project.getMeasureValue("it_coverage")).isEqualTo(37.5);
-
- assertThat(project.getMeasureValue("overall_line_coverage")).isEqualTo(75.0);
- assertThat(project.getMeasureValue("overall_lines_to_cover")).isEqualTo(4);
- assertThat(project.getMeasureValue("overall_uncovered_lines")).isEqualTo(1);
- assertThat(project.getMeasureValue("overall_branch_coverage")).isEqualTo(50.0);
- assertThat(project.getMeasureValue("overall_conditions_to_cover")).isEqualTo(4);
- assertThat(project.getMeasureValue("overall_uncovered_conditions")).isEqualTo(2);
- assertThat(project.getMeasureValue("overall_coverage")).isEqualTo(62.5);
+ assertThat(project.getMeasureValue("it_coverage")).isNull();
+
+ assertThat(project.getMeasureValue("overall_coverage")).isNull();
String coverage = cleanupScmAndDuplication(orchestrator.getServer().adminWsClient().get("api/sources/lines", "key", "sample-overall-coverage:src/main/xoo/sample/Sample.xoo"));
// Use strict checking to be sure no extra coverage is present
"sources": [
{
"line": 1,
- "code": "package sample;",
+ "code": "package sample;"
},
{
"line": 2,
- "code": "",
+ "code": ""
},
{
"line": 3,
- "code": "public class Sample {",
+ "code": "public class Sample {"
},
{
"line": 4,
- "code": "\t",
+ "code": "\t"
},
{
"line": 5,
- "code": "\tpublic Sample(int i) {",
+ "code": "\tpublic Sample(int i) {"
},
{
"line": 6,
"code": "\t\tint j = i++;",
- "itLineHits": 1
+ "utLineHits": 1
},
{
"line": 7,
- "code": "\t}",
+ "code": "\t}"
},
{
"line": 8,
- "code": "\t",
+ "code": "\t"
},
{
"line": 9,
- "code": "\tprivate String myMethod() {",
+ "code": "\tprivate String myMethod() {"
},
{
"line": 10,
"code": "\t\tif (foo == bar) {",
- "itLineHits": 0,
- "itConditions": 2,
- "itCoveredConditions": 1
+ "utLineHits": 0,
+ "utConditions": 2,
+ "utCoveredConditions": 1
},
{
"line": 11,
"code": "\t\t\treturn \"hello\";",
- "itLineHits": 1
+ "utLineHits": 1
},
{
"line": 12,
- "code": "\t\t} else {",
+ "code": "\t\t} else {"
},
{
"line": 13,
"code": "\t\t\tthrow new IllegalStateException();",
- "itLineHits": 0
+ "utLineHits": 0
},
{
"line": 14,
- "code": "\t\t}",
+ "code": "\t\t}"
},
{
"line": 15,
- "code": "\t}",
+ "code": "\t}"
},
{
"line": 16,
- "code": "}",
+ "code": "}"
},
{
"line": 17,
- "code": "",
+ "code": ""
}
]
}
"sources": [
{
"line": 1,
- "code": "package sample;",
+ "code": "package sample;"
},
{
"line": 2,
- "code": "",
+ "code": ""
},
{
"line": 3,
- "code": "public class Sample {",
+ "code": "public class Sample {"
},
{
"line": 4,
- "code": "\t",
+ "code": "\t"
},
{
"line": 5,
- "code": "\tpublic Sample(int i) {",
+ "code": "\tpublic Sample(int i) {"
},
{
"line": 6,
"code": "\t\tint j = i++;",
- "utLineHits": 1,
- "itLineHits": 1
+ "utLineHits": 1
},
{
"line": 7,
- "code": "\t}",
+ "code": "\t}"
},
{
"line": 8,
- "code": "\t",
+ "code": "\t"
},
{
"line": 9,
- "code": "\tprivate String myMethod() {",
+ "code": "\tprivate String myMethod() {"
},
{
"line": 10,
"code": "\t\tif (foo == bar && biz > 1) {",
"utLineHits": 0,
"utConditions": 4,
- "utCoveredConditions": 1,
- "itLineHits": 0,
- "itConditions": 4,
- "itCoveredConditions": 1
+ "utCoveredConditions": 1
},
{
"line": 11,
"code": "\t\t\treturn \"hello\";",
- "utLineHits": 1,
- "itLineHits": 0
+ "utLineHits": 1
},
{
"line": 12,
- "code": "\t\t} else {",
+ "code": "\t\t} else {"
},
{
"line": 13,
"code": "\t\t\tthrow new IllegalStateException();",
- "utLineHits": 0,
- "itLineHits": 1
+ "utLineHits": 1
},
{
"line": 14,
- "code": "\t\t}",
+ "code": "\t\t}"
},
{
"line": 15,
- "code": "\t}",
+ "code": "\t}"
},
{
"line": 16,
- "code": "}",
+ "code": "}"
},
{
"line": 17,
- "code": "",
+ "code": ""
}
]
import javax.annotation.CheckForNull;
import org.sonar.db.protobuf.DbFileSources;
import org.sonar.scanner.protocol.output.ScannerReport;
-import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage.HasItCoveredConditionsCase;
-import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage.HasItHitsCase;
-import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage.HasOverallCoveredConditionsCase;
-import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage.HasUtCoveredConditionsCase;
-import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage.HasUtHitsCase;
+import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage.HasCoveredConditionsCase;
+import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage.HasHitsCase;
public class CoverageLineReader implements LineReader {
ScannerReport.LineCoverage reportCoverage = getNextLineCoverageIfMatchLine(lineBuilder.getLine());
if (reportCoverage != null) {
processUnitTest(lineBuilder, reportCoverage);
- processIntegrationTest(lineBuilder, reportCoverage);
processOverallTest(lineBuilder, reportCoverage);
coverage = null;
}
}
private static void processUnitTest(DbFileSources.Line.Builder lineBuilder, ScannerReport.LineCoverage reportCoverage) {
- if (reportCoverage.getHasUtHitsCase() == HasUtHitsCase.UT_HITS) {
- lineBuilder.setUtLineHits(reportCoverage.getUtHits() ? 1 : 0);
+ if (reportCoverage.getHasHitsCase() == HasHitsCase.HITS) {
+ lineBuilder.setUtLineHits(reportCoverage.getHits() ? 1 : 0);
}
- if (reportCoverage.getHasUtCoveredConditionsCase() == HasUtCoveredConditionsCase.UT_COVERED_CONDITIONS) {
+ if (reportCoverage.getHasCoveredConditionsCase() == HasCoveredConditionsCase.COVERED_CONDITIONS) {
lineBuilder.setUtConditions(reportCoverage.getConditions());
- lineBuilder.setUtCoveredConditions(reportCoverage.getUtCoveredConditions());
- }
- }
-
- private static void processIntegrationTest(DbFileSources.Line.Builder lineBuilder, ScannerReport.LineCoverage reportCoverage) {
- if (reportCoverage.getHasItHitsCase() == HasItHitsCase.IT_HITS) {
- lineBuilder.setItLineHits(reportCoverage.getItHits() ? 1 : 0);
- }
- if (reportCoverage.getHasItCoveredConditionsCase() == HasItCoveredConditionsCase.IT_COVERED_CONDITIONS) {
- lineBuilder.setItConditions(reportCoverage.getConditions());
- lineBuilder.setItCoveredConditions(reportCoverage.getItCoveredConditions());
+ lineBuilder.setUtCoveredConditions(reportCoverage.getCoveredConditions());
}
}
private static void processOverallTest(DbFileSources.Line.Builder lineBuilder, ScannerReport.LineCoverage reportCoverage) {
- if (reportCoverage.getHasUtHitsCase() == HasUtHitsCase.UT_HITS || reportCoverage.getHasItHitsCase() == HasItHitsCase.IT_HITS) {
- lineBuilder.setOverallLineHits((reportCoverage.getUtHits() || reportCoverage.getItHits()) ? 1 : 0);
+ if (reportCoverage.getHasHitsCase() == HasHitsCase.HITS) {
+ lineBuilder.setOverallLineHits(reportCoverage.getHits() ? 1 : 0);
}
- if (reportCoverage.getHasOverallCoveredConditionsCase() == HasOverallCoveredConditionsCase.OVERALL_COVERED_CONDITIONS) {
+ if (reportCoverage.getHasCoveredConditionsCase() == HasCoveredConditionsCase.COVERED_CONDITIONS) {
lineBuilder.setOverallConditions(reportCoverage.getConditions());
- lineBuilder.setOverallCoveredConditions(reportCoverage.getOverallCoveredConditions());
+ lineBuilder.setOverallCoveredConditions(reportCoverage.getCoveredConditions());
}
}
CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder()
.setLine(1)
.setConditions(10)
- .setUtHits(true)
- .setUtCoveredConditions(2)
- .setItHits(true)
- .setItCoveredConditions(3)
- .setOverallCoveredConditions(4)
+ .setHits(true)
+ .setCoveredConditions(2)
.build()).iterator());
DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1);
assertThat(lineBuilder.getUtLineHits()).isEqualTo(1);
assertThat(lineBuilder.getUtConditions()).isEqualTo(10);
- assertThat(lineBuilder.getItLineHits()).isEqualTo(1);
- assertThat(lineBuilder.getItConditions()).isEqualTo(10);
- assertThat(lineBuilder.getItCoveredConditions()).isEqualTo(3);
- assertThat(lineBuilder.getOverallLineHits()).isEqualTo(1);
- assertThat(lineBuilder.getOverallConditions()).isEqualTo(10);
}
// Some tools are only able to report condition coverage
CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder()
.setLine(1)
.setConditions(10)
- .setUtCoveredConditions(2)
- .setItCoveredConditions(3)
+ .setCoveredConditions(2)
.build()).iterator());
DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1);
assertThat(lineBuilder.hasUtLineHits()).isFalse();
assertThat(lineBuilder.getUtConditions()).isEqualTo(10);
assertThat(lineBuilder.hasItLineHits()).isFalse();
- assertThat(lineBuilder.getItConditions()).isEqualTo(10);
- assertThat(lineBuilder.getItCoveredConditions()).isEqualTo(3);
assertThat(lineBuilder.hasOverallLineHits()).isFalse();
- assertThat(lineBuilder.hasOverallConditions()).isFalse();
+ assertThat(lineBuilder.hasOverallConditions()).isTrue();
+ assertThat(lineBuilder.getOverallConditions()).isEqualTo(10);
}
@Test
CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder()
.setLine(1)
.setConditions(10)
- .setUtHits(true)
- .setUtCoveredConditions(2)
+ .setHits(true)
+ .setCoveredConditions(2)
.build()).iterator());
DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1);
assertThat(lineBuilder.getUtLineHits()).isEqualTo(1);
assertThat(lineBuilder.getUtConditions()).isEqualTo(10);
+ assertThat(lineBuilder.getUtCoveredConditions()).isEqualTo(2);
assertThat(lineBuilder.hasItLineHits()).isFalse();
assertThat(lineBuilder.hasItConditions()).isFalse();
assertThat(lineBuilder.hasItCoveredConditions()).isFalse();
assertThat(lineBuilder.getOverallLineHits()).isEqualTo(1);
- assertThat(lineBuilder.hasOverallCoveredConditions()).isFalse();
- }
-
- @Test
- public void set_coverage_only_it() {
- CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder()
- .setLine(1)
- .setConditions(10)
- .setItHits(true)
- .setItCoveredConditions(3)
- .build()).iterator());
-
- DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1);
- computeCoverageLine.read(lineBuilder);
-
- assertThat(lineBuilder.hasUtLineHits()).isFalse();
- assertThat(lineBuilder.hasUtConditions()).isFalse();
- assertThat(lineBuilder.getItLineHits()).isEqualTo(1);
- assertThat(lineBuilder.getItConditions()).isEqualTo(10);
- assertThat(lineBuilder.getItCoveredConditions()).isEqualTo(3);
- assertThat(lineBuilder.getOverallLineHits()).isEqualTo(1);
- assertThat(lineBuilder.hasOverallConditions()).isFalse();
+ assertThat(lineBuilder.hasOverallCoveredConditions()).isTrue();
+ assertThat(lineBuilder.getOverallCoveredConditions()).isEqualTo(2);
}
@Test
public void set_coverage_on_uncovered_lines() {
CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder()
.setLine(1)
- .setUtHits(false)
- .setItHits(false)
+ .setHits(false)
.build()).iterator());
DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1);
assertThat(lineBuilder.hasUtLineHits()).isTrue();
assertThat(lineBuilder.getUtLineHits()).isEqualTo(0);
- assertThat(lineBuilder.hasItLineHits()).isTrue();
- assertThat(lineBuilder.getItLineHits()).isEqualTo(0);
assertThat(lineBuilder.hasOverallLineHits()).isTrue();
assertThat(lineBuilder.getOverallLineHits()).isEqualTo(0);
}
public void set_overall_line_hits_with_only_ut() {
CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder()
.setLine(1)
- .setUtHits(true)
+ .setHits(true)
.build()).iterator());
DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1);
public void set_overall_line_hits_with_only_it() {
CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder()
.setLine(1)
- .setItHits(true)
+ .setHits(true)
.build()).iterator());
DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1);
public void set_overall_line_hits_with_ut_and_it() {
CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder()
.setLine(1)
- .setUtHits(true)
- .setItHits(true)
+ .setHits(true)
.build()).iterator());
DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1);
ScannerReport.LineCoverage.newBuilder()
.setLine(1)
.setConditions(10)
- .setUtHits(true)
- .setUtCoveredConditions(2)
- .setItHits(true)
- .setItCoveredConditions(3)
- .setOverallCoveredConditions(4)
+ .setHits(true)
+ .setCoveredConditions(2)
.build()
// No coverage info on line 2
).iterator());
ScannerReport.LineCoverage.newBuilder()
.setLine(1)
.setConditions(10)
- .setUtHits(true)
- .setUtCoveredConditions(2)
- .setItHits(true)
- .setItCoveredConditions(3)
- .setOverallCoveredConditions(4)
+ .setHits(true)
+ .setCoveredConditions(2)
.build()
// No coverage info on line 2
).iterator());
import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType;
import org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType;
import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderRule;
-import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
import org.sonar.server.computation.task.projectanalysis.component.Component;
import org.sonar.server.computation.task.projectanalysis.component.ReportComponent;
+import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
import org.sonar.server.computation.task.projectanalysis.duplication.Duplicate;
import org.sonar.server.computation.task.projectanalysis.duplication.Duplication;
import org.sonar.server.computation.task.projectanalysis.duplication.DuplicationRepositoryRule;
reportReader.putCoverage(FILE_REF, newArrayList(ScannerReport.LineCoverage.newBuilder()
.setLine(1)
.setConditions(10)
- .setUtHits(true)
- .setUtCoveredConditions(2)
- .setItHits(true)
- .setItCoveredConditions(3)
- .setOverallCoveredConditions(4)
+ .setHits(true)
+ .setCoveredConditions(2)
.build()));
underTest.execute();
assertThat(data.getLines(0).getUtLineHits()).isEqualTo(1);
assertThat(data.getLines(0).getUtConditions()).isEqualTo(10);
assertThat(data.getLines(0).getUtCoveredConditions()).isEqualTo(2);
- assertThat(data.getLines(0).hasItLineHits()).isTrue();
- assertThat(data.getLines(0).getItConditions()).isEqualTo(10);
- assertThat(data.getLines(0).getItCoveredConditions()).isEqualTo(3);
- assertThat(data.getLines(0).getOverallLineHits()).isEqualTo(1);
- assertThat(data.getLines(0).getOverallConditions()).isEqualTo(10);
- assertThat(data.getLines(0).getOverallCoveredConditions()).isEqualTo(4);
}
@Test
int lineCount = ((InputFile) resource.inputComponent()).lines();
applyLineMeasure(resource.key(), lineCount, CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY, coveragePerLine,
- new MeasureOperation() {
- @Override
- public void apply(String value, LineCoverage.Builder builder) {
- builder.setUtHits(Integer.parseInt(value) > 0);
- }
- });
- applyLineMeasure(resource.key(), lineCount, CoreMetrics.IT_COVERAGE_LINE_HITS_DATA_KEY, coveragePerLine,
- new MeasureOperation() {
- @Override
- public void apply(String value, LineCoverage.Builder builder) {
- builder.setItHits(Integer.parseInt(value) > 0);
- }
- });
- // Just in case we have only IT and no UT, we first take conditions from ITs, then from UTs (UTs will override ITs).
- // Note that it would be very strange (and unsupported in scanner report) to have ITs and UTs don't report the same number of
- // conditions. Not even talking about overall conditions...
- applyLineMeasure(resource.key(), lineCount, CoreMetrics.IT_CONDITIONS_BY_LINE_KEY, coveragePerLine,
- new MeasureOperation() {
- @Override
- public void apply(String value, LineCoverage.Builder builder) {
- builder.setConditions(Integer.parseInt(value));
- }
- });
+ (value, builder) -> builder.setHits(Integer.parseInt(value) > 0));
applyLineMeasure(resource.key(), lineCount, CoreMetrics.CONDITIONS_BY_LINE_KEY, coveragePerLine,
- new MeasureOperation() {
- @Override
- public void apply(String value, LineCoverage.Builder builder) {
- builder.setConditions(Integer.parseInt(value));
- }
- });
+ (value, builder) -> builder.setConditions(Integer.parseInt(value)));
applyLineMeasure(resource.key(), lineCount, CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY, coveragePerLine,
- new MeasureOperation() {
- @Override
- public void apply(String value, LineCoverage.Builder builder) {
- builder.setUtCoveredConditions(Integer.parseInt(value));
- }
- });
- applyLineMeasure(resource.key(), lineCount, CoreMetrics.IT_COVERED_CONDITIONS_BY_LINE_KEY, coveragePerLine,
- new MeasureOperation() {
- @Override
- public void apply(String value, LineCoverage.Builder builder) {
- builder.setItCoveredConditions(Integer.parseInt(value));
- }
- });
- applyLineMeasure(resource.key(), lineCount, CoreMetrics.OVERALL_COVERED_CONDITIONS_BY_LINE_KEY, coveragePerLine,
- new MeasureOperation() {
- @Override
- public void apply(String value, LineCoverage.Builder builder) {
- builder.setOverallCoveredConditions(Integer.parseInt(value));
- }
- });
+ (value, builder) -> builder.setCoveredConditions(Integer.parseInt(value)));
writer.writeComponentCoverage(resource.batchId(), Iterables.transform(coveragePerLine.values(), BuildCoverage.INSTANCE));
}
}
.start();
InputFile file = result.inputFile("src/sample.xoo");
- assertThat(result.coverageFor(file, 2).getUtHits()).isTrue();
- assertThat(result.coverageFor(file, 2).getItHits()).isFalse();
+ assertThat(result.coverageFor(file, 2).getHits()).isTrue();
assertThat(result.coverageFor(file, 2).getConditions()).isEqualTo(2);
- assertThat(result.coverageFor(file, 2).getUtCoveredConditions()).isEqualTo(1);
- assertThat(result.coverageFor(file, 2).getItCoveredConditions()).isEqualTo(0);
- assertThat(result.coverageFor(file, 2).getOverallCoveredConditions()).isEqualTo(0);
+ assertThat(result.coverageFor(file, 2).getCoveredConditions()).isEqualTo(1);
Map<String, List<org.sonar.scanner.protocol.output.ScannerReport.Measure>> allMeasures = result.allMeasures();
assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue.value")
.start();
InputFile file = result.inputFile("src/sample.xoo");
- assertThat(result.coverageFor(file, 2).getUtHits()).isTrue();
+ assertThat(result.coverageFor(file, 2).getHits()).isTrue();
assertThat(result.coverageFor(file, 2).getConditions()).isEqualTo(2);
- assertThat(result.coverageFor(file, 2).getUtCoveredConditions()).isEqualTo(2);
- assertThat(result.coverageFor(file, 3).getUtHits()).isTrue();
+ assertThat(result.coverageFor(file, 2).getCoveredConditions()).isEqualTo(2);
+ assertThat(result.coverageFor(file, 3).getHits()).isTrue();
Map<String, List<org.sonar.scanner.protocol.output.ScannerReport.Measure>> allMeasures = result.allMeasures();
assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue.value")
InputFile file = result.inputFile("src/sample.xoo");
assertThat(result.coverageFor(file, 1)).isNull();
- assertThat(result.coverageFor(file, 2).getUtHits()).isFalse();
- assertThat(result.coverageFor(file, 2).getItHits()).isFalse();
+ assertThat(result.coverageFor(file, 2).getHits()).isFalse();
assertThat(result.coverageFor(file, 2).getConditions()).isEqualTo(0);
- assertThat(result.coverageFor(file, 2).getUtCoveredConditions()).isEqualTo(0);
- assertThat(result.coverageFor(file, 2).getItCoveredConditions()).isEqualTo(0);
- assertThat(result.coverageFor(file, 2).getOverallCoveredConditions()).isEqualTo(0);
+ assertThat(result.coverageFor(file, 2).getCoveredConditions()).isEqualTo(0);
- assertThat(result.coverageFor(file, 3).getUtHits()).isFalse();
+ assertThat(result.coverageFor(file, 3).getHits()).isFalse();
assertThat(result.coverageFor(file, 4)).isNull();
Map<String, List<org.sonar.scanner.protocol.output.ScannerReport.Measure>> allMeasures = result.allMeasures();
try (CloseableIterator<LineCoverage> it = new ScannerReportReader(outputDir).readComponentCoverage(2)) {
assertThat(it.next()).isEqualTo(LineCoverage.newBuilder()
.setLine(2)
- .setUtHits(true)
+ .setHits(true)
.build());
assertThat(it.next()).isEqualTo(LineCoverage.newBuilder()
.setLine(3)
- .setUtHits(true)
+ .setHits(true)
.setConditions(4)
- .setUtCoveredConditions(2)
+ .setCoveredConditions(2)
.build());
assertThat(it.next()).isEqualTo(LineCoverage.newBuilder()
.setLine(5)
- .setUtHits(false)
+ .setHits(false)
.build());
}
// Number of conditions to cover (if set, the value must be greater than 0)
int32 conditions = 2;
// Is the line has been touched by a unit test ? Returning false means that no test has touched this executable line.
- oneof has_ut_hits {
- bool ut_hits = 3;
+ oneof has_hits {
+ bool hits = 3;
}
- // Is the line has been touched by a integration test ? Returning false means that no test has touched this executable line.
- oneof has_it_hits {
- bool it_hits = 4;
- }
- // Number of conditions covered by unit tests
- oneof has_ut_covered_conditions {
- int32 ut_covered_conditions = 5;
- }
- // Number of conditions covered by integration tests
- oneof has_it_covered_conditions {
- int32 it_covered_conditions = 6;
- }
- // Number of conditions covered by overall tests
- oneof has_overall_covered_conditions {
- int32 overall_covered_conditions = 7;
+ // Number of conditions covered by tests
+ oneof has_covered_conditions {
+ int32 covered_conditions = 5;
}
}
ScannerReport.LineCoverage.newBuilder()
.setLine(1)
.setConditions(1)
- .setUtHits(true)
- .setItHits(false)
- .setUtCoveredConditions(1)
- .setItCoveredConditions(1)
- .setOverallCoveredConditions(1)
+ .setHits(true)
+ .setCoveredConditions(1)
.build(),
ScannerReport.LineCoverage.newBuilder()
.setLine(2)
.setConditions(5)
- .setUtHits(false)
- .setItHits(false)
- .setUtCoveredConditions(4)
- .setItCoveredConditions(5)
- .setOverallCoveredConditions(5)
+ .setHits(false)
+ .setCoveredConditions(4)
.build()));
underTest = new ScannerReportReader(dir);
ScannerReport.LineCoverage coverage = it.next();
assertThat(coverage.getLine()).isEqualTo(1);
assertThat(coverage.getConditions()).isEqualTo(1);
- assertThat(coverage.getUtHits()).isTrue();
- assertThat(coverage.getItHits()).isFalse();
- assertThat(coverage.getUtCoveredConditions()).isEqualTo(1);
- assertThat(coverage.getItCoveredConditions()).isEqualTo(1);
- assertThat(coverage.getOverallCoveredConditions()).isEqualTo(1);
+ assertThat(coverage.getHits()).isTrue();
+ assertThat(coverage.getCoveredConditions()).isEqualTo(1);
}
}
ScannerReport.LineCoverage.newBuilder()
.setLine(1)
.setConditions(1)
- .setUtHits(true)
- .setItHits(false)
- .setUtCoveredConditions(1)
- .setItCoveredConditions(1)
- .setOverallCoveredConditions(1)
+ .setHits(true)
+ .setCoveredConditions(1)
.build()));
assertThat(underTest.hasComponentData(FileStructure.Domain.COVERAGES, 1)).isTrue();