use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.
the class GenericTestExecutionMediumTest method twoReports.
@Test
public void twoReports() throws IOException {
File projectDir = new File("src/test/resources/mediumtest/xoo/sample-generic-test-exec");
TaskResult result = tester.newScanTask(new File(projectDir, "sonar-project.properties")).property("sonar.testExecutionReportPaths", "unittest.xml,unittest2.xml").start();
InputFile testFile = result.inputFile("testx/ClassOneTest.xoo");
ScannerReport.Test success = result.firstTestExecutionForName(testFile, "test1");
assertThat(success.getDurationInMs()).isEqualTo(5);
assertThat(success.getStatus()).isEqualTo(TestStatus.OK);
ScannerReport.Test success2 = result.firstTestExecutionForName(testFile, "test1b");
assertThat(success2.getDurationInMs()).isEqualTo(5);
assertThat(success2.getStatus()).isEqualTo(TestStatus.OK);
ScannerReport.Test skipped = result.firstTestExecutionForName(testFile, "test2");
assertThat(skipped.getDurationInMs()).isEqualTo(500);
assertThat(skipped.getStatus()).isEqualTo(TestStatus.SKIPPED);
assertThat(skipped.getMsg()).isEqualTo("short message");
assertThat(skipped.getStacktrace()).isEqualTo("other");
ScannerReport.Test failed = result.firstTestExecutionForName(testFile, "test3");
assertThat(failed.getDurationInMs()).isEqualTo(100);
assertThat(failed.getStatus()).isEqualTo(TestStatus.FAILURE);
assertThat(failed.getMsg()).isEqualTo("short");
assertThat(failed.getStacktrace()).isEqualTo("stacktrace");
ScannerReport.Test error = result.firstTestExecutionForName(testFile, "test4");
assertThat(error.getDurationInMs()).isEqualTo(500);
assertThat(error.getStatus()).isEqualTo(TestStatus.ERROR);
assertThat(error.getMsg()).isEqualTo("short");
assertThat(error.getStacktrace()).isEqualTo("stacktrace");
assertThat(result.allMeasures().get(testFile.key())).extracting("metricKey", "intValue.value", "longValue.value").containsOnly(tuple(CoreMetrics.TESTS_KEY, 4, 0L), tuple(CoreMetrics.SKIPPED_TESTS_KEY, 2, 0L), tuple(CoreMetrics.TEST_ERRORS_KEY, 1, 0L), tuple(CoreMetrics.TEST_EXECUTION_TIME_KEY, 0, 1610L), tuple(CoreMetrics.TEST_FAILURES_KEY, 1, 0L));
}
use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.
the class MeasuresMediumTest method lineMeasures.
@Test
public void lineMeasures() throws IOException {
File xooFile = new File(srcDir, "sample.xoo");
FileUtils.write(xooFile, "Sample xoo\n\n\ncontent");
File lineMeasures = new File(srcDir, "sample.xoo.linemeasures");
FileUtils.write(lineMeasures, "ncloc_data:1=1;2=0;4=1");
TaskResult result = tester.newTask().properties(ImmutableMap.<String, String>builder().put("sonar.task", "scan").put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.projectName", "Foo Project").put("sonar.projectVersion", "1.0-SNAPSHOT").put("sonar.projectDescription", "Description of Foo Project").put("sonar.sources", "src").build()).start();
Map<String, List<Measure>> allMeasures = result.allMeasures();
assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue.value", "stringValue.value").containsExactly(tuple("ncloc_data", 0, "1=1;4=1"));
}
use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.
the class MeasuresMediumTest method applyExclusionsOnCoverageMeasures.
@Test
public void applyExclusionsOnCoverageMeasures() throws IOException {
File xooFile = new File(srcDir, "sample.xoo");
FileUtils.write(xooFile, "Sample xoo\n\ncontent");
File measures = new File(srcDir, "sample.xoo.measures");
FileUtils.write(measures, "lines_to_cover:2");
TaskResult result = tester.newTask().properties(ImmutableMap.<String, String>builder().put("sonar.task", "scan").put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.projectName", "Foo Project").put("sonar.projectVersion", "1.0-SNAPSHOT").put("sonar.projectDescription", "Description of Foo Project").put("sonar.sources", "src").build()).start();
Map<String, List<Measure>> allMeasures = result.allMeasures();
assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue.value").containsOnly(tuple("lines_to_cover", 2));
result = tester.newTask().properties(ImmutableMap.<String, String>builder().put("sonar.task", "scan").put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.projectName", "Foo Project").put("sonar.projectVersion", "1.0-SNAPSHOT").put("sonar.projectDescription", "Description of Foo Project").put("sonar.sources", "src").put("sonar.coverage.exclusions", "src/sample.xoo").build()).start();
allMeasures = result.allMeasures();
assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue.value").isEmpty();
}
use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.
the class MeasuresMediumTest method projectLevelMeasures.
@Test
public void projectLevelMeasures() throws IOException {
File xooFile = new File(srcDir, "sample.xoo");
FileUtils.write(xooFile, "Sample xoo\n\n\ncontent");
File projectMeasures = new File(baseDir, "module.measures");
FileUtils.write(projectMeasures, "tests:10");
TaskResult result = tester.newTask().properties(ImmutableMap.<String, String>builder().put("sonar.task", "scan").put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.projectName", "Foo Project").put("sonar.projectVersion", "1.0-SNAPSHOT").put("sonar.projectDescription", "Description of Foo Project").put("sonar.sources", "src").build()).start();
Map<String, List<Measure>> allMeasures = result.allMeasures();
assertThat(allMeasures.get("com.foo.project")).extracting("metricKey", "intValue.value", "stringValue.value").containsExactly(tuple("tests", 10, ""));
}
use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.
the class IssueModeAndReportsMediumTest method testIssueCallback.
@Test
public void testIssueCallback() throws Exception {
File projectDir = copyProject("/mediumtest/xoo/sample");
IssueRecorder issueListener = new IssueRecorder();
TaskResult result = tester.newScanTask(new File(projectDir, "sonar-project.properties")).setIssueListener(issueListener).property("sonar.verbose", "true").start();
assertThat(result.trackedIssues()).hasSize(19);
assertThat(issueListener.issueList).hasSize(19);
}
Aggregations