in the in Development JUnit Testing makes it easy to find and handle problems as early as possible, and it's very easy to use, just import junit test-related jar packages and create test classes to test your business capabilities without having to test your code to add an output statement to your code. It should be noted that the test method written can only be public void and no parameters, and in the test method will do whatever it takes.
@Test Public void Testadd () { new Demo (); System.out.println (D.add);}
Testing in the Android environment does not seem to be convenient, and you need to configure the test in your app project configuration to write the test class. Fortunately, Google provides an ADT integration environment for everyone, and this problem is not a problem.
Next, take a look at an Android project to do the JUnit test configuration steps:
1. Find the <application></application> section in the project's Androidmanifest.xml file toadd:
<android:name= "Android.test.runner"/>
2, found in the project Androidmanifest.xml file <manifest></ Manifest > section, where to add:
< Intent-filter > < android:name= "Android.intent.action.MAIN"/> < android:name= "Android.intent.category.LAUNCHER"/></ Intent-filter >
3, create a test class, inherit Androidtestcase, in which to write test methods. Such as:
Public void throws Exception { new personservice (); Ps.getfirstname (); } Public void throws Exception { new personservice (); Assert.assertequals (2, Ps.calc ()); }
4. Finally, the Android JUnit test,junit window will display a red or green bar, and you'll see some information in the console, such as:
[2014-05-26 17:04:47-slidedemo]------------------------------[2014-05-26 17:04:47-slidedemo] Android launch! [2014-05-26 17:04:47-slidedemo] adb is running normally. [2014-05-26 17:04:47-slidedemo] Performing Android.test.InstrumentationTestRunner JUnit launch[2014-05-26 17:04:47-slidedemo] Automatic Target Mode: Using existing emulator ' emulator-5554 ' running compatible AVD ' XT531 ' [2014-05-26 17:04:47-slidedemo] uploading Slidedem o.apk onto device ' emulator-5554 ' [2014-05-26 17:04:48-slidedemo] Installing slidedemo.apk ... [2014-05-26 17:04:49-slidedemo] success! [2014-05-26 17:04:49-slidedemo] Launching instrumentation Android.test.InstrumentationTestRunner on emulator-5554[2014-05-26 17:04:50-slidedemo] Sending test information to eclipse[2014-05-26 17:04:50-slidedemo] test run finished