You should start writing and launching Tests as part of your Android program development cycle. Writing good tests can help you find bugs earlier and give you confidence in your code.
A test case defines a collection of objects and methods that are used to initiate a variety of independent tests of each other. Test cases can be organized into test suites and initiated programmatically, with a repeatable rule, and the test framework provides a way to test the startup.
This lesson will teach you how to use the Android Custom test framework (based on the popular JUnit framework). You can write your test cases to verify the specified behavior in your program, and check for consistent performance across different Android devices. Your test case can also serve as an internal code document that describes the expected behavior of the application component.
Lessons
-
Configure your test environment
-
Learn how to create a test project.
-
Create and start a test case
-
Learn how to write test cases to validate the desired properties of the activity and launch it using the test launcher that comes with the Andorid framework
Instrumentation .
-
Testing the UI Component
-
Learn how to test the de behavior of special UI components in your activity.
-
Creating unit Tests
-
Learn how to perform unit tests to verify the behavior of an isolated activity.
-
Create a functional test
-
Learn how to perform functional tests to validate interactions between multiple activity.
Configure your test environment
Before you start writing and starting your tests, you should configure your test environment first. This lesson teaches you how to configure Eclipse to write and launch tests, and how to use the Gradle framework to build and launch tests using the command prompt line.
Note: to help you get started, this course is based on the eclipse and ADT plugins. However, for your personal testing environment, you are free to choose the IDE or choose the command prompt line method.
Configuring the Eclipse test environment
The Eclipse and ADT plug-ins provide an integrated development environment that enables you to create, build, and launch the graphical interface of your Android program test cases. Eclipse provides a very useful feature that will automatically generate a suitable new test project for your Android program project.
Configuration steps:
- Download and install the ADT plugin if you haven't installed it yet.
- Import or create an Android project that you like to create.
- To build a test project that fits your project, you need to create (build) a test project for your project:
- On the left side of the bundle Management Area (package Explorer), right-click on your project and select Android Tools > New Test Project.
- In the New Create Project dialog box (new Android Test project), set the value of the corresponding property for your project and click Finish.
You should now is able to create, build, and run test cases from your Eclipse environment. Read more about creating and Running a Test case.
Test environment for how command prompt lines are configured
If you use Gradle version 1.6 or later as your build environment, you can use Gradle wrapper to configure your test environment. Make sure that the gradle.build minsdkversion property in your file, in the Defaultconfig node, is set to 8 or higher. You can refer to the example sample file in the training course included in the download file gradle.build .
To start a test using Gradle Wrapper:
- Connect a physical device to your machine, or open an emulator.
- In your project folder, execute the following command:
./Gradlew build Connectedcheck
To learn more using Gradle for Android testing, refer to Gradle Plugin User Guide.
To learn more using command line tools other than Gradle for test development, see testing from other IDEs.
Android Chinese translator-Test your Android Activity