Skip to content

Commit dd099b8

Browse files
authored
Integration test + some other minor improvements. (#1)
* Added a proper integration test to the plugin that tests the plugin on a project with three module types: `android-library`, `android-application` and `java-library`. * New configuration option: `testTypes` * Updated README.md * improved warning and error messages * Updated version to 1.0.0.
1 parent 81ba4a2 commit dd099b8

File tree

71 files changed

+534
-471
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+534
-471
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
*.iml
22
.gradle
3-
/local.properties
3+
local.properties
44
/.idea/caches/build_file_checksums.ser
55
/.idea/libraries
66
/.idea/modules.xml
@@ -12,3 +12,4 @@
1212
.idea/
1313
*.exec
1414
repo/
15+
build/

README.md

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
# Android-Root-Coverage-Plugin
2-
**A Gradle plugin for easy generation of combined code coverage reports for Android projects with multiple modules.**
3-
Generating code coverage reports for Android Projects that make use of the Gradle build is quite easy. Unfortunately by default code coverage is generated separately per module, this means each modules takes into account it's own sources and tests, which is in terms of domain separation fine. However it is very common to find multi-module Android project where only one module has instrumented tests, or full-fledged UI tests using Espresso. This plugin comes in handy for those projects. It generates code coverage reports using Jacoco taking into account all the modules and tests at once.
2+
**A Gradle plugin for combined code coverage reports for Android projects.**
3+
Generating code coverage reports for Android Projects is in most cases quite easy. Unfortunately by
4+
default (using Jacoco) code coverage is generated separately per module. This means each module
5+
takes into account it's own sources and tests (which is in terms of domain separation fine). However
6+
it is very common to find multi-module Android projects where only one module actually has tests.
7+
This plugin comes in handy for those projects. It generates code coverage reports using Jacoco
8+
taking into account all the modules and tests at once, or in other words: code in module B will show
9+
up as "covered" when tests in Module A touch it.
410

511
- Supports both Android app and library modules (`com.android.application` & `com.android.library`).
612
- Supports different build variants per module within the same report.
7-
- Supports custom filters.
13+
- Supports custom package/class filters.
14+
815

916
# Setup
10-
Apply the Android-Root-Coverage-Plugin plugin to your top-level (root project) gradle file following these 2 steps:
17+
Apply the Android-Root-Coverage-Plugin plugin to your top-level (root project) gradle file:
1118

1219
```groovy
1320
// Step 2: Apply the plugin to the top-level gradle file
@@ -16,13 +23,16 @@ apply plugin: 'org.neotech.plugin.rootcoverage'
1623
buildscript {
1724
dependencies {
1825
// Step 1: add the dependency
19-
classpath 'org.neotech.plugin:android-root-coverage-plugin:0.0.1-dev'
26+
classpath 'org.neotech.plugin:android-root-coverage-plugin:1.0.0'
2027
}
2128
}
2229
```
2330

31+
2432
# How to use
25-
Currently only modules with the plugin type `com.android.application` or `com.android.library` are taken into account when generating the root code coverage report, besides this any module that does not have `testCoverageEnabled true` for the default build variant (`debug`) will be skipped::
33+
Currently only modules with the plugin type `com.android.application` or `com.android.library` are
34+
taken into account when generating the coverage report, besides this any module that does not have
35+
`testCoverageEnabled true` for the selected build variant (by default: `debug`) will be skipped:
2636

2737
You can add a module by enabling `testCoverageEnabled`:
2838
```groovy
@@ -35,35 +45,55 @@ android {
3545
}
3646
```
3747

38-
The Android-Root-Coverage-Plugin generates a special Gradle task `:rootCodeCoverageReport` that when executed generates a Jacoco code coverage report. You can either run this task directly from Android Studio using the Gradle Tool Window (see: https://www.jetbrains.com/help/idea/jetgradle-tool-window.html) or from the terminal.
48+
The Android-Root-Coverage-Plugin generates a special Gradle task `:rootCodeCoverageReport` that when
49+
executed generates a Jacoco code coverage report. You can either run this task directly from
50+
Android Studio using the Gradle Tool Window (see:
51+
https://www.jetbrains.com/help/idea/jetgradle-tool-window.html) or from the terminal.
3952

4053
- **Gradle Tool Window:** You can find the task under: `Tasks > reporting > rootCodeCoverageReport`, double click to execute it.
4154
- **Terminal:** Execute the task using `gradlew rootCodeCoverageReport`.
4255

56+
4357
# Configuration
44-
By default the plugin generates code coverage reports using the build variant `debug` for every module. However in some cases different build variants per module might be required, especially if there is no `debug` build variant available. In those cases you can configure custom build variants for specific modules:
58+
By default the plugin generates code coverage reports using the build variant `debug` for every
59+
module. However in some cases different build variants per module might be required, especially if
60+
there is no `debug` build variant available. In those cases you can configure custom build variants
61+
for specific modules:
4562

4663
```groovy
4764
rootCoverage {
4865
// The default build variant for every module
4966
buildVariant "debug"
5067
// Overrides the default build variant for specific modules.
5168
buildVariantOverrides ":moduleA" : "debugFlavourA", ":moduleB": "debugFlavourA"
69+
70+
5271
// Class exclude patterns
5372
excludes = ["**/some.package/**"]
5473
// If true the task it self does not execute any tests (debug option)
5574
skipTestExecution false
75+
// Type of tests to run (import com.android.builder.model.TestVariantBuildOutput.TestType)
76+
testTypes = [TestType.UNIT, TestType.ANDROID_TEST]
5677
}
5778
```
5879

5980

6081
# Development
61-
Want to contribute? Great! Currently this plugin is in need of extensive testing. Besides this there is also a small wish list:
82+
Want to contribute? Great! Currently this plugin is mainly in need of extensive testing in some more
83+
projects. But if you like to add some actually functionality, this is the wish list:
6284

63-
- Support for Java modules
85+
- Support for Java library modules
6486
- Make use of the JacocoMerge task? To merge the `exec` en `ec` files?
6587
- Support for configuring the output type: html, xml etc. (Just like Jacoco)
66-
- Actual Plugin unit-tests (instead of a test project)
88+
- Improved integration test setup: without the hackish dynamic versions in the Gradle plugin block?
89+
90+
**How to test your changes/additions?**
91+
The plugin comes with an integration test. You can run this test either by executing
92+
`gradlew clean test` or run the test directly from Android Studio using a proper run/test
93+
configuration as shown in the image *(by default it generates configuration that is not compatible
94+
with a plugin module)*:
95+
![Correct run/test configuration](correct-test-run-configuration.png)
96+
6797

6898
# Author note
69-
Many thanks to [Hans van Dam](https://github.com/hansvdam) for helping with testing and the inital idea.
99+
Many thanks to [Hans van Dam](https://github.com/hansvdam) for helping with testing and the initial idea.

app/build.gradle

Lines changed: 0 additions & 39 deletions
This file was deleted.

app/src/androidTest/java/org/neotech/app/multimoduleapplication/ExampleInstrumentedTest.kt

Lines changed: 0 additions & 30 deletions
This file was deleted.

app/src/test/java/org/neotech/app/multimoduleapplication/ExampleUnitTest.kt

Lines changed: 0 additions & 23 deletions
This file was deleted.

build.gradle

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,21 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2-
apply plugin: 'jacoco'
3-
apply plugin: 'org.neotech.plugin.rootcoverage'
4-
52
buildscript {
6-
ext.versions = [
7-
minSdk: 21,
8-
targetSdk: 28,
9-
compileSdk: 28,
10-
kotlin: "1.2.71",
11-
gradlePlugin: "3.2.1"
12-
]
13-
ext.deps = [
14-
kotlinPlugin: "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}",
15-
gradlePlugin: "com.android.tools.build:gradle:${versions.gradlePlugin}",
16-
kotlinStdlibJdk7: "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}"
17-
]
3+
4+
// Import versions
5+
apply from: "gradle/dependencies.gradle"
186

197
repositories {
208
google()
219
jcenter()
22-
23-
// Local maven repository for development purposes.
24-
maven {
25-
url uri('/repo')
26-
}
2710
}
2811
dependencies {
29-
classpath deps.gradlePlugin
30-
classpath deps.kotlinPlugin
12+
classpath projectDependency.gradlePlugin
13+
classpath projectDependency.kotlinPlugin
3114

3215
// Bintray & Maven for publishing
3316
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
3417
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
3518

36-
classpath 'org.neotech.plugin:android-root-coverage-plugin:0.0.2-dev'
3719
// NOTE: Do not place your application dependencies here; they belong
3820
// in the individual module build.gradle files
3921
}
@@ -48,16 +30,4 @@ allprojects {
4830

4931
task clean(type: Delete) {
5032
delete rootProject.buildDir
51-
}
52-
53-
54-
jacoco {
55-
toolVersion = "0.8.2"
56-
}
57-
58-
rootCoverage {
59-
buildVariant "debug"
60-
buildVariantOverrides ":library_a" : "debug", ":library_b": "debug"
61-
//excludes = ["**/LibraryAJava.class"]
62-
//skipTestExecution true
6333
}

correct-test-run-configuration.png

37.4 KB
Loading

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ org.gradle.jvmargs=-Xmx1536m
1919
#PACKAGING=jar
2020

2121
GROUP=org.neotech.plugin
22-
VERSION=0.0.2-dev
22+
VERSION=1.0.0
2323
DESCRIPTION=A Gradle plugin for easy generation of combined code coverage reports for Android projects with multiple modules.
2424

2525
PROJECT_WEBSITE=https://github.com/NeoTech-Software/android-root-coverage-plugin

gradle/dependencies.gradle

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
ext {
2+
projectVersion = [
3+
minSdk : 21,
4+
targetSdk : 28,
5+
compileSdk : 28,
6+
// Kotlin version is used in multiple places hence it is available as version variable
7+
kotlin : "1.2.71"
8+
]
9+
projectDependency = [
10+
11+
// Gradle Plugins
12+
kotlinPlugin : "org.jetbrains.kotlin:kotlin-gradle-plugin:${projectVersion.kotlin}",
13+
gradlePlugin : "com.android.tools.build:gradle:3.2.1",
14+
15+
// Dependencies
16+
kotlinStdlibJdk7 : "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${projectVersion.kotlin}",
17+
appCompat : "com.android.support:appcompat-v7:28.0.0",
18+
19+
// Test dependencies
20+
junit : "junit:junit:4.12",
21+
truth : "com.google.truth:truth:0.42",
22+
supportTestRunner : "com.android.support.test:runner:1.0.2",
23+
espressoCore : "com.android.support.test.espresso:espresso-core:3.0.2"
24+
]
25+
26+
// Used by the plugin-version-handler.gradle
27+
pluginVersions = [
28+
"org.jetbrains.kotlin.android": "${projectVersion.kotlin}"
29+
]
30+
}

gradle/plugin-version-handler.gradle

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (C) 2018 Rolf Smit
2+
//
3+
// This file can be used as a hack to make it possible to use variable/dynamic version numbers for
4+
// plugins in the new Gradle Plugins Block:
5+
// https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block
6+
// Normally variables cannot be used, but through the project settings.pluginManagement DSL some
7+
// configuration is possible.
8+
//
9+
// How to use?
10+
//
11+
// 1. Add the following to your settings.gradle file:
12+
//
13+
// pluginManagement {
14+
// apply from: "path/to/plugin-version-handler.gradle", to: pluginManagement
15+
// }
16+
//
17+
// 2. Add the plugins that you want to use variable/dynamic version for to the dependencies.gradle
18+
// file:
19+
//
20+
// ext {
21+
// projectVersion = [
22+
// kotlin : "1.3.0",
23+
// ]
24+
//
25+
// pluginVersions = [
26+
// "org.jetbrains.kotlin.android": "${projectVersion.kotlin}"
27+
// ]
28+
// }
29+
30+
31+
apply from: "dependencies.gradle"
32+
33+
resolutionStrategy {
34+
eachPlugin {
35+
def version = pluginVersions[requested.id.id]
36+
if (requested.version == null && version != null) {
37+
useVersion version
38+
}
39+
}
40+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)