Browse Source

Added espresso tests

master
Henning Hall 6 years ago
parent
commit
d2d1c8c85b
4 changed files with 72 additions and 102 deletions
  1. +0
    -96
      .circleci/config.yml
  2. +15
    -2
      example/android/app/build.gradle
  3. +56
    -0
      example/android/app/src/androidTest/java/com/datepickerexample/HelloWorldEspressoTest.java
  4. +1
    -4
      example/android/build.gradle

+ 0
- 96
.circleci/config.yml View File

@ -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

+ 15
- 2
example/android/app/build.gradle View File

@ -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

+ 56
- 0
example/android/app/src/androidTest/java/com/datepickerexample/HelloWorldEspressoTest.java View File

@ -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<MainActivity> 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();
}
}
}

+ 1
- 4
example/android/build.gradle View File

@ -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()
}
}

Loading…
Cancel
Save