Book Image

Learning Android Application Testing

Book Image

Learning Android Application Testing

Overview of this book

Table of Contents (16 chapters)
Learning Android Application Testing
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Testing with Espresso


Testing UI components can be difficult. Knowing when a view has been inflated or ensuring you don't access views on the wrong thread can lead to strange behavior and flaky tests. This is why Google has released a helper library for UI-related instrumentation tests called Espresso (https://code.google.com/p/android-test-kit/wiki/Espresso).

Adding the Espresso library JAR can be achieved by adding to the /libs folder, but to make it easier for Gradle users, Google released a version to their Maven repository (consider yourselves lucky users because this was not available before version 2.0). When using Espresso, you need to use the bundled TestRunner as well. Therefore, the setup becomes:

dependencies {
// other dependencies
androidTestCompile('com.android.support.test.espresso:espresso-core:2.0')
}
android {
    defaultConfig {
    // other configuration
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
// Annoyingly there is a overlap with...