Search in sources :

Example 56 with TaskResult

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));
}
Also used : ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) TaskResult(org.sonar.scanner.mediumtest.TaskResult) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 57 with TaskResult

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"));
}
Also used : TaskResult(org.sonar.scanner.mediumtest.TaskResult) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 58 with TaskResult

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();
}
Also used : TaskResult(org.sonar.scanner.mediumtest.TaskResult) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 59 with TaskResult

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, ""));
}
Also used : TaskResult(org.sonar.scanner.mediumtest.TaskResult) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 60 with TaskResult

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);
}
Also used : TaskResult(org.sonar.scanner.mediumtest.TaskResult) File(java.io.File) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)61 TaskResult (org.sonar.scanner.mediumtest.TaskResult)61 File (java.io.File)59 InputFile (org.sonar.api.batch.fs.InputFile)31 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)21 List (java.util.List)8 Issue (org.sonar.scanner.protocol.output.ScannerReport.Issue)7 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)6 Path (java.nio.file.Path)3 InputDir (org.sonar.api.batch.fs.InputDir)3 ScannerMediumTester (org.sonar.scanner.mediumtest.ScannerMediumTester)3 XooPlugin (org.sonar.xoo.XooPlugin)3 XooRulesDefinition (org.sonar.xoo.rule.XooRulesDefinition)3 TrackedIssue (org.sonar.scanner.issue.tracking.TrackedIssue)2 Date (java.util.Date)1 LogOutputRecorder (org.sonar.scanner.mediumtest.LogOutputRecorder)1