If you are using Espresso with Eclipse, try this sample first.
This project uses Eclipse and ADT to build and run the tests.
- Download the project code, preferably using
git clone. - Check out the static JAR files required to run the Espresso tests in the libs/ folder of the project
- Run the ./remove_license.sh script to remove duplicated LICENSE.txt files. This step is required because some of the test dependencies contain LICENSE.txt files which result in this build error: "Error generating final archive: Found duplicate file for APK: LICENSE.txt". The problem is that the same LICENSE.TXT file is found multiple times and AAPT does not know how to resolve this conflict.
- Check out the relevant code:
- The application under test is located in
src/ - Tests are in
tests/
- The application under test is located in
- Create the test configuration with a custom runner:
android.support.test.runner.AndroidJUnitRunner- Open Run menu | Run Configurations
- Click on Android JUnit Test
- Add a new configuration by pressing the "new launch configuration" button
- Select your project by clicking the "Browse" button
- Add a Specific instrumentation runner:
android.support.test.runner.AndroidJUnitRunner
- Connect a device or start an emulator
- Turn animations off. (On your device, under Settings->Developer options disable the following 3 settings: "Window animation scale", "Transition animation scale" and "Animator duration scale")
- Run the newly created configuration
The application will be started on the device/emulator and a series of actions will be performed automatically.