There are three elements of writing Android test cases, one is "Android Simulator device" (to display the UI), the other is "Uiautomatorviewer.bat" (to locate the elements on the UI), and the third is "Robotium" The class that is provided in (to interact with the UI element). After you have written your Android test case, you can run the test code in batches from the Android JUnit test. A total of four steps--
The first step: Write a Suite Class (The suite contains the specified test cases, add the Sendinfotest class as a test case to the suite, Logintest this class is not added to the suite because it was commented):
Packagecom.renren.test.suites;Importcom.renren.test.SendInfoTest;ImportJunit.framework.TestSuite; Public classSuitefortest {
Public StaticTestSuite Gettestsuite () {TestSuite Suite=NewTestSuite (); //Suite.addtestsuite (logintest.class);Suite.addtestsuite (sendinfotest.class); returnSuite; }
}
Step two: Write a runner class that runs the specified Suite,runner class and inherits the Instrumentationtestrunner class, and overrides the Getalltests method:
Packagecom.renren.test.runners;Importcom.renren.test.suites.SuiteForTest;ImportAndroid.test.InstrumentationTestRunner;ImportJunit.framework.TestSuite; Public classRunner1extendsInstrumentationtestrunner {@Override PublicTestSuite getalltests () {TestSuite Suite=NewTestSuite (); Suite.addtest (Suitefortest.gettestsuite ()); returnSuite; }}
Step three: Modify the Androidmanifest.xml file and add a instrumentation tag, such as:
Where the value of "Android:name" fills in "package name +runner class name in Project","Android:targetpackage" value fills in the package name of the app under test, this package name is not the package name in the project where the runner class is located. It is the package name (which is generated with the main activity name) that is generated after the app--is tested and the APK is re-signed:
Fourth step: Right-click on the project->run as->run configurations-> select Android JUnit Test and click on the "New button" above to create a new Android JUnit called "Formyrenren" Test,instrumentation Runner Select the Runner class that we created ourselves, click run-> Batch Run test.
Attached-a way to get the package name and main activity name of the app under test:
1. Download "Apktool.jar" and "Apktool.bat" files.
2. Build-tools path on Android (My is C:\Users\Administration\AppData\Local\Android \android-sdk\build-tools\ ) under Select a higher version of the folder (I chose 23.0.2) to open, find the "aapt.exe" file;
3. Copy and paste the three files "Apktool.jar", "Apktool.bat" and "Aapt.exe" into the "C:\Windows" directory:
4, start the cmd command line, enter "AAPT dump badging apk in the local pathname" (I use the Renren re-sign apk), as follows:
We found the package name and activity name of the APK separately, which corresponds to the package name and main activity name generated after the APK was re-signed.
Android JUnit test--Run test code in bulk