Android practice-quickly build an Android jUnit test environment

Source: Internet
Author: User

Quickly build an Android jUnit test environment

Classification of tests:Source code transparency: black box testing: Unknown source code, relational user operations. White-box testing: Write test cases based on source code. Test granularity: method test: function test unit test: jUnit test integration test: intergration test times: smoke test (Android monkey) stress test: pressure test Android monkey:Android monkey is a tool used in Android to perform the smoke test. It simulates a monkey clicking the Android mobile phone at random. Usage: cmd --> adb shell --> monkey [times] [prerequisite: configured .. /sdk/platform-tools/environment variable]
Configure the jUnit environment:
1. Compile the test class to inherit the AndroidTestCase class. When writing the test method, you should throw the exception.
Public class TestArithmeticService extends AndroidTestCase {/*** test the code of the add method. You need to throw the Exception to ** @ throws Exception */public void testAdd () throws Exception {ArithmeticService service = new ArithmeticService (); int retsult = service. add (5, 15); assertEquals (22, retsult );}}
2. Configure the AndroidManifest. xml file
 
 
  
 
 
 
AndroidManifest. xml file:
 <Manifest xmlns: android = "http://schemas.android.com/apk/res/android" package = "com. meritit. dm. junittest" android: versionCode = "1" android: versionName = "1.0">
     
     
     
             
 <Uses-library android: name = "android. test. runner "/> <activity android: name =" com. meritit. dm. junittest. mainActivity "android: label =" @ string/app_name "> <intent-filter> <action android: name =" android. intent. action. MAIN "/> <category android: name =" android. intent. category. LAUNCHER "/>
         
     
 
In addition, you can create an Android Test Project. The above configuration is automatically generated.

Related Article

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.