Android JUnit test--Run test code in bulk

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.