]> source.dussan.org Git - sonarqube.git/commitdiff
Add ITs on new coverage measures
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 21 Jul 2015 11:43:24 +0000 (13:43 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 21 Jul 2015 11:43:44 +0000 (13:43 +0200)
15 files changed:
it/it-projects/testing/xoo-sample-new-coverage-v1/sonar-project.properties [new file with mode: 0644]
it/it-projects/testing/xoo-sample-new-coverage-v1/src/main/xoo/sample/Sample.xoo [new file with mode: 0644]
it/it-projects/testing/xoo-sample-new-coverage-v1/src/main/xoo/sample/Sample.xoo.coverage [new file with mode: 0644]
it/it-projects/testing/xoo-sample-new-coverage-v1/src/main/xoo/sample/Sample.xoo.itcoverage [new file with mode: 0644]
it/it-projects/testing/xoo-sample-new-coverage-v1/src/main/xoo/sample/Sample.xoo.measures [new file with mode: 0644]
it/it-projects/testing/xoo-sample-new-coverage-v1/src/main/xoo/sample/Sample.xoo.overallcoverage [new file with mode: 0644]
it/it-projects/testing/xoo-sample-new-coverage-v1/src/main/xoo/sample/Sample.xoo.scm [new file with mode: 0644]
it/it-projects/testing/xoo-sample-new-coverage-v2/sonar-project.properties [new file with mode: 0644]
it/it-projects/testing/xoo-sample-new-coverage-v2/src/main/xoo/sample/Sample.xoo [new file with mode: 0644]
it/it-projects/testing/xoo-sample-new-coverage-v2/src/main/xoo/sample/Sample.xoo.coverage [new file with mode: 0644]
it/it-projects/testing/xoo-sample-new-coverage-v2/src/main/xoo/sample/Sample.xoo.itcoverage [new file with mode: 0644]
it/it-projects/testing/xoo-sample-new-coverage-v2/src/main/xoo/sample/Sample.xoo.measures [new file with mode: 0644]
it/it-projects/testing/xoo-sample-new-coverage-v2/src/main/xoo/sample/Sample.xoo.overallcoverage [new file with mode: 0644]
it/it-projects/testing/xoo-sample-new-coverage-v2/src/main/xoo/sample/Sample.xoo.scm [new file with mode: 0644]
it/it-tests/src/test/java/testing/suite/NewCoverageTest.java [new file with mode: 0644]

diff --git a/it/it-projects/testing/xoo-sample-new-coverage-v1/sonar-project.properties b/it/it-projects/testing/xoo-sample-new-coverage-v1/sonar-project.properties
new file mode 100644 (file)
index 0000000..a711b2b
--- /dev/null
@@ -0,0 +1,6 @@
+sonar.projectKey=sample-new-coverage
+sonar.projectName=Sample new Coverage
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.sources=src/main/xoo
+sonar.language=xoo
+sonar.scm.provider=xoo
diff --git a/it/it-projects/testing/xoo-sample-new-coverage-v1/src/main/xoo/sample/Sample.xoo b/it/it-projects/testing/xoo-sample-new-coverage-v1/src/main/xoo/sample/Sample.xoo
new file mode 100644 (file)
index 0000000..41871e1
--- /dev/null
@@ -0,0 +1,16 @@
+package sample;
+
+public class Sample {
+       
+       public Sample(int i) {
+               int j = i++;
+       }
+       
+       private String myMethod() {
+               if (foo == bar) {
+                       return "hello";
+               } else {
+                       throw new IllegalStateException();
+               }
+       }
+}
diff --git a/it/it-projects/testing/xoo-sample-new-coverage-v1/src/main/xoo/sample/Sample.xoo.coverage b/it/it-projects/testing/xoo-sample-new-coverage-v1/src/main/xoo/sample/Sample.xoo.coverage
new file mode 100644 (file)
index 0000000..a2d656d
--- /dev/null
@@ -0,0 +1 @@
+6:2:3:3
diff --git a/it/it-projects/testing/xoo-sample-new-coverage-v1/src/main/xoo/sample/Sample.xoo.itcoverage b/it/it-projects/testing/xoo-sample-new-coverage-v1/src/main/xoo/sample/Sample.xoo.itcoverage
new file mode 100644 (file)
index 0000000..a2d656d
--- /dev/null
@@ -0,0 +1 @@
+6:2:3:3
diff --git a/it/it-projects/testing/xoo-sample-new-coverage-v1/src/main/xoo/sample/Sample.xoo.measures b/it/it-projects/testing/xoo-sample-new-coverage-v1/src/main/xoo/sample/Sample.xoo.measures
new file mode 100644 (file)
index 0000000..18b6b8e
--- /dev/null
@@ -0,0 +1,2 @@
+ncloc:17
+
diff --git a/it/it-projects/testing/xoo-sample-new-coverage-v1/src/main/xoo/sample/Sample.xoo.overallcoverage b/it/it-projects/testing/xoo-sample-new-coverage-v1/src/main/xoo/sample/Sample.xoo.overallcoverage
new file mode 100644 (file)
index 0000000..a2d656d
--- /dev/null
@@ -0,0 +1 @@
+6:2:3:3
diff --git a/it/it-projects/testing/xoo-sample-new-coverage-v1/src/main/xoo/sample/Sample.xoo.scm b/it/it-projects/testing/xoo-sample-new-coverage-v1/src/main/xoo/sample/Sample.xoo.scm
new file mode 100644 (file)
index 0000000..e047ea4
--- /dev/null
@@ -0,0 +1,17 @@
+1,user1,2015-01-04
+1,user1,2015-01-04
+1,user1,2015-01-04
+1,user1,2015-01-04
+2,user2,2015-01-05
+2,user2,2015-01-05
+3,user3,2015-01-06
+4,user4,2015-01-07
+4,user4,2015-01-07
+4,user4,2015-01-07
+4,user4,2015-01-07
+4,user4,2015-01-07
+4,user4,2015-01-07
+4,user4,2015-01-07
+4,user4,2015-01-07
+4,user4,2015-01-07
+4,user4,2015-01-07
diff --git a/it/it-projects/testing/xoo-sample-new-coverage-v2/sonar-project.properties b/it/it-projects/testing/xoo-sample-new-coverage-v2/sonar-project.properties
new file mode 100644 (file)
index 0000000..a711b2b
--- /dev/null
@@ -0,0 +1,6 @@
+sonar.projectKey=sample-new-coverage
+sonar.projectName=Sample new Coverage
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.sources=src/main/xoo
+sonar.language=xoo
+sonar.scm.provider=xoo
diff --git a/it/it-projects/testing/xoo-sample-new-coverage-v2/src/main/xoo/sample/Sample.xoo b/it/it-projects/testing/xoo-sample-new-coverage-v2/src/main/xoo/sample/Sample.xoo
new file mode 100644 (file)
index 0000000..41871e1
--- /dev/null
@@ -0,0 +1,16 @@
+package sample;
+
+public class Sample {
+       
+       public Sample(int i) {
+               int j = i++;
+       }
+       
+       private String myMethod() {
+               if (foo == bar) {
+                       return "hello";
+               } else {
+                       throw new IllegalStateException();
+               }
+       }
+}
diff --git a/it/it-projects/testing/xoo-sample-new-coverage-v2/src/main/xoo/sample/Sample.xoo.coverage b/it/it-projects/testing/xoo-sample-new-coverage-v2/src/main/xoo/sample/Sample.xoo.coverage
new file mode 100644 (file)
index 0000000..cd6fabd
--- /dev/null
@@ -0,0 +1,6 @@
+6:0:3:1
+7:1:3:1
+8:0
+9:1
+10:1
+11:1
diff --git a/it/it-projects/testing/xoo-sample-new-coverage-v2/src/main/xoo/sample/Sample.xoo.itcoverage b/it/it-projects/testing/xoo-sample-new-coverage-v2/src/main/xoo/sample/Sample.xoo.itcoverage
new file mode 100644 (file)
index 0000000..77bdb58
--- /dev/null
@@ -0,0 +1,5 @@
+6:0:3:1
+7:1:3:2
+8:1
+9:1
+10:1
diff --git a/it/it-projects/testing/xoo-sample-new-coverage-v2/src/main/xoo/sample/Sample.xoo.measures b/it/it-projects/testing/xoo-sample-new-coverage-v2/src/main/xoo/sample/Sample.xoo.measures
new file mode 100644 (file)
index 0000000..e4f33ed
--- /dev/null
@@ -0,0 +1 @@
+ncloc:17
diff --git a/it/it-projects/testing/xoo-sample-new-coverage-v2/src/main/xoo/sample/Sample.xoo.overallcoverage b/it/it-projects/testing/xoo-sample-new-coverage-v2/src/main/xoo/sample/Sample.xoo.overallcoverage
new file mode 100644 (file)
index 0000000..ab5d844
--- /dev/null
@@ -0,0 +1,3 @@
+6:0:3:1
+7:1:3:2
+8:0:4:1
diff --git a/it/it-projects/testing/xoo-sample-new-coverage-v2/src/main/xoo/sample/Sample.xoo.scm b/it/it-projects/testing/xoo-sample-new-coverage-v2/src/main/xoo/sample/Sample.xoo.scm
new file mode 100644 (file)
index 0000000..06d9b20
--- /dev/null
@@ -0,0 +1,17 @@
+1,user1,2015-01-04
+1,user1,2015-01-04
+1,user1,2015-01-04
+1,user1,2015-01-04
+2,user2,2015-01-05
+2,user2,2015-01-05
+3,user3,2015-06-06
+4,user4,2015-06-07
+4,user4,2015-06-07
+4,user4,2015-06-07
+4,user4,2015-06-07
+4,user4,2015-01-07
+4,user4,2015-01-07
+4,user4,2015-01-07
+4,user4,2015-01-07
+4,user4,2015-01-07
+4,user4,2015-01-07
diff --git a/it/it-tests/src/test/java/testing/suite/NewCoverageTest.java b/it/it-tests/src/test/java/testing/suite/NewCoverageTest.java
new file mode 100644 (file)
index 0000000..29e7848
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package testing.suite;
+
+import com.sonar.orchestrator.Orchestrator;
+import com.sonar.orchestrator.build.SonarRunner;
+import java.util.List;
+import org.assertj.core.data.Offset;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonar.wsclient.services.Measure;
+import org.sonar.wsclient.services.Resource;
+import org.sonar.wsclient.services.ResourceQuery;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static util.ItUtils.projectDir;
+
+public class NewCoverageTest {
+
+  @ClassRule
+  public static Orchestrator orchestrator = TestingTestSuite.ORCHESTRATOR;
+
+  private static final String PROJECT_KEY = "sample-new-coverage";
+
+  private static final Offset<Double> DEFAULT_OFFSET = Offset.offset(0.1d);
+
+  private static final String[] ALL_NEW_COVERAGE_METRICS = new String[] {
+    "new_coverage", "new_line_coverage", "new_branch_coverage",
+    "new_it_coverage", "new_it_line_coverage", "new_it_branch_coverage",
+    "new_overall_coverage", "new_overall_line_coverage", "new_overall_branch_coverage"
+  };
+
+  @BeforeClass
+  public static void analyze_project() {
+    orchestrator.resetData();
+
+    orchestrator.executeBuilds(SonarRunner.create(projectDir("testing/xoo-sample-new-coverage-v1"))
+        .setProperty("sonar.projectDate", "2015-02-01")
+        .setProperty("sonar.scm.disabled", "false")
+    );
+    orchestrator.executeBuilds(SonarRunner.create(projectDir("testing/xoo-sample-new-coverage-v2"))
+      .setProperty("sonar.scm.disabled", "false"));
+  }
+
+  @Test
+  public void new_unit_test_coverage() throws Exception {
+    Resource project = orchestrator.getServer().getWsClient().find(ResourceQuery.createForMetrics(PROJECT_KEY, ALL_NEW_COVERAGE_METRICS).setIncludeTrends(true));
+    assertThat(project.getMeasure("new_coverage").getVariation1()).isEqualTo(62.5d, DEFAULT_OFFSET);
+    assertThat(project.getMeasure("new_line_coverage").getVariation1()).isEqualTo(80d, DEFAULT_OFFSET);
+    assertThat(project.getMeasure("new_branch_coverage").getVariation1()).isEqualTo(33.3, DEFAULT_OFFSET);
+  }
+
+  @Test
+  public void new_integration_test_coverage() throws Exception {
+    Resource project = orchestrator.getServer().getWsClient().find(ResourceQuery.createForMetrics(PROJECT_KEY, ALL_NEW_COVERAGE_METRICS).setIncludeTrends(true));
+    assertThat(project.getMeasure("new_it_coverage").getVariation1()).isEqualTo(85.7, DEFAULT_OFFSET);
+    assertThat(project.getMeasure("new_it_line_coverage").getVariation1()).isEqualTo(100d, DEFAULT_OFFSET);
+    assertThat(project.getMeasure("new_it_branch_coverage").getVariation1()).isEqualTo(66.7, DEFAULT_OFFSET);
+  }
+
+  @Test
+  public void new_overall_coverage() throws Exception {
+    Resource project = orchestrator.getServer().getWsClient().find(ResourceQuery.createForMetrics(PROJECT_KEY, ALL_NEW_COVERAGE_METRICS).setIncludeTrends(true));
+    assertThat(project.getMeasure("new_overall_coverage").getVariation1()).isEqualTo(44.4d, DEFAULT_OFFSET);
+    assertThat(project.getMeasure("new_overall_line_coverage").getVariation1()).isEqualTo(50d, DEFAULT_OFFSET);
+    assertThat(project.getMeasure("new_overall_branch_coverage").getVariation1()).isEqualTo(42.85, DEFAULT_OFFSET);
+  }
+
+}