Permalink
Browse files

Adds 2 new samples (Idling Resources and RecyclerViews for Espresso) …

…+ version bump

Change-Id: Ida0e8d4363b3e6b2819e5f8ea5fb86d2475da6a6
1 parent 22100ea commit e34c14775495dc13ede80ed6eca422db5eabb267 @JoseAlcerreca JoseAlcerreca committed Aug 26, 2016
Showing with 1,949 additions and 66 deletions.
  1. +4 −0 README.md
  2. +4 −4 integration/ServiceTestRuleSample/app/build.gradle
  3. +7 −0 integration/ServiceTestRuleSample/build.gradle
  4. +6 −6 runner/AndroidJunitRunnerSample/app/build.gradle
  5. +8 −0 runner/AndroidJunitRunnerSample/build.gradle
  6. +6 −6 ui/espresso/BasicSample/app/build.gradle
  7. +8 −0 ui/espresso/BasicSample/build.gradle
  8. +6 −6 ui/espresso/CustomMatcherSample/app/build.gradle
  9. +8 −0 ui/espresso/CustomMatcherSample/build.gradle
  10. +6 −6 ui/espresso/DataAdapterSample/app/build.gradle
  11. +8 −0 ui/espresso/DataAdapterSample/build.gradle
  12. +6 −0 ui/espresso/IdlingResourceSample/.gitignore
  13. +24 −0 ui/espresso/IdlingResourceSample/README.md
  14. +52 −0 ui/espresso/IdlingResourceSample/app/build.gradle
  15. +79 −0 ...idTest/java/com/example/android/testing/espresso/IdlingResourceSample/ChangeTextBehaviorTest.java
  16. +35 −0 ui/espresso/IdlingResourceSample/app/src/main/AndroidManifest.xml
  17. +63 −0 ...om/example/android/testing/espresso/IdlingResourceSample/IdlingResource/SimpleIdlingResource.java
  18. +88 −0 ...ple/app/src/main/java/com/example/android/testing/espresso/IdlingResourceSample/MainActivity.java
  19. +65 −0 ...e/app/src/main/java/com/example/android/testing/espresso/IdlingResourceSample/MessageDelayer.java
  20. BIN ui/espresso/IdlingResourceSample/app/src/main/res/drawable-hdpi/ic_launcher.png
  21. BIN ui/espresso/IdlingResourceSample/app/src/main/res/drawable-mdpi/ic_launcher.png
  22. BIN ui/espresso/IdlingResourceSample/app/src/main/res/drawable-xhdpi/ic_launcher.png
  23. BIN ui/espresso/IdlingResourceSample/app/src/main/res/drawable-xxhdpi/ic_launcher.png
  24. BIN ui/espresso/IdlingResourceSample/app/src/main/res/drawable-xxxhdpi/ic_launcher.png
  25. +52 −0 ui/espresso/IdlingResourceSample/app/src/main/res/layout/activity_main.xml
  26. +19 −0 ui/espresso/IdlingResourceSample/app/src/main/res/values-v13/styles.xml
  27. +19 −0 ui/espresso/IdlingResourceSample/app/src/main/res/values-v21/styles.xml
  28. +22 −0 ui/espresso/IdlingResourceSample/app/src/main/res/values-w820dp/dimens.xml
  29. +21 −0 ui/espresso/IdlingResourceSample/app/src/main/res/values/dimens.xml
  30. +23 −0 ui/espresso/IdlingResourceSample/app/src/main/res/values/strings.xml
  31. +20 −0 ui/espresso/IdlingResourceSample/app/src/main/res/values/styles.xml
  32. +43 −0 ui/espresso/IdlingResourceSample/build.gradle
  33. BIN ui/espresso/IdlingResourceSample/gradle/wrapper/gradle-wrapper.jar
  34. +22 −0 ui/espresso/IdlingResourceSample/gradle/wrapper/gradle-wrapper.properties
  35. +164 −0 ui/espresso/IdlingResourceSample/gradlew
  36. +90 −0 ui/espresso/IdlingResourceSample/gradlew.bat
  37. +17 −0 ui/espresso/IdlingResourceSample/settings.gradle
  38. +7 −7 ui/espresso/IntentsAdvancedSample/app/build.gradle
  39. +8 −0 ui/espresso/IntentsAdvancedSample/build.gradle
  40. +8 −8 ui/espresso/IntentsBasicSample/app/build.gradle
  41. +8 −0 ui/espresso/IntentsBasicSample/build.gradle
  42. +6 −6 ui/espresso/MultiWindowSample/app/build.gradle
  43. +8 −0 ui/espresso/MultiWindowSample/build.gradle
  44. +6 −0 ui/espresso/RecyclerViewSample/.gitignore
  45. +7 −0 ui/espresso/RecyclerViewSample/README.md
  46. +50 −0 ui/espresso/RecyclerViewSample/app/build.gradle
  47. +92 −0 ...roidTest/java/com/example/android/testing/espresso/RecyclerViewSample/RecyclerViewSampleTest.java
  48. +35 −0 ui/espresso/RecyclerViewSample/app/src/main/AndroidManifest.xml
  49. +100 −0 ...mple/app/src/main/java/com/example/android/testing/espresso/RecyclerViewSample/CustomAdapter.java
  50. +52 −0 ...ample/app/src/main/java/com/example/android/testing/espresso/RecyclerViewSample/MainActivity.java
  51. BIN ui/espresso/RecyclerViewSample/app/src/main/res/drawable-hdpi/ic_launcher.png
  52. BIN ui/espresso/RecyclerViewSample/app/src/main/res/drawable-mdpi/ic_launcher.png
  53. BIN ui/espresso/RecyclerViewSample/app/src/main/res/drawable-xhdpi/ic_launcher.png
  54. BIN ui/espresso/RecyclerViewSample/app/src/main/res/drawable-xxhdpi/ic_launcher.png
  55. BIN ui/espresso/RecyclerViewSample/app/src/main/res/drawable-xxxhdpi/ic_launcher.png
  56. +30 −0 ui/espresso/RecyclerViewSample/app/src/main/res/layout/activity_main.xml
  57. +30 −0 ui/espresso/RecyclerViewSample/app/src/main/res/layout/text_row_item.xml
  58. +19 −0 ui/espresso/RecyclerViewSample/app/src/main/res/values-v13/styles.xml
  59. +19 −0 ui/espresso/RecyclerViewSample/app/src/main/res/values-v21/styles.xml
  60. +22 −0 ui/espresso/RecyclerViewSample/app/src/main/res/values-w820dp/dimens.xml
  61. +22 −0 ui/espresso/RecyclerViewSample/app/src/main/res/values/dimens.xml
  62. +22 −0 ui/espresso/RecyclerViewSample/app/src/main/res/values/strings.xml
  63. +20 −0 ui/espresso/RecyclerViewSample/app/src/main/res/values/styles.xml
  64. +43 −0 ui/espresso/RecyclerViewSample/build.gradle
  65. BIN ui/espresso/RecyclerViewSample/gradle/wrapper/gradle-wrapper.jar
  66. +22 −0 ui/espresso/RecyclerViewSample/gradle/wrapper/gradle-wrapper.properties
  67. +164 −0 ui/espresso/RecyclerViewSample/gradlew
  68. +90 −0 ui/espresso/RecyclerViewSample/gradlew.bat
  69. +17 −0 ui/espresso/RecyclerViewSample/settings.gradle
  70. +6 −6 ui/espresso/WebBasicSample/app/build.gradle
  71. +8 −0 ui/espresso/WebBasicSample/build.gradle
  72. +4 −4 ui/uiautomator/BasicSample/app/build.gradle
  73. +9 −0 ui/uiautomator/BasicSample/build.gradle
  74. +3 −3 unit/BasicSample/app/build.gradle
  75. +6 −0 unit/BasicSample/build.gradle
  76. +4 −4 unit/BasicUnitAndroidTest/app/build.gradle
  77. +7 −0 unit/BasicUnitAndroidTest/build.gradle
View
@@ -11,12 +11,16 @@ A collection of samples demonstrating different frameworks and techniques for au
**[DataAdapterSample](https://github.com/googlesamples/android-testing/blob/master/ui/espresso/DataAdapterSample)** - Showcases the `onData()` entry point for Espresso, for lists and AdapterViews
+**[IdlingResourceSample](https://github.com/googlesamples/android-testing/blob/master/ui/espresso/IdlingResourceSample)** - Synchronization with background jobs
+
**[IntentsBasicSample](https://github.com/googlesamples/android-testing/blob/master/ui/espresso/IntentsBasicSample)** - Basic usage of `intended()` and `intending()`
**[IntentsAdvancedSample](https://github.com/googlesamples/android-testing/blob/master/ui/espresso/IntentsAdvancedSample)** - Simulates a user fetching a bitmap using the camera
**[MultiWindowSample](https://github.com/googlesamples/android-testing/blob/master/ui/espresso/MultiWindowSample)** - Shows how to point Espresso to different windows
+**[RecyclerViewSample](https://github.com/googlesamples/android-testing/blob/master/ui/espresso/RecyclerViewSample)** - RecyclerView actions for Espresso
+
**[WebBasicSample](https://github.com/googlesamples/android-testing/blob/master/ui/espresso/WebBasicSample)** - Use Espresso-web to interact with WebViews
**[BasicSampleBundled](https://github.com/googlesamples/android-testing/blob/master/ui/espresso/BasicSampleBundled)** - Basic sample for Eclipse and other IDEs
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 24
- buildToolsVersion '24.0.1'
+ buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
applicationId "com.example.android.testing.integrationtesting.ServiceTestRuleSample"
minSdkVersion 10
@@ -22,7 +22,7 @@ android {
dependencies {
// Testing-only dependencies
// Force usage of support annotations in the test app, since it is internally used by the runner module.
- androidTestCompile 'com.android.support:support-annotations:24.1.1'
- androidTestCompile 'com.android.support.test:runner:0.5'
- androidTestCompile 'com.android.support.test:rules:0.5'
+ androidTestCompile 'com.android.support:support-annotations:' + rootProject.supportLibVersion;
+ androidTestCompile 'com.android.support.test:runner:' + rootProject.runnerVersion;
+ androidTestCompile 'com.android.support.test:rules:' + rootProject.rulesVersion;
}
@@ -17,3 +17,10 @@ allprojects {
jcenter()
}
}
+
+ext {
+ buildToolsVersion = "24.0.1"
+ supportLibVersion = "24.2.0"
+ runnerVersion = "0.5"
+ rulesVersion = "0.5"
+}
@@ -3,7 +3,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 24
- buildToolsVersion '24.0.1'
+ buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
applicationId "com.example.android.testing.androidjunitrunnersample"
minSdkVersion 8
@@ -25,13 +25,13 @@ android {
dependencies {
// App's dependencies, including test
- compile 'com.android.support:support-annotations:24.1.1'
+ compile 'com.android.support:support-annotations:' + rootProject.supportLibVersion;
compile 'com.google.guava:guava:18.0'
// Testing-only dependencies
// Force usage of support annotations in the test app, since it is internally used by the runner module.
- androidTestCompile 'com.android.support:support-annotations:24.1.1'
- androidTestCompile 'com.android.support.test:runner:0.5'
- androidTestCompile 'com.android.support.test:rules:0.5'
- androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
+ androidTestCompile 'com.android.support:support-annotations:' + rootProject.supportLibVersion;
+ androidTestCompile 'com.android.support.test:runner:' + rootProject.runnerVersion;
+ androidTestCompile 'com.android.support.test:rules:' + rootProject.rulesVersion;
+ androidTestCompile 'com.android.support.test.espresso:espresso-core:' + rootProject.espressoVersion;
}
@@ -17,3 +17,11 @@ allprojects {
jcenter()
}
}
+
+ext {
+ buildToolsVersion = "24.0.1"
+ supportLibVersion = "24.2.0"
+ runnerVersion = "0.5"
+ rulesVersion = "0.5"
+ espressoVersion = "2.2.2"
+}
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 24
- buildToolsVersion '24.0.1'
+ buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
applicationId "com.example.android.testing.espresso.BasicSample"
minSdkVersion 10
@@ -21,12 +21,12 @@ android {
dependencies {
// App dependencies
- compile 'com.android.support:support-annotations:24.1.1'
+ compile 'com.android.support:support-annotations:' + rootProject.supportLibVersion;
compile 'com.google.guava:guava:18.0'
// Testing-only dependencies
// Force usage of support annotations in the test app, since it is internally used by the runner module.
- androidTestCompile 'com.android.support:support-annotations:24.1.1'
- androidTestCompile 'com.android.support.test:runner:0.5'
- androidTestCompile 'com.android.support.test:rules:0.5'
- androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
+ androidTestCompile 'com.android.support:support-annotations:' + rootProject.supportLibVersion;
+ androidTestCompile 'com.android.support.test:runner:' + rootProject.runnerVersion;
+ androidTestCompile 'com.android.support.test:rules:' + rootProject.rulesVersion;
+ androidTestCompile 'com.android.support.test.espresso:espresso-core:' + rootProject.espressoVersion;
}
@@ -17,3 +17,11 @@ allprojects {
jcenter()
}
}
+
+ext {
+ buildToolsVersion = "24.0.1"
+ supportLibVersion = "24.2.0"
+ runnerVersion = "0.5"
+ rulesVersion = "0.5"
+ espressoVersion = "2.2.2"
+}
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 24
- buildToolsVersion '24.0.1'
+ buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
applicationId "com.example.android.testing.espresso.CustomMatcherSample"
minSdkVersion 10
@@ -27,12 +27,12 @@ android {
dependencies {
// App dependencies
- compile 'com.android.support:support-annotations:24.1.1'
+ compile 'com.android.support:support-annotations:' + rootProject.supportLibVersion;
compile 'com.google.guava:guava:18.0'
// Testing-only dependencies
// Force usage of support annotations in the test app, since it is internally used by the runner module.
- androidTestCompile 'com.android.support:support-annotations:24.1.1'
- androidTestCompile 'com.android.support.test:runner:0.5'
- androidTestCompile 'com.android.support.test:rules:0.5'
- androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
+ androidTestCompile 'com.android.support:support-annotations:' + rootProject.supportLibVersion;
+ androidTestCompile 'com.android.support.test:runner:' + rootProject.runnerVersion;
+ androidTestCompile 'com.android.support.test:rules:' + rootProject.rulesVersion;
+ androidTestCompile 'com.android.support.test.espresso:espresso-core:' + rootProject.espressoVersion;
}
@@ -17,3 +17,11 @@ allprojects {
jcenter()
}
}
+
+ext {
+ buildToolsVersion = "24.0.1"
+ supportLibVersion = "24.2.0"
+ runnerVersion = "0.5"
+ rulesVersion = "0.5"
+ espressoVersion = "2.2.2"
+}
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 24
- buildToolsVersion '24.0.1'
+ buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
applicationId "com.example.android.testing.espresso.DataAdapterSample"
minSdkVersion 10
@@ -18,12 +18,12 @@ android {
dependencies {
// App dependencies
- compile 'com.android.support:support-annotations:24.1.1'
+ compile 'com.android.support:support-annotations:' + rootProject.supportLibVersion;
compile 'com.google.guava:guava:18.0'
// Testing-only dependencies
// Force usage of support annotations in the test app, since it is internally used by the runner module.
- androidTestCompile 'com.android.support:support-annotations:24.1.1'
- androidTestCompile 'com.android.support.test:runner:0.5'
- androidTestCompile 'com.android.support.test:rules:0.5'
- androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
+ androidTestCompile 'com.android.support:support-annotations:' + rootProject.supportLibVersion;
+ androidTestCompile 'com.android.support.test:runner:' + rootProject.runnerVersion;
+ androidTestCompile 'com.android.support.test:rules:' + rootProject.rulesVersion;
+ androidTestCompile 'com.android.support.test.espresso:espresso-core:' + rootProject.espressoVersion;
}
@@ -17,3 +17,11 @@ allprojects {
jcenter()
}
}
+
+ext {
+ buildToolsVersion = "24.0.1"
+ supportLibVersion = "24.2.0"
+ runnerVersion = "0.5"
+ rulesVersion = "0.5"
+ espressoVersion = "2.2.2"
+}
@@ -0,0 +1,6 @@
+.gradle
+local.properties
+.idea
+.DS_Store
+build
+*.iml
@@ -0,0 +1,24 @@
+# Basic Idling Resource sample for Espresso
+
+The centerpiece of Espresso is its ability to seamlessly synchronize all test operations with the application under test. By default, Espresso waits for UI events in the current message queue to be processed and default AsyncTasks* to complete before it moves on to the next test operation. This should address the majority of application/test synchronization in your application.
+
+However, there are instances where applications perform background operations (such as communicating with web services) via non-standard means; for example: direct creation and management of threads.
+
+This sample showcases how to implement a very simple IdlingResource interface and expose it to a test. The application shows a message to the user after a delay that is executed on a different thread.
+
+Consider using the CountingIdlingResource class from the espresso-contrib package. It's a very easy to use Idling Resource implementation that can handle multiple parallel operations keeping track of the number of pending operations.
+
+Note that the `espresso-idling-resource` dependency is added into the `compile` scope:
+
+```
+ androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
+ compile 'com.android.support.test.espresso:espresso-idling-resource:2.2.2'
+```
+
+This dependency and its implementation are added to the app under test but are not needed in production. This bloats the released app but it's kept this way to simplify the sample. You can:
+ * ProGuard/shrink your release build to minimize impact
+ * Use a build type or product flavor for tests and remove the Idling Resource classes in the production/release variant.
+ * Add the dependency to `androidTestCompile` and inject an IdlingResource-aware MessageDelayer from the test.
+ * Keep them, since the added methods and size are insignificant.
+
+
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2016, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+apply plugin: 'com.android.application'
+
+android {
+ compileSdkVersion 24
+ buildToolsVersion rootProject.buildToolsVersion
+
+ defaultConfig {
+ applicationId "com.example.android.testing.espresso.IdlingResourceSample"
+ minSdkVersion 10
+ targetSdkVersion 24
+ versionCode 1
+ versionName "1.0"
+
+ testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
+ }
+ lintOptions {
+ abortOnError false
+ }
+}
+
+dependencies {
+ // App dependencies
+ compile 'com.android.support:support-annotations:' + rootProject.supportLibVersion;
+ compile 'com.google.guava:guava:18.0'
+
+ // Testing-only dependencies
+ androidTestCompile 'com.android.support.test:runner:' + rootProject.runnerVersion
+ androidTestCompile 'com.android.support.test:rules:' + rootProject.rulesVersion;
+ androidTestCompile 'com.android.support.test.espresso:espresso-core:' + rootProject.espressoVersion;
+ // Note that espresso-idling-resource is used in the code under test.
+ compile 'com.android.support.test.espresso:espresso-idling-resource:' + rootProject.espressoVersion;
+
+ // Force usage of support annotations in the test app, since it is internally used by the
+ // runner module.
+ androidTestCompile 'com.android.support:support-annotations:' + rootProject.supportLibVersion;
+}
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2016, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.testing.espresso.IdlingResourceSample;
+
+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.typeText;
+import static android.support.test.espresso.assertion.ViewAssertions.matches;
+import static android.support.test.espresso.matcher.ViewMatchers.withId;
+import static android.support.test.espresso.matcher.ViewMatchers.withText;
+
+import android.support.test.espresso.Espresso;
+import android.support.test.espresso.IdlingResource;
+import android.support.test.rule.ActivityTestRule;
+import android.support.test.runner.AndroidJUnit4;
+import android.test.suitebuilder.annotation.LargeTest;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Same as Espresso's BasicSample, but with an Idling Resource to help with synchronization.
+ */
+@RunWith(AndroidJUnit4.class)
+@LargeTest
+public class ChangeTextBehaviorTest {
+
+ private static final String STRING_TO_BE_TYPED = "Espresso";
+
+ @Rule
+ public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(
+ MainActivity.class);
+
+ private IdlingResource mIdlingResource;
+
+ @Before
+ public void registerIdlingResource() {
+ mIdlingResource = mActivityRule.getActivity().getIdlingResource();
+ // To prove that the test fails, omit this call:
+ Espresso.registerIdlingResources(mIdlingResource);
+ }
+
+ @Test
+ public void changeText_sameActivity() {
+ // Type text and then press the button.
+ onView(withId(R.id.editTextUserInput))
+ .perform(typeText(STRING_TO_BE_TYPED), closeSoftKeyboard());
+ onView(withId(R.id.changeTextBt)).perform(click());
+
+ // Check that the text was changed.
+ onView(withId(R.id.textToBeChanged)).check(matches(withText(STRING_TO_BE_TYPED)));
+ }
+
+ @After
+ public void unregisterIdlingResource() {
+ if (mIdlingResource != null) {
+ Espresso.unregisterIdlingResources(mIdlingResource);
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit e34c147

Please sign in to comment.