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.