From d2d1c8c85b51f7bb6ecdccc9fe59980158dfc772 Mon Sep 17 00:00:00 2001 From: Henning Hall Date: Sun, 18 Nov 2018 18:16:54 +0100 Subject: [PATCH] Added espresso tests --- .circleci/config.yml | 96 ------------------- example/android/app/build.gradle | 17 +++- .../HelloWorldEspressoTest.java | 56 +++++++++++ example/android/build.gradle | 5 +- 4 files changed, 72 insertions(+), 102 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 example/android/app/src/androidTest/java/com/datepickerexample/HelloWorldEspressoTest.java diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index cc4062a..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,96 +0,0 @@ -version: 2 -jobs: - node: - working_directory: ~/rn-dp - docker: - - image: circleci/node:8 - steps: - - checkout - - - restore_cache: - key: yarn-v1-{{ checksum "example/yarn.lock" }}-{{ arch }} - - - restore_cache: - key: node-v1-{{ checksum "example/package.json" }}-{{ arch }} - - - run: cd example && yarn install - - - save_cache: - key: yarn-v1-{{ checksum "example/yarn.lock" }}-{{ arch }} - paths: - - ~/.cache/yarn - - - save_cache: - key: node-v1-{{ checksum "example/package.json" }}-{{ arch }} - paths: - - example/node_modules - - - persist_to_workspace: - root: ~/rn-dp - paths: - - example/node_modules - - android: - working_directory: ~/rn-dp/example/android - docker: - - image: circleci/android:api-27-node8-alpha - environment: - JVM_OPTS: -Xmx3200m - steps: - - - checkout: - path: ~/rn-dp - - - attach_workspace: - at: ~/rn-dp - - - restore_cache: - key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }} - - - run: - name: Cd - command: cd .. && ls -la - - - run: - name: Download Dependencies - command: ./gradlew androidDependencies - - - save_cache: - paths: - - ~/.gradle - key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }} - - - run: - name: Setup emulator - command: sdkmanager "system-images;android-16;default;armeabi-v7a" && echo "no" | avdmanager create avd -n test -k "system-images;android-16;default;armeabi-v7a" - - run: - name: Launch emulator - command: export LD_LIBRARY_PATH=${ANDROID_HOME}/emulator/lib64:${ANDROID_HOME}/emulator/lib64/qt/lib && emulator64-arm -avd test -noaudio -no-boot-anim -no-window -accel auto -verbose - background: true - - run: - name: Wait emulator - command: | - # start the emulator - - emulator -avd circleci-android22 -no-audio -no-window: - background: true - parallel: true - # wait for it to have booted - circle-android wait-for-boot - # unlock the emulator screen - sleep 30 - adb shell input keyevent 82 - ./gradlew connectedAndroidTest -PdisablePreDex - - store_artifacts: - path: app/build/reports - destination: reports - - store_test_results: - path: app/build/test-results - -workflows: - version: 2 - node-android: - jobs: - - node - - android: - requires: - - node \ No newline at end of file diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 1e337f8..8204c4f 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -106,6 +106,8 @@ android { ndk { abiFilters "armeabi-v7a", "x86" } + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } splits { abi { @@ -120,6 +122,9 @@ android { minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" } + debug { + testCoverageEnabled = true + } } // applicationVariants are e.g. debug, release applicationVariants.all { variant -> @@ -137,11 +142,19 @@ android { } dependencies { + androidTestImplementation 'junit:junit:4.12' compile project(':react-native-date-picker') compile project(':react-native-device-info') - compile fileTree(dir: "libs", include: ["*.jar"]) + compile fileTree(include: ['*.jar'], dir: 'libs') compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}" - compile "com.facebook.react:react-native:+" // From node_modules + compile 'com.facebook.react:react-native:+' + // From node_modules + + compile 'com.android.support:support-annotations:27.1.1' + + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test:rules:1.0.2' } // Run this once to be able to run the application with BUCK diff --git a/example/android/app/src/androidTest/java/com/datepickerexample/HelloWorldEspressoTest.java b/example/android/app/src/androidTest/java/com/datepickerexample/HelloWorldEspressoTest.java new file mode 100644 index 0000000..c410acd --- /dev/null +++ b/example/android/app/src/androidTest/java/com/datepickerexample/HelloWorldEspressoTest.java @@ -0,0 +1,56 @@ +package com.datepickerexample; + + +import android.support.test.espresso.ViewInteraction; +import android.support.test.rule.ActivityTestRule; +import android.support.test.runner.AndroidJUnit4; +import android.test.suitebuilder.annotation.LargeTest; +import android.view.KeyEvent; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.action.ViewActions.click; +import static android.support.test.espresso.action.ViewActions.pressKey; +import static android.support.test.espresso.action.ViewActions.replaceText; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription; +import static android.support.test.espresso.matcher.ViewMatchers.withText; +import static org.hamcrest.Matchers.allOf; + +@LargeTest +@RunWith(AndroidJUnit4.class) +public class HelloWorldEspressoTest { + + @Rule + public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(MainActivity.class); + + @Test + public void mainActivityTest() { + try { + Thread.sleep(15000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + ViewInteraction minimal = onView(allOf(withText("Minimal"), isDisplayed())); + minimal.perform(click()); + + onView(allOf(withText("Today"), isDisplayed())); + + onView(allOf(withText("Back"), isDisplayed())).perform(click()); + + minimal = onView(allOf(withText("Minimal"), isDisplayed())); + minimal.perform(click()); + + + try { + Thread.sleep(30000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + } +} \ No newline at end of file diff --git a/example/android/build.gradle b/example/android/build.gradle index c8c1fff..c8e204c 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -3,10 +3,6 @@ buildscript { repositories { jcenter() - maven { - url 'https://maven.google.com/' - name 'Google' - } google() } dependencies { @@ -31,6 +27,7 @@ allprojects { url 'https://maven.google.com/' name 'Google' } + google() } }