diff --git a/.gitignore b/.gitignore
index 0adb93e6a..cdfca4bd3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,3 +24,8 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
+
+.idea/
+
+*.iml
+target/
diff --git a/azure-pipelines.Gradle.yml b/azure-pipelines.Gradle.yml
index ee7ed4ad8..beaaf09de 100644
--- a/azure-pipelines.Gradle.yml
+++ b/azure-pipelines.Gradle.yml
@@ -19,6 +19,14 @@ steps:
testResultsFiles: '**/TEST-*.xml'
tasks: 'build'
+# Publish Cobertura or JaCoCo code coverage results from a build
+- task: PublishCodeCoverageResults@1
+ inputs:
+ codeCoverageTool: 'JaCoCo'
+ summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/reports/code-cov-report.xml'
+ reportDirectory: '$(System.DefaultWorkingDirectory)/**/reports/code-cov-report.html'
+ failIfCoverageEmpty: true
+
- task: CopyFiles@2
inputs:
contents: '**/helloworld*.jar'
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index f56977e54..8cf79b32b 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -18,6 +18,14 @@ steps:
testResultsFiles: '**/TEST-*.xml'
goals: 'package'
+# Publish Cobertura or JaCoCo code coverage results from a build
+- task: PublishCodeCoverageResults@1
+ inputs:
+ codeCoverageTool: 'JaCoCo'
+ summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/site/jacoco/jacoco.xml'
+ reportDirectory: '$(System.DefaultWorkingDirectory)/**/site/jacoco'
+ failIfCoverageEmpty: true
+
- task: CopyFiles@2
inputs:
contents: '**/*.war'
diff --git a/build.gradle b/build.gradle
index b34729bfd..8c0476fe2 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,5 +1,6 @@
apply plugin: 'java'
apply plugin: 'maven'
+apply plugin: 'jacoco'
group = 'helloworld'
version = '1.0-SNAPSHOT'
@@ -16,3 +17,14 @@ repositories {
dependencies {
testCompile group: 'junit', name: 'junit', version:'4.11'
}
+
+jacocoTestReport {
+ reports {
+ xml.enabled true
+ xml.destination "${buildDir}/reports/code-cov-report.xml"
+ html.enabled true
+ html.destination "${buildDir}/reports/code-cov-report.html"
+ }
+}
+
+check.dependsOn jacocoTestReport
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 0aa66b65c..310949ae8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,6 +19,47 @@
helloworld
+
+
+
+ org.jacoco
+ jacoco-maven-plugin
+ 0.8.2
+
+
+ prepare-agent
+
+ prepare-agent
+
+
+
+ report
+ prepare-package
+
+ report
+
+
+
+ post-unit-test
+ test
+
+ report
+
+
+
+ target/jacoco.exec
+
+ target/jacoco-ut
+
+
+
+
+
+ target/jacoco.exec
+
+
+
+
diff --git a/src/main/java/com/microsoft/demo/Demo.java b/src/main/java/com/microsoft/demo/Demo.java
new file mode 100644
index 000000000..3ab319fe3
--- /dev/null
+++ b/src/main/java/com/microsoft/demo/Demo.java
@@ -0,0 +1,12 @@
+package com.microsoft.demo;
+
+public class Demo {
+ public void DoSomething(boolean flag){
+ if(flag){
+ System.out.println("I am covered");
+ return;
+ }
+
+ System.out.println("I am not covered");
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/MyTest.java b/src/test/java/MyTest.java
index 62ee40e00..9e1d2abed 100644
--- a/src/test/java/MyTest.java
+++ b/src/test/java/MyTest.java
@@ -1,8 +1,11 @@
-import org.junit.*;
+import com.microsoft.demo.Demo;
+import org.junit.Test;
public class MyTest {
@Test
public void test_method_1() {
+ Demo d = new Demo();
+ d.DoSomething(true);
}
@Test