Skip to content

Commit

Permalink
Setup code coverage #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Alin Turcu committed Dec 16, 2017
1 parent 87fe972 commit 1b1d961
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -32,7 +32,8 @@ cache:

script:
- ./gradlew clean build
- ./gradlew jacocoTestReport

after_success:
# - ./gradlew jacocoTestReport coveralls
- bash <(curl -s https://codecov.io/bash)
- .buildscript/deploy_snapshot.sh
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -13,6 +13,11 @@ Grox helps to maintain the state of Java / Android apps.
<a alt="Maven Central" href="http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22grox-core%22">
<img src="https://img.shields.io/maven-central/v/com.groupon.grox/grox-core.svg?maxAge=2592000"/></a>
<br/>
<br/>
<a href="https://codecov.io/gh/groupon/grox">
<img src="https://codecov.io/gh/groupon/grox/branch/master/graph/badge.svg" />
</a>
<br/>
<a alt="Android Dev Weekly" href="http://androidweekly.net/issues/issue-282">
<img src="https://img.shields.io/badge/Android%20Weekly-%23207-brightgreen.svg"/></a>
<br/>
Expand Down
39 changes: 39 additions & 0 deletions build.gradle
Expand Up @@ -41,6 +41,7 @@ allprojects {
// plugin for all (checkstyle, pmd and findbugs)
quality_gradle_java_file = "config/quality_java.gradle"
quality_gradle_android_file = "config/quality_android.gradle"
jacoco_gradle_java_file = "config/jacoco_java.gradle"

// config files
pmd_rulesetFile = "${project.rootDir}/config/pmd/pmd-ruleset.xml"
Expand All @@ -53,6 +54,44 @@ subprojects { project ->
version = VERSION_NAME
}

apply plugin: 'jacoco'

//https://gist.github.com/aalmiray/e6f54aa4b3803be0bcac
task jacocoTestReport(type: JacocoReport) {
sourceDirectories = files()
classDirectories = files()
executionData = files()

reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
}

// Work-around to allow us to build list of executionData files in doFirst
onlyIf = {
true
}

/*
* Builds list of source dirs, class dirs, and executionData files
* when task is run, not at script evaluation time
*/
doFirst {
subprojects.findAll { subproject ->
subproject.pluginManager.hasPlugin('jacoco')
}.each { subproject ->
additionalSourceDirs files((Set<File>) subproject.sourceSets.main.allJava.srcDirs)
additionalClassDirs((FileCollection) subproject.sourceSets.main.output)
executionData subproject.tasks.jacocoTestReport.executionData
}

executionData = files(executionData.findAll {
it.exists()
})
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
Expand Down
13 changes: 13 additions & 0 deletions config/jacoco_java.gradle
@@ -0,0 +1,13 @@
apply plugin: 'jacoco'

jacocoTestReport {
dependsOn tasks.test

reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
}
}

rootProject.tasks.jacocoTestReport.dependsOn tasks.test
2 changes: 2 additions & 0 deletions grox-commands-rx2/build.gradle
Expand Up @@ -23,3 +23,5 @@ license {
java = 'SLASHSTAR_STYLE'
}
}

apply from: rootProject.file("${jacoco_gradle_java_file}")
11 changes: 11 additions & 0 deletions grox-core-rx/src/test/java/com/groupon/grox/RxStoresTest.java
Expand Up @@ -26,6 +26,7 @@
import org.junit.Test;
import rx.Subscription;
import rx.observers.TestSubscriber;
import static org.junit.Assert.fail;

public class RxStoresTest {

Expand Down Expand Up @@ -91,4 +92,14 @@ public void states_should_unsubscribeListener() {
//THEN
verify(mockStore);
}

@Test(expected = IllegalArgumentException.class)
public void states_should_throw_when_storeIsNull() {

//WHEN
states(null);

//THEN
fail("Should have thrown an exception");
}
}
2 changes: 2 additions & 0 deletions grox-core-rx2/build.gradle
Expand Up @@ -23,3 +23,5 @@ license {
java = 'SLASHSTAR_STYLE'
}
}

apply from: rootProject.file("${jacoco_gradle_java_file}")
11 changes: 11 additions & 0 deletions grox-core-rx2/src/test/java/com/groupon/grox/RxStoresTest.java
Expand Up @@ -26,6 +26,7 @@
import static org.easymock.EasyMock.verify;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

public class RxStoresTest {

Expand Down Expand Up @@ -91,4 +92,14 @@ public void states_should_unsubscribeListener() {
//THEN
verify(mockStore);
}

@Test(expected = IllegalArgumentException.class)
public void states_should_throw_when_storeIsNull() {

//WHEN
states(null);

//THEN
fail("Should have thrown an exception");
}
}
2 changes: 2 additions & 0 deletions grox-core/build.gradle
Expand Up @@ -21,3 +21,5 @@ license {
java = 'SLASHSTAR_STYLE'
}
}

apply from: rootProject.file("${jacoco_gradle_java_file}")

0 comments on commit 1b1d961

Please sign in to comment.