Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)

Setting Up Your Test Environment

Before you start writing and running your tests, you should set up your test development environment. This lesson teaches you how to set up the Eclipse IDE to build and run tests, and how to build and run tests with the Gradle framework by using the command line interface.

Note: To help you get started, the lessons are based on Eclipse with the ADT plugin. However, for your own test development, you are free to use the IDE of your choice or the command-line.

Set Up Eclipse for Testing

Eclipse with the Android Developer Tools (ADT) plugin provides an integrated development environment for you to create, build, and run Android application test cases from a graphical user interface (GUI). A convenient feature that Eclipse provides is the ability to auto-generate a new test project that corresponds with your Android application project .

To set up your test environment in Eclipse:

  1. Download and install the Eclipse ADT plugin , if you haven’t installed it yet.
  2. Import or create the Android application project that you want to test against.
  3. Generate a test project that corresponds to the application project under test. To generate a test project for the app project that you imported:
    1. In the Package Explorer, right-click on your app project, then select Android Tools > New Test Project .
    2. In the New Android Test Project wizard, set the property values for your test project then click Finish .

You should now be able to create, build, and run test cases from your Eclipse environment. To learn how to perform these tasks in Eclipse, proceed to Creating and Running a Test Case .

Set Up the Command Line Interface for Testing

If you are using Gradle version 1.6 or higher as your build environment, you can build and run your Android application tests from the command line by using the Gradle Wrapper. Make sure that in your gradle.build file, the minSdkVersion attribute in the defaultConfig section is set to 8 or higher. You can refer to the sample gradle.build file that is included in the download bundle for this training class.

To run your tests with the Gradle Wrapper:

  1. Connect a physical Android device to your machine or launch the Android Emulator.
  2. Run the following command from your project directory:
             ./gradlew build connectedCheck
            

To learn more about using Gradle for Android testing, see the Gradle Plugin User Guide .

To learn more about using command line tools other than Gradle for test development, see Testing from Other IDEs .