Skip to content

Commit eceb802

Browse files
authored
Added sanity UI tests in the sample app (#190)
* Added sanity UI tests in the sample app * Added tasks for merged code coverage report and for static code analysis combined with UI tests * Added CircleCI integration * Added simple screenshot reports. * Fixed incorrect color in the sample app in 'Custom StepperLayout theme' sample
1 parent bdc10b5 commit eceb802

File tree

21 files changed

+965
-92
lines changed

21 files changed

+965
-92
lines changed

.travis.yml

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

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<img src ="./art/material-stepper-logo.png" width="256" height="256"/>
33
</p>
44

5-
# Android Material Stepper [![Build Status](https://travis-ci.org/stepstone-tech/android-material-stepper.svg?branch=master)](https://travis-ci.org/stepstone-tech/android-material-stepper) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Android%20Material%20Stepper-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/5138) [![Android Weekly](https://img.shields.io/badge/Android%20Weekly-%23243-brightgreen.svg)](http://androidweekly.net/issues/issue-243)
5+
# Android Material Stepper [![CircleCI](https://circleci.com/gh/stepstone-tech/android-material-stepper.svg?style=svg)](https://circleci.com/gh/stepstone-tech/android-material-stepper) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Android%20Material%20Stepper-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/5138) [![Android Weekly](https://img.shields.io/badge/Android%20Weekly-%23243-brightgreen.svg)](http://androidweekly.net/issues/issue-243)
66

77
This library allows to use Material steppers inside Android applications.
88

build.gradle

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
buildscript {
2-
ext.gradleAndroidVersion = '2.3.3'
2+
ext.gradleAndroidVersion = '3.0.0-beta2'
33
ext.kotlinVersion = '1.1.3-2'
44
ext.bintrayVersion = '1.4'
55
ext.mavenGradlePluginVersion = '1.4.1'
66

77
repositories {
88
jcenter()
9+
google()
910
}
1011
dependencies {
1112
classpath "com.android.tools.build:gradle:$gradleAndroidVersion"
@@ -19,9 +20,7 @@ allprojects {
1920
repositories {
2021
jcenter()
2122
mavenCentral()
22-
maven {
23-
url "https://maven.google.com"
24-
}
23+
google()
2524
}
2625
}
2726

@@ -40,6 +39,9 @@ configure(allprojects) {
4039
robolectricVersion = '3.3.1'
4140
assertjVersion = '1.1.1'
4241

42+
supportTestVersion = '1.0.0'
43+
espressoVersion = '3.0.0'
44+
4345
/* Sample only */
4446
butterknifeVersion = '8.5.1'
4547
calligraphyVersion = '2.2.0'

circle.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
machine:
2+
environment:
3+
PATH: "~/$CIRCLE_PROJECT_REPONAME/gradle-4.1/bin:$PATH"
4+
TERM: "dumb"
5+
ADB_INSTALL_TIMEOUT: "10"
6+
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"'
7+
_JAVA_OPTIONS: "-Xms512m -Xmx1024m -XX:ParallelGCThreads=2 -XX:ConcGCThreads=2 -XX:ParallelGCThreads=2 -Djava.util.concurrent.ForkJoinPool.common.parallelism=2"
8+
9+
dependencies:
10+
pre:
11+
- wget "https://services.gradle.org/distributions/gradle-4.1-bin.zip"; unzip gradle-4.1-bin.zip
12+
- if [ ! -e /usr/local/android-sdk-linux/build-tools/25.0.2 ]; then echo y | android update sdk --all --no-ui --filter "build-tools-25.0.2"; fi;
13+
- if [ ! -e /usr/local/android-sdk-linux/platforms/android-25 ]; then echo y | android update sdk --all --no-ui --filter "android-25"; fi;
14+
- if ! $(grep -q "Revision=47.0.0" /usr/local/android-sdk-linux/extras/android/m2repository/source.properties); then echo y | android update sdk --all --no-ui --filter "extra-android-m2repository"; fi;
15+
- echo y | android update sdk --no-ui --all --filter tool,extra-google-google_play_services
16+
- printf 'bintray.user=dummy_user\nbintray.apikey=dummy_api_key\nsdk.dir=/usr/local/android-sdk-linux' > local.properties
17+
18+
cache_directories:
19+
- /usr/local/android-sdk-linux/build-tools/25.0.2
20+
- /usr/local/android-sdk-linux/platforms/android-25
21+
- /usr/local/android-sdk-linux/extras/android/m2repository
22+
23+
test:
24+
override:
25+
# run static analysis and unit tests with coverage
26+
- ./gradlew checkWithCoverage --stacktrace --no-daemon
27+
28+
# Create SD card (needed for screenshots)
29+
- mksdcard -l sdcard 200M sdcard.img
30+
31+
# start the emulator
32+
- emulator -avd circleci-android22 -sdcard sdcard.img -no-audio -no-window:
33+
background: true
34+
parallel: true
35+
# wait for it to have booted
36+
- circle-android wait-for-boot
37+
- sleep 30
38+
# unlock the emulator screen
39+
- adb shell input keyevent 82
40+
41+
# run instrumentation tests with coverage & lint for the sample app
42+
- ./gradlew :sample:lintDebug mergedJacocoTestReport --stacktrace --no-daemon -Ptest.integration.options.adbInstallOptions=-r
43+
- ./gradlew install --no-daemon
44+
45+
# upload code coverage reports to Codecov.io
46+
- bash <(curl -s https://codecov.io/bash)
47+
48+
post:
49+
# copy the test results to the test results directory
50+
- mkdir -p $CIRCLE_TEST_REPORTS/unit
51+
- mkdir -p $CIRCLE_TEST_REPORTS/instrumentation
52+
- find . -type f -regex ".*/build/test-results/testDebugUnitTest/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/unit/ \;
53+
- find . -type f -regex ".*/build/outputs/androidTest-results/connected/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/instrumentation/ \;
54+
55+
# copy the reports to artifacts directory
56+
- mkdir -p $CIRCLE_ARTIFACTS/reports-library
57+
- mkdir -p $CIRCLE_ARTIFACTS/reports-sample
58+
- cp -r material-stepper/build/reports $CIRCLE_ARTIFACTS/reports-library
59+
- cp -r sample/build/reports $CIRCLE_ARTIFACTS/reports-sample

config/project_properties.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def final String PROPERTY_ADB_INSTALL_OPTIONS = 'test.integration.options.adbInstallOptions'
2+
3+
/**
4+
* Returns adbInstallOptions to use. This is needed because different adb install options are supported depending on OS version.
5+
* @return
6+
*/
7+
ext.getAdbInstallOptions = {
8+
def adbInstallOptions = (project.hasProperty(PROPERTY_ADB_INSTALL_OPTIONS) ? project.getProperties().get(PROPERTY_ADB_INSTALL_OPTIONS).split(',') : ['-g', '-r']) as String[]
9+
println("Running with adbInstallOptions: $adbInstallOptions")
10+
return adbInstallOptions
11+
}

config/quality/quality.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencies {
1818
checkstyle 'com.puppycrawl.tools:checkstyle:6.11.1'
1919
}
2020

21-
def qualityConfigDir = "$project.rootDir/config/quality";
21+
def qualityConfigDir = "$project.rootDir/config/quality"
2222
def reportsDir = "$project.buildDir/reports"
2323

2424
task checkstyle(type: Checkstyle, group: 'Verification', description: 'Runs code style checks') {
@@ -29,7 +29,7 @@ task checkstyle(type: Checkstyle, group: 'Verification', description: 'Runs code
2929
reports {
3030
xml.enabled = true
3131
xml {
32-
destination "$reportsDir/checkstyle/checkstyle.xml"
32+
destination file("$reportsDir/checkstyle/checkstyle.xml")
3333
}
3434
}
3535

@@ -52,10 +52,10 @@ task findbugs(type: FindBugs,
5252
exclude '**/gen/**'
5353

5454
reports {
55-
xml.enabled = true
56-
html.enabled = false
55+
xml.enabled = false
56+
html.enabled = true
5757
xml {
58-
destination "$reportsDir/findbugs/findbugs.xml"
58+
destination file("$reportsDir/findbugs/findbugs.xml")
5959
}
6060
}
6161

@@ -76,10 +76,10 @@ task pmd(type: Pmd, group: 'Verification', description: 'Inspect sourcecode for
7676
xml.enabled = true
7777
html.enabled = true
7878
xml {
79-
destination "$reportsDir/pmd/pmd.xml"
79+
destination file("$reportsDir/pmd/pmd.xml")
8080
}
8181
html {
82-
destination "$reportsDir/pmd/pmd.html"
82+
destination file("$reportsDir/pmd/pmd.html")
8383
}
8484
}
8585
}

gradle.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@
1919

2020
POM_GROUP_ID=com.stepstone.stepper
2121
POM_ARTIFACT_ID=material-stepper
22-
POM_VERSION=4.0.0
22+
POM_VERSION=4.0.0
23+
24+
#Needed so that Robolectric is working: https://github.com/robolectric/robolectric/issues/3169
25+
android.enableAapt2=false

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-3.3-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

material-stepper/build.gradle

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ android {
3636
minSdkVersion project.androidMinSdkVersion
3737
targetSdkVersion project.androidTargetSdkVersion
3838
vectorDrawables.useSupportLibrary = true
39-
4039
}
40+
4141
buildTypes {
4242
release {
4343
minifyEnabled false
4444
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
4545
}
46+
debug {
47+
testCoverageEnabled true
48+
}
4649
}
4750

4851
testOptions {
@@ -52,26 +55,29 @@ android {
5255
includeNoLocationClasses = true
5356
}
5457
}
58+
//fixes https://github.com/robolectric/robolectric/issues/3169#issuecomment-312046322
59+
unitTests.includeAndroidResources = true
5560
}
5661

5762
lintOptions {
5863
warningsAsErrors true
64+
disable 'RequiredSize', 'ClickableViewAccessibility'
5965
}
6066
}
6167

6268
dependencies {
63-
compile "com.android.support:appcompat-v7:$androidSupportLibraryVersion"
69+
api "com.android.support:appcompat-v7:$androidSupportLibraryVersion"
6470

65-
testCompile "junit:junit:$junitVersion"
66-
testCompile "org.mockito:mockito-core:$mockitoVersion"
67-
testCompile "com.squareup.assertj:assertj-android:$assertjVersion"
68-
testCompile("org.robolectric:robolectric:$robolectricVersion") {
71+
testImplementation "junit:junit:$junitVersion"
72+
testImplementation "org.mockito:mockito-core:$mockitoVersion"
73+
testImplementation "com.squareup.assertj:assertj-android:$assertjVersion"
74+
testImplementation("org.robolectric:robolectric:$robolectricVersion") {
6975
exclude group: 'commons-logging', module: 'commons-logging'
7076
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
7177
}
72-
testCompile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlinVersion"
73-
testCompile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
74-
testCompile "com.nhaarman:mockito-kotlin:$mockitoKotlinVersion"
78+
testImplementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlinVersion"
79+
testImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
80+
testImplementation "com.nhaarman:mockito-kotlin:$mockitoKotlinVersion"
7581
}
7682

7783
gradle.taskGraph.beforeTask { Task task ->
@@ -85,11 +91,13 @@ gradle.taskGraph.beforeTask { Task task ->
8591
}
8692

8793
// Log out test results to console
88-
tasks.matching { it instanceof Test }.all {
94+
tasks.matching { it instanceof Test}.all {
8995
testLogging.events = ["failed", "passed", "skipped"]
9096
}
9197

92-
check.dependsOn 'checkstyle', 'findbugs', 'pmd', 'jacocoTestReport'
98+
task ('checkWithCoverage') {
99+
dependsOn 'checkstyle', 'findbugs', 'pmd', 'jacocoTestReport', 'lintDebug'
100+
}
93101

94102
apply from: '../installv1.gradle'
95103
apply from: '../bintrayv1.gradle'

material-stepper/code_coverage.gradle

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ task('jacocoTestReport', type: JacocoReport, dependsOn: 'testDebugUnitTest') {
1414

1515
classDirectories = fileTree(
1616
dir: './build/intermediates/classes/debug',
17-
excludes: ['**/R*.class',
18-
'**/*$InjectAdapter.class',
19-
'**/*$ModuleAdapter.class',
20-
'**/*$ViewInjector*.class'
21-
]
17+
excludes: ['**/R.class',
18+
'**/R$*.class',
19+
'**/BuildConfig.*',
20+
'**/Manifest*.*',
21+
'**/*IScript*.*',
22+
'android/**/*.*',
23+
'**/**_ViewBinding.*',
24+
'**/**_ViewBinding$*']
2225
)
2326

2427
def coverageSourceDirs = [

0 commit comments

Comments
 (0)