Skip to content

Commit 0b14423

Browse files
committed
Fixes to allow the code to work with latest Android Plugin
1 parent 1b624db commit 0b14423

File tree

4 files changed

+24
-22
lines changed

4 files changed

+24
-22
lines changed

app/build.gradle

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,38 @@
11
apply plugin: 'com.android.application'
22
apply plugin: 'jacoco'
33

4-
task jacocoTestReport(type: JacocoReport, dependsOn: 'testDebugUnitTest') {
4+
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
55

66
reports {
77
xml.enabled = true
88
html.enabled = true
99
}
1010

11-
jacocoClasspath = configurations['androidJacocoAnt']
12-
1311
def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
1412
def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter)
1513
def mainSrc = "${project.projectDir}/src/main/java"
1614

1715
sourceDirectories = files([mainSrc])
1816
classDirectories = files([debugTree])
19-
executionData = files(["${buildDir}/jacoco/testDebugUnitTest.exec",
20-
"${buildDir}/outputs/code-coverage/connected/coverage.ec"
17+
executionData = fileTree(dir: "$buildDir", includes: [
18+
"jacoco/testDebugUnitTest.exec", "outputs/code-coverage/connected/*coverage.ec"
2119
])
2220
}
2321

24-
jacoco {
25-
26-
}
27-
2822
android {
29-
compileSdkVersion 23
30-
buildToolsVersion '23.0.3'
23+
compileSdkVersion 25
24+
buildToolsVersion '25.0.0'
3125

3226
defaultConfig {
3327
applicationId 'net.rafaeltoledo.coverage'
3428
minSdkVersion 15
35-
targetSdkVersion 23
29+
targetSdkVersion 25
3630
versionCode 1
3731
versionName '1.0'
3832

3933
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
4034
}
35+
4136
buildTypes {
4237
debug {
4338
testCoverageEnabled true
@@ -47,15 +42,22 @@ android {
4742
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
4843
}
4944
}
45+
46+
testOptions {
47+
unitTests.all {
48+
jacoco {
49+
includeNoLocationClasses = true
50+
}
51+
}
52+
}
5053
}
5154

5255
dependencies {
53-
compile 'com.android.support:appcompat-v7:23.3.0'
56+
compile 'com.android.support:appcompat-v7:25.0.0'
5457

5558
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
56-
androidTestCompile 'com.android.support:support-annotations:23.3.0'
57-
androidTestCompile 'com.android.support.test:runner:0.5'
59+
androidTestCompile 'com.android.support:support-annotations:25.0.0'
5860

5961
testCompile 'junit:junit:4.12'
60-
testCompile 'org.robolectric:robolectric:3.0'
62+
testCompile 'org.robolectric:robolectric:3.1.4'
6163
}

app/src/test/java/net/rafaeltoledo/coverage/MainActivityTest.java renamed to app/src/test/java/net/rafaeltoledo/coverage/MainActivityUnitTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
import org.junit.Test;
77
import org.junit.runner.RunWith;
88
import org.robolectric.Robolectric;
9-
import org.robolectric.RobolectricGradleTestRunner;
9+
import org.robolectric.RobolectricTestRunner;
1010
import org.robolectric.annotation.Config;
1111

1212
import static org.hamcrest.MatcherAssert.assertThat;
1313
import static org.hamcrest.core.Is.is;
1414

15-
@RunWith(RobolectricGradleTestRunner.class)
16-
@Config(constants = BuildConfig.class, sdk = 21)
17-
public class MainActivityTest {
15+
@RunWith(RobolectricTestRunner.class)
16+
@Config(constants = BuildConfig.class, sdk = 22)
17+
public class MainActivityUnitTest {
1818

1919
@Test
2020
public void shouldHideButtonAfterClick() {

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ buildscript {
33
jcenter()
44
}
55
dependencies {
6-
classpath 'com.android.tools.build:gradle:2.0.0'
6+
classpath 'com.android.tools.build:gradle:2.2.2'
77
}
88
}
99

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-all.zip

0 commit comments

Comments
 (0)