Android翻译_测试最佳实践_测试你的Activity_建立测试环境

本章翻译说明:以为时间精力有限,在这部分完全按照Android 文档翻译,并对容易理解的直接复制,做一定的注释说明,需要翻译做到英汉对照。

本章源地址:http://developer.android.com/training/activity-testing/preparing-activity-testing.html

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.

//在Eclipse里面建立一个测试工程即可,最新的ADT是 右键->new->other->搜索Android Test project->选择需要被测试的目标工程->Finish.

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.buildfile, the minSdkVersion attribute in the defaultConfig section is set to 8 or higher. You can refer to the samplegradle.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.

posted @ 2015-08-24 16:27  RainFool  阅读(181)  评论(0编辑  收藏  举报