Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

Commit

Permalink
Added more tests (#236)
Browse files Browse the repository at this point in the history
* Removed unused code

* Fixed nasty crash happening when selecting a distance for a sight mark and returning to EditBowActivity while keyboard is opened

* Added SightMarksTest

* Fixes for EditSightMarksTest

* Added EditArrowTest

* More test

* Fixed image selection, renamed matchFab, fixed multiple fabs

WIP intent mocking

* Added espresso classes

* Included my changes

* Removed dependency

* Updated translations

* Refactored and Enhanced MainActivityTest

* Added Scoreboard and TrainingActivityTest

* Fixed crash when opening settings from within scoreboard activity

* Fixed bugs and added logging statements

* Fixed delete bug

* Fixed StandardRound setId NPE

* Fixed some more bugs

* Fixed NPE

* Removed logging again

* Changes to failing UI test

* Added launcher icons 32px and 16px

* Updated libraries

* Fixed generateRegularReleasePlayResources task

* Some changes for backup

* Disabled part of the failing test

* Added rule to automatically disable animations for ui tests

* Removed log statement

* Disable via adb again

* Minor fixes in StandardRound

* Closed #231

* Fixed init error

* Hope fixed wear related crash

* Revert "Added rule to automatically disable animations for ui tests"

This reverts commit 5e4acd5.

* Fixed change target face button

* Added first try to fold and commented more on the failing test

* Revert "Added espresso classes"

* Fixed editArrowTest

* Revert "Revert "Added rule to automatically disable animations for ui tests""

This reverts commit 33a7d77.

* Some fixes

* Fixed EnvironmentSelector

* Revert "Revert "Revert "Added rule to automatically disable animations for ui tests"""

This reverts commit 91408fe.

* Fix travis fold

* Remove camera intent to make sure this does not cause the native crashes

* Reenabled image capture

* Disabled capture test

* Fixed EditTrainingActivityTest

* Updated translations

* Refactored UITestBase by extracting a few methods to helper classes
Fixed strange crashes by disabling ScoreboardActivityTest

* Reverted ScoreboardActivity
  • Loading branch information
DreierF authored Feb 10, 2017
1 parent e453176 commit 5b1ab44
Show file tree
Hide file tree
Showing 131 changed files with 1,655 additions and 752 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ env:
- JAVA7_HOME=/usr/lib/jvm/java-7-oracle
- JAVA8_HOME=/usr/lib/jvm/java-8-oracle
- JAVA_HOME=$JAVA8_HOME
- PWD=`pwd`
android:
components:
- tools
Expand All @@ -39,12 +40,13 @@ before_install:
- wget https://raw.githubusercontent.com/JakeWharton/pidcat/master/pidcat.py
install:
- git fetch --unshallow --tags
- chmod +x travis_fold
before_script:
- echo no | android create avd -f -n test -t "android-"$EMULATOR_API_LEVEL --abi $ANDROID_ABI -s WVGA800 -c 128M
- emulator -avd test -no-audio -no-window &
- ./gradlew clean
script:
- ./gradlew assembleRegularRelease -PdisablePreDex
- ./travis_fold assembleRelease ./gradlew assembleRegularRelease -PdisablePreDex
- android-wait-for-emulator
- adb shell settings put global window_animation_scale 0
- adb shell settings put global transition_animation_scale 0
Expand All @@ -56,7 +58,7 @@ after_success:
- |
if [[ "$TRAVIS_TAG" ]]; then
./gradlew publishRegularRelease
./gradlew -PFirebaseServiceAccountFilePath=app/src/main/google-services.json :app:firebaseUploadRegularReleaseProguardMapping
./gradlew -PFirebaseServiceAccountFilePath=$PWD/app/src/main/google-services.json :app:firebaseUploadRegularReleaseProguardMapping
./dropbox_uploader.sh upload app/build/outputs/apk/app-regular-release.apk /Release/$TRAVIS_TAG/MyTargets.apk
./dropbox_uploader.sh upload app/build/outputs/mapping/regular/release/mapping.txt /Release/$TRAVIS_TAG/mapping.txt
fi
Expand Down
20 changes: 6 additions & 14 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,11 @@ tasks.withType(DataBindingExportBuildInfoTask) { task ->
}
}

task renameFolders {
file('app/src/main/play/ca-ES').renameTo(file('app/src/main/play/ca'))
file('app/src/main/play/sk-SK').renameTo(file('app/src/main/play/sk'))
file('app/src/main/play/sl-SI').renameTo(file('app/src/main/play/sl'))
}

def CROWDIN_API_KEY = project.hasProperty('CROWDIN_API_KEY') ? CROWDIN_API_KEY : System.getenv('CROWDIN_API_KEY')
if (CROWDIN_API_KEY != null && !CROWDIN_API_KEY.isEmpty()) {
tasks.whenTaskAdded { task ->
if (task.name.equals("generateRegularReleasePlayResources")) {
task.dependsOn(':crowdinDownload')
task.dependsOn renameFolders
task.doLast {
file('app/src/main/play/ca').renameTo(file('app/src/main/play/ca-ES'))
file('app/src/main/play/sk').renameTo(file('app/src/main/play/sk-SK'))
file('app/src/main/play/sl').renameTo(file('app/src/main/play/sl-SI'))
}
task.dependsOn ':crowdinDownload'
}
}

Expand Down Expand Up @@ -213,7 +201,11 @@ dependencies {
androidTestCompile("com.android.support.test.espresso:espresso-contrib:$libraryVersion.espresso", {
exclude group: 'com.android.support'
})
androidTestCompile "com.android.support.test.espresso:espresso-intents:$libraryVersion.espresso"
androidTestCompile("com.android.support.test.espresso:espresso-intents:$libraryVersion.espresso", {
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude module: 'recyclerview-v7'
})
androidTestScreengrabCompile "tools.fastlane:screengrab:$libraryVersion.screengrab"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@
* GNU General Public License for more details.
*/

package de.dreier.mytargets.views.selector;
package de.dreier.mytargets.features.arrow;


import android.content.Intent;
import android.support.test.espresso.intent.rule.IntentsTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.widget.RelativeLayout;

import org.hamcrest.core.IsInstanceOf;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
Expand All @@ -41,11 +39,13 @@
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.intent.Intents.intended;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent;
import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withParent;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static de.dreier.mytargets.test.utils.PermissionGranter.allowPermissionsIfNeeded;
import static de.dreier.mytargets.test.utils.matchers.ParentViewMatcher.isNestedChildOfView;
import static de.dreier.mytargets.test.utils.matchers.RecyclerViewMatcher.withRecyclerView;
import static org.hamcrest.Matchers.allOf;

@RunWith(AndroidJUnit4.class)
Expand Down Expand Up @@ -76,18 +76,16 @@ private void arrowSelectionTest(String type) {

onView(withText(R.string.add_arrow)).perform(nestedScrollTo(), click());
intended(hasComponent(EditArrowActivity.class.getName()));
onView(allOf(withId(R.id.action_save), isDisplayed())).perform(click());
save();

onView(allOf(withId(R.id.name),
withParent(withParent(withParent(withParent(withId(R.id.arrow))))), isDisplayed()))
onView(allOf(withId(R.id.name), isNestedChildOfView(withId(R.id.arrow)), isDisplayed()))
.check(matches(withText(R.string.my_arrow)));

// Check if arrow selection opens
onView(withId(R.id.arrow)).perform(nestedScrollTo(), click());
intended(hasComponent(ArrowActivity.class.getName()));
onView(allOf(withId(R.id.name), childAtPosition(childAtPosition(
IsInstanceOf.instanceOf(RelativeLayout.class), 1), 0),
isDisplayed())).check(matches(withText(R.string.my_arrow)));
onView(withRecyclerView(R.id.recyclerView).atPosition(0))
.check(matches(hasDescendant(withText(R.string.my_arrow))));
navigateUp();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
* Copyright (C) 2017 Florian Dreier
*
* This file is part of MyTargets.
*
* MyTargets is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* MyTargets is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

package de.dreier.mytargets.features.arrow;


import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.runner.RunWith;

import de.dreier.mytargets.R;
import de.dreier.mytargets.features.main.MainActivity;
import de.dreier.mytargets.test.base.UITestBase;
import de.dreier.mytargets.test.utils.rules.EmptyDbTestRule;

import static android.support.test.espresso.Espresso.onData;
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.closeSoftKeyboard;
import static android.support.test.espresso.action.ViewActions.longClick;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withSpinnerText;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static de.dreier.mytargets.test.utils.matchers.RecyclerViewMatcher.withRecyclerView;
import static de.dreier.mytargets.test.utils.matchers.ViewMatcher.supportFab;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.allOf;

@RunWith(AndroidJUnit4.class)
public class EditArrowTest extends UITestBase {

private ActivityTestRule<MainActivity> activityTestRule = new ActivityTestRule<>(
MainActivity.class);

@Rule
public final RuleChain rule = RuleChain.outerRule(new EmptyDbTestRule())
.around(activityTestRule);

@Test
public void editArrowTest() {
onView(allOf(withText(R.string.arrow), isDisplayed())).perform(click());

// Add new arrow and change some properties
onView(supportFab())
.perform(click());
onView(withId(R.id.name))
.perform(nestedScrollTo(), replaceText("Arrow"), closeSoftKeyboard());
onView(withText(R.string.more_fields))
.perform(nestedScrollTo(), click());
onView(withId(R.id.length))
.perform(nestedScrollTo(), replaceText("Length"));
onView(withId(R.id.diameter))
.perform(nestedScrollTo(), replaceText("680"), closeSoftKeyboard());

// Attempt to save and check if error is shown
save();
onView(withId(R.id.diameterTextInputLayout))
.check(matches(hasDescendant(withText(R.string.not_within_expected_range_mm))));

// Fix input
onView(withId(R.id.diameter))
.perform(nestedScrollTo(), replaceText("6.8"), closeSoftKeyboard());
save();

// Check if arrow has been saved
onView(withRecyclerView(R.id.recyclerView).atPosition(0))
.check(matches(hasDescendant(withText("Arrow"))));

// Open arrow again via CAB
onView(withRecyclerView(R.id.recyclerView).atPosition(0))
.perform(longClick());
clickContextualActionBarItem(R.id.action_edit, R.string.edit);

// Check if properties have been saved and are shown
onView(withId(R.id.length))
.check(matches(withText("Length")));
onView(withId(R.id.diameter))
.check(matches(withText("6.8")));
onView(withId(R.id.diameterUnit))
.check(matches(withSpinnerText("mm")));

// Change unit to inch
onView(withId(R.id.diameterUnit)).perform(click());
onData(allOf(is(instanceOf(String.class)), is("inch"))).perform(click());
save();

// Correct value and save
onView(withId(R.id.diameterTextInputLayout))
.check(matches(hasDescendant(withText(R.string.not_within_expected_range_inch))));
onView(withId(R.id.diameter))
.perform(nestedScrollTo(), replaceText("0.5"), closeSoftKeyboard());

// TODO
// onView(withId(R.id.coordinatorLayout)).perform(swipeDown());
// onView(supportFab()).perform(click());
// intendingImageCapture(getInstrumentation().getContext(),
// de.dreier.mytargets.debug.test.R.raw.mocked_image_capture);
// onView(withText(R.string.take_picture))
// .perform(click());
//
// allowPermissionsIfNeeded(activityTestRule.getActivity(), CAMERA);
//
// intendedImageCapture();

save();

onView(withRecyclerView(R.id.recyclerView).atPosition(0))
.perform(click());

onView(withId(R.id.diameter)).check(matches(withText("0.5")));
onView(withId(R.id.diameterUnit))
.check(matches(withSpinnerText("inch")));

// Change name and discard it
onView(withId(R.id.name))
.perform(nestedScrollTo(), replaceText("Arrrr"), closeSoftKeyboard());
navigateUp();

// Check if arrow has not been saved
onView(withRecyclerView(R.id.recyclerView).atPosition(0))
.check(matches(hasDescendant(withText("Arrow"))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@
* GNU General Public License for more details.
*/

package de.dreier.mytargets.views.selector;
package de.dreier.mytargets.features.bow;


import android.content.Intent;
import android.support.test.espresso.intent.rule.IntentsTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.widget.RelativeLayout;

import org.hamcrest.core.IsInstanceOf;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
Expand All @@ -41,11 +39,13 @@
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.intent.Intents.intended;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent;
import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withParent;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static de.dreier.mytargets.test.utils.PermissionGranter.allowPermissionsIfNeeded;
import static de.dreier.mytargets.test.utils.matchers.ParentViewMatcher.isNestedChildOfView;
import static de.dreier.mytargets.test.utils.matchers.RecyclerViewMatcher.withRecyclerView;
import static org.hamcrest.Matchers.allOf;

@RunWith(AndroidJUnit4.class)
Expand Down Expand Up @@ -76,19 +76,17 @@ private void bowSelectionTest(String type) {

onView(withText(R.string.add_bow)).perform(nestedScrollTo(), click());
intended(hasComponent(EditBowActivity.class.getName()));
onView(allOf(withId(R.id.action_save), isDisplayed())).perform(click());
save();

onView(allOf(withId(R.id.name),
withParent(withParent(withParent(withParent(withId(R.id.bow))))), isDisplayed()))
onView(allOf(withId(R.id.name), isNestedChildOfView(withId(R.id.bow)), isDisplayed()))
.check(matches(withText(R.string.my_bow)));

// Check if bow selection opens
onView(withId(R.id.bow)).perform(nestedScrollTo(), click());
intended(hasComponent(BowActivity.class.getName()));

onView(allOf(withId(R.id.name), childAtPosition(childAtPosition(
IsInstanceOf.instanceOf(RelativeLayout.class), 1), 0),
isDisplayed())).check(matches(withText(R.string.my_bow)));
onView(withRecyclerView(R.id.recyclerView).atPosition(0))
.check(matches(hasDescendant(withText(R.string.my_bow))));
navigateUp();
}
}
Loading

0 comments on commit 5b1ab44

Please sign in to comment.