Skip to content

Commit

Permalink
Ui tests and dependency bump (#14)
Browse files Browse the repository at this point in the history
Ui tests and dependency bump

 * Runs UI tests on CircleCI and BuddyBuild
    * Drops renaming APK, created problems for spoon on CircleCi
 * Updates depenedencies to newer versions, and ports code if needed
    * Drops `apt`, uses default `annotationProcessor` instead
  • Loading branch information
Naitbit committed Oct 26, 2016
1 parent 61cb704 commit d488263
Show file tree
Hide file tree
Showing 26 changed files with 260 additions and 77 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ env:
android:
components:
- tools
- android-23
- android-25
- platform-tools
- build-tools-23.0.3
- build-tools-25.0.0
- extra-android-m2repository

script: ./gradlew check jacocoTestReport coveralls
93 changes: 59 additions & 34 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ apply plugin: 'com.android.application'
apply from: '../gradle/byoutline/retrolambdaConfig.gradle'
apply from: "$rootDir/gradle/checkstyle.gradle"
apply from: "$rootDir/gradle/pmd.gradle"
apply plugin: 'jacoco'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'jacoco' /// used only by tests

buildscript {
// ext.support_version = '23.1.1'
ext.support_version = '23.3.0'
ext.dagger_version = '2.4'
ext.support_version = '25.0.0'
ext.dagger_version = '2.7'

repositories {
jcenter()
Expand All @@ -17,6 +15,7 @@ buildscript {
dependencies {
classpath 'net.saliman:gradle-cobertura-plugin:2.0.0'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.3.1'
classpath 'com.stanfy.spoon:spoon-gradle-plugin:1.0.4'
}
}

Expand All @@ -28,8 +27,8 @@ repositories {


android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
compileSdkVersion 25
buildToolsVersion '25'

dataBinding {
enabled = true
Expand All @@ -38,12 +37,17 @@ android {
defaultConfig {
applicationId 'com.byoutline.kickmaterial'
minSdkVersion 18
targetSdkVersion 23
targetSdkVersion 25
versionCode 2
versionName '1.0.1'

multiDexEnabled false
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'

// CircleCi needs custom runner to turn off animations.
// BuddyBuild on the other hand does not find any tests with custom runner.
testInstrumentationRunner System.getenv('BUDDYBUILD_APP_ID') == null ?
'com.jakewharton.u2020.U2020TestRunner' :
'android.support.test.runner.AndroidJUnitRunner'
}

buildTypes {
Expand All @@ -54,20 +58,20 @@ android {
}
}

applicationVariants.all { variant ->
variant.outputs.each { output ->
def file = output.outputFile
output.outputFile = new File(file.parent, 'kickmaterial-' + defaultConfig.versionName + '.apk')
}
}
// applicationVariants.all { variant ->
// variant.outputs.each { output ->
// def file = output.outputFile
// output.outputFile = new File(file.parent, 'kickmaterial-' + defaultConfig.versionName + '.apk')
// }
// }

testOptions {
//unitTests.returnDefaultValues = true
}

lintOptions {
lintConfig file('lint.xml')
textOutput 'stdout'
// textOutput 'stdout'
textReport true
}

Expand All @@ -94,17 +98,15 @@ android {
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':appjava')
compile "com.android.support:support-v4:$support_version"
compile "com.android.support:appcompat-v7:$support_version"
compile "com.android.support:cardview-v7:$support_version"
compile "com.android.support:recyclerview-v7:$support_version"
compile "com.android.support:support-annotations:$support_version"
compile "com.android.support:palette-v7:$support_version"
compile 'com.jakewharton:butterknife:8.0.1'
apt 'com.jakewharton:butterknife-compiler:8.0.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.0.1'
compile 'com.byoutline.secretsauce:secretsauce:0.5.2'
compile 'com.byoutline.ottocachedfield:observablecachedfield:1.1.0-SNAPSHOT'
compile 'com.byoutline.androidstubserver:stubserver:2.0.0-beta1'
compile 'com.byoutline.androidstubserver:stubserver:2.0.0-beta2-SNAPSHOT'
compile 'com.byoutline.eventcallback:eventcallback-api:1.0.1'
compile 'com.byoutline.ottoeventcallback:anythreadbus:1.0.0'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
Expand All @@ -115,38 +117,61 @@ dependencies {
compile 'javax.inject:javax.inject:1'
// For dagger 2
compile "com.google.dagger:dagger:$dagger_version"
apt "com.google.dagger:dagger-compiler:$dagger_version"
apt 'com.google.guava:guava:19.0' // For some reason currently required for dagger
provided 'javax.annotation:jsr250-api:1.0'
annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version"

compile 'com.kenai.nbpwr:edu-umd-cs-findbugs-annotations:1.3.2-201002241900'
compile 'com.jakewharton.timber:timber:3.1.0'
compile 'com.github.shell-software:fab:1.0.5'
compile 'commons-collections:commons-collections:3.2.1'
compile 'me.tatarka.bindingcollectionadapter:bindingcollectionadapter:1.1.0'
compile 'me.tatarka.bindingcollectionadapter:bindingcollectionadapter-recyclerview:1.1.0'

compile 'me.tatarka.bindingcollectionadapter:bindingcollectionadapter:1.3.0'
compile 'me.tatarka.bindingcollectionadapter:bindingcollectionadapter-recyclerview:1.3.0'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.9.5'
testCompile 'com.squareup.assertj:assertj-android:1.0.0'
testCompile 'org.robolectric:robolectric:2.4'
testCompile 'com.google.code.findbugs:jsr305:3.0.0'

androidTestCompile "com.android.support:support-v4:$support_version"
androidTestCompile "com.android.support:support-annotations:$support_version"
androidTestCompile "com.android.support:appcompat-v7:$support_version"
androidTestCompile "com.android.support:recyclerview-v7:$support_version"
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.1'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile "com.android.support:cardview-v7:$support_version"
androidTestCompile "com.android.support:palette-v7:$support_version"
androidTestCompile "com.android.support:support-annotations:25.0.0"
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2.2') {
// AS does not want to run tests without this exclude
exclude group: 'com.android.support'
}
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2') {
exclude group: 'com.android.support'
}
androidTestCompile ('com.android.support.test.espresso:espresso-intents:2.2.2') {
exclude group: 'com.android.support'
}
androidTestCompile ('com.android.support.test:rules:0.5') {
exclude group: 'com.android.support'
}
androidTestCompile ('com.android.support.test:runner:0.5') {
exclude group: 'com.android.support'
}
androidTestCompile 'com.google.code.findbugs:jsr305:3.0.0'
androidTestCompile 'com.squareup.spoon:spoon-client:1.3.1'
androidTestCompile 'com.byoutline.cachedfield:idlingresource:1.0.0'
androidTestCompile 'com.byoutline.cachedfield:cachedfield:1.5.3'
}

// AS does not want to run application with play button without resolution strategy
// (despite app installing and working fine for tests)
configurations.all {
resolutionStrategy.force "com.android.support:support-annotations:$support_version"
}

// Wait before applying spoon plugin, because otherwise it does not see custom apk name.
apply plugin: 'spoon'

spoon {
noAnimations = true
adbTimeout = 60 * 10
debug = true
}

//configurations.all {
// // check for updates every build
// resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
Expand Down
3 changes: 3 additions & 0 deletions app/lint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
<ignore regexp="okio.Okio.*"/>
<ignore regexp="retrofit2.Platform.Java8.*"/>
</issue>
<issue id="MissingSuperCall">
<ignore regexp="com.byoutline.kickmaterial.KickMaterialApp" />
</issue>
</lint>
2 changes: 1 addition & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers

-keepattributes Signature,*Annotation*,EnclosingMethod,SourceFile,LineNumberTable
-keepattributes Signature,*Annotation*,EnclosingMethod,SourceFile,LineNumberTable,InnerClasses
-dontnote

-keepclassmembers enum * { *; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.byoutline.kickmaterial;

import android.support.test.espresso.Espresso;
import android.support.test.rule.ActivityTestRule;
import com.byoutline.cachedfield.utils.CachedFieldIdlingResource;
import com.byoutline.kickmaterial.activities.MainActivity;
import com.byoutline.kickmaterial.espressohelpers.DaggerRules;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

Expand All @@ -17,6 +21,18 @@
public class MainActivityFirstStartTest {
@Rule
public ActivityTestRule<MainActivity> activityRule = DaggerRules.userFirstLaunchRule();
private CachedFieldIdlingResource cachedFieldIdlingResource;

@Before
public void registerIdlingResources() {
cachedFieldIdlingResource = CachedFieldIdlingResource.from(KickMaterialApp.component.getDiscoverField());
Espresso.registerIdlingResources(cachedFieldIdlingResource);
}

@After
public void unregisterIdlingResources() {
Espresso.unregisterIdlingResources(cachedFieldIdlingResource);
}

@Test
public void testAllCategoriesShouldBeVisible() {
Expand All @@ -25,8 +41,6 @@ public void testAllCategoriesShouldBeVisible() {

@Test
public void testHeaderShouldBeVisible() {
// onView(withId(R.id.project_recycler_view))
// .perform(RecyclerViewActions.scrollTo(withText(R.string.explore)));
onView(withText(R.string.explore))
.check(matches(isDisplayed()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package com.byoutline.kickmaterial;

import android.support.test.espresso.Espresso;
import android.support.test.espresso.NoMatchingViewException;
import android.support.test.rule.ActivityTestRule;

import com.byoutline.cachedfield.utils.CachedFieldIdlingResource;
import com.byoutline.kickmaterial.activities.MainActivity;
import com.byoutline.kickmaterial.espressohelpers.DaggerRules;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

Expand All @@ -18,11 +24,21 @@
public class MainActivityNextStartTest {
@Rule
public ActivityTestRule<MainActivity> activityRule = DaggerRules.userNextLaunchRule();
private CachedFieldIdlingResource cachedFieldIdlingResource;

@Before
public void registerIdlingResources() {
cachedFieldIdlingResource = CachedFieldIdlingResource.from(KickMaterialApp.component.getDiscoverField());
Espresso.registerIdlingResources(cachedFieldIdlingResource);
}

@After
public void unregisterIdlingResources() {
Espresso.unregisterIdlingResources(cachedFieldIdlingResource);
}

@Test(expected=NoMatchingViewException.class)
public void testHeaderShouldNotBeVisible() {
// onView(withId(R.id.project_recycler_view))
// .perform(RecyclerViewActions.scrollTo(withText(R.string.explore)));
onView(withText(R.string.explore))
.check(matches(isDisplayed()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
import android.app.Application;
import android.support.annotation.NonNull;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.Espresso;
import android.support.test.espresso.base.DefaultFailureHandler;
import android.support.test.rule.ActivityTestRule;
import com.squareup.spoon.Spoon;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

/**
* {@link ActivityTestRule} which provides hook for
Expand Down Expand Up @@ -61,4 +66,16 @@ public interface OnBeforeActivityLaunchedListener<T> {

void beforeActivityLaunched(@NonNull Application application, @NonNull T activity);
}

@Override
public Statement apply(Statement base, Description description) {
// On Ci take screenshot if test fails
if(System.getenv("CIRCLECI") != null) {
Espresso.setFailureHandler((error, viewMatcher) -> {
Spoon.screenshot(getActivity(), error.getClass().getSimpleName(), description.getClassName(), description.getMethodName());
new DefaultFailureHandler(getActivity()).handle(error, viewMatcher);
});
}
return super.apply(base, description);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.jakewharton.u2020;

import android.annotation.SuppressLint;
import android.app.KeyguardManager;
import android.content.Context;
import android.os.PowerManager;
import android.support.test.runner.AndroidJUnitRunner;

import static android.content.Context.KEYGUARD_SERVICE;
import static android.content.Context.POWER_SERVICE;
import static android.os.PowerManager.ACQUIRE_CAUSES_WAKEUP;
import static android.os.PowerManager.FULL_WAKE_LOCK;
import static android.os.PowerManager.ON_AFTER_RELEASE;

public final class U2020TestRunner extends AndroidJUnitRunner {
private PowerManager.WakeLock wakeLock;

// Permissions added in debug only manifest.
@Override
@SuppressLint("MissingPermission")
public void onStart() {
Context app = getTargetContext().getApplicationContext();

String name = U2020TestRunner.class.getSimpleName();
// Unlock the device so that the tests can input keystrokes.
KeyguardManager keyguard = (KeyguardManager) app.getSystemService(KEYGUARD_SERVICE);
//noinspection ResourceType
keyguard.newKeyguardLock(name).disableKeyguard();
// Wake up the screen.
PowerManager power = (PowerManager) app.getSystemService(POWER_SERVICE);
wakeLock = power.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP | ON_AFTER_RELEASE, name);
wakeLock.acquire();

super.onStart();
}

@Override
@SuppressLint("MissingPermission")
public void onDestroy() {
super.onDestroy();
wakeLock.release();
}
}
10 changes: 10 additions & 0 deletions app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.byoutline.kickmaterial">

<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>

</manifest>
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@

</application>

<instrumentation
android:name="com.byoutline.kickmaterial.espressohelpers.U2020TestRunner"
android:targetPackage="com.byoutline.kickmaterial"
/>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,6 @@ public void onResume() {
showActionbar(false, false);
}

@Override
public void onPause() {
super.onPause();
}

@Override
public void onSaveInstanceState(Bundle outState) {
outState.putInt(INSTANCE_STATE_SUMMARY_SCROLLED, summaryScrolledValue);
Expand Down

0 comments on commit d488263

Please sign in to comment.