quddusc | 2ef3952 | 2013-06-21 16:49:46 -0700 | [diff] [blame] | 1 | page.title=Setting Up Your Test Environment |
| 2 | trainingnavtop=true |
| 3 | |
| 4 | @jd:body |
| 5 | |
| 6 | <!-- This is the training bar --> |
| 7 | <div id="tb-wrapper"> |
| 8 | <div id="tb"> |
| 9 | |
| 10 | <h2>This lesson teaches you to</h2> |
| 11 | <ol> |
| 12 | <li><a href="#eclipse">Set Up Eclipse for Testing</a></li> |
| 13 | <li><a href="#cmdline">Set Up the Command Line Interface for Testing</a></li> |
| 14 | </ol> |
| 15 | |
| 16 | <h2>You should also read</h2> |
| 17 | <ul> |
| 18 | <li><a href="{@docRoot}sdk/index.html">Getting the SDK Bundle</a></li> |
| 19 | <li><a href="{@docRoot}tools/testing/testing_eclipse.html">Testing from Eclipse |
| 20 | with ADT</a></li> |
| 21 | <li><a href="{@docRoot}tools/testing/testing_otheride.html">Testing from Other |
| 22 | IDEs</a></li> |
| 23 | </ul> |
| 24 | |
| 25 | <h2>Try it out</h2> |
| 26 | <div class="download-box"> |
| 27 | <a href="http://developer.android.com/shareables/training/AndroidTestingFun.zip" |
| 28 | class="button">Download the demo</a> |
| 29 | <p class="filename">AndroidTestingFun.zip</p> |
| 30 | </div> |
| 31 | |
| 32 | </div> |
| 33 | </div> |
| 34 | |
| 35 | <p>Before you start writing and running your tests, you should set up your test |
| 36 | development environment. This lesson teaches you how to set up the Eclipse |
| 37 | IDE to build and run tests, and how to |
| 38 | build and run tests with the Gradle framework by using the command line |
| 39 | interface.</p> |
| 40 | |
| 41 | <p class="note"><strong>Note:</strong> To help you get started, the lessons are |
| 42 | based on Eclipse with the ADT plugin. However, for your own test development, you |
| 43 | are free to use the IDE of your choice or the command-line.</p> |
| 44 | |
| 45 | <h2 id="eclipse">Set Up Eclipse for Testing</h2> |
| 46 | <p>Eclipse with the Android Developer Tools (ADT) plugin provides an integrated |
| 47 | development environment for you to create, build, and run Android application |
| 48 | test cases from a graphical user interface (GUI). A convenient feature that |
| 49 | Eclipse provides is the ability to auto-generate a new test project that |
| 50 | corresponds with your Android application project</a>. |
| 51 | |
| 52 | <p>To set up your test environment in Eclipse:</p> |
| 53 | |
| 54 | <ol> |
| 55 | <li><a href="{@docRoot}sdk/installing/bundle.html">Download and install the |
| 56 | Eclipse ADT plugin</a>, if you haven’t installed it yet.</li> |
| 57 | <li>Import or create the Android application project that you want to test |
| 58 | against.</li> |
| 59 | <li>Generate a test project that corresponds to the application project under |
| 60 | test. To generate a test project for the app project that you imported:</p> |
| 61 | <ol type="a"> |
| 62 | <li>In the Package Explorer, right-click on your app project, then |
| 63 | select <strong>Android Tools</strong> > <strong>New Test Project</strong>.</li> |
| 64 | <li>In the New Android Test Project wizard, set the property |
| 65 | values for your test project then click <strong>Finish</strong>.</li> |
| 66 | </ol> |
| 67 | </li> |
| 68 | </ol> |
| 69 | <p>You should now be able to create, build, and run test |
| 70 | cases from your Eclipse environment. To learn how to perform these tasks in |
| 71 | Eclipse, proceed to <a href="activity-basic-testing.html">Creating and Running |
| 72 | a Test Case</a>.</p> |
| 73 | |
| 74 | <h2 id="cmdline">Set Up the Command Line Interface for Testing</h2> |
| 75 | <p>If you are using Gradle version 1.6 or higher as your build environment, you |
| 76 | can build and run your Android application tests from the command line by using |
| 77 | the Gradle Wrapper. Make sure that in your {@code gradle.build} file, the |
| 78 | <a href={@docRoot}guide/topics/manifest/uses-sdk-element.html#min>minSdkVersion</a> |
| 79 | attribute in the {@code defaultConfig} section is set to 8 or higher. You can |
| 80 | refer to the sample {@code gradle.build} file that is |
| 81 | included in the download bundle for this training class.</p> |
| 82 | <p>To run your tests with the Gradle Wrapper:</p> |
| 83 | <ol> |
| 84 | <li>Connect a physical Android device to your machine or launch the Android |
| 85 | Emulator.</li> |
| 86 | <li>Run the following command from your project directory: |
| 87 | <pre>./gradlew build connectedCheck</pre> |
| 88 | </li> |
| 89 | </ol> |
| 90 | <p>To learn more about using Gradle for Android testing, see the |
| 91 | <a href="//tools.android.com/tech-docs/new-build-system/user-guide#TOC-Testing">Gradle Plugin User Guide</a>.</p> |
| 92 | <p>To learn more about using command line tools other than Gradle for test |
| 93 | development, see |
| 94 | <a href="{@docRoot}tools/testing/testing_otheride.html">Testing from Other IDEs</a>.</p> |
| 95 | |