Android's automated testing framework is not much to choose from, then Robotium (https://code.google.com/p/robotium/), its syntax and ease of use is quite like the kif we use in iOS.
The official document does not mention how to build it in Android Studio, and later found an answer in stack overflow: http://stackoverflow.com/questions/23275602/ robotium-with-android-studio/23295849#23295849
In my own analysis, it is quite simple to build Robotium in Android Studio:
1, Build.gradle, dependencies under increase Androidtestcompile ' com.jayway.android.robotium:robotium-solo:5.1 '. If this configuration is missing, the Robotium package will not be available in the test code.
2, the code structure of our project is old-fashioned, so we need to re-set the test address, that is, under android.sourcesets new Androidtest.setroot (' tests '). You can take other names outside of tests, and then set up this folder in the same class as build.gradle, without any additional settings, the test code placement needs to follow the new structure, that is, Tests\java. If it is not configured correctly, the test code will not be visible.
In addition to the code changes, if you want to run in Android Studio, you also need additional configuration: Menu run, Edit configuration, the new entry under Android tests, and then properly configured, you can: choose which module, Select the range of tests (module or package, etc.) and select Target Device. This is a configuration thing and there is no way to commit to git.
Here is a simple example, our app in the test environment will first pop up a selected environment Alertdialog, so need to Clickontext:
- /**
- * Created by Samuel Cai on 5/20/14.
- */
- Public class Mainactivitytest extends ActivityInstrumentationTestCase2 {
- private solo solo;
- Public mainactivitytest () {
- super (logoactivity. Class);
- }
- @Override
- public void SetUp () throws Exception {
- Super.setup ();
- Solo = new solo (Getinstrumentation (), getactivity ());
- }
- public void Testnavigatetohomescreen () throws Exception {
- //choose Environment
- Solo.waitfordialogtoopen ();
- Solo.clickontext ("QA");
- Solo.clickonbutton ("OK");
- //assert Home screen finished loading.
- Asserttrue (Solo.waitfortext ("diapering"));
- }
- }
Transferred from: http://m.blog.csdn.net/blog/hongaiyan/39676657#
Go Build an automated test framework in Android Studio Robotium