Android中的Junit单元测试


1、修改 AndroidManifest.xml        

 

	...
	<!-- [增加] android:targetPackage与manifest节点中的package属性相同 -->
	<instrumentation
        android:name="android.test.InstrumentationTestRunner"
        android:targetPackage="com.company.io" />
	
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
         <!-- [增加] -->
	        <uses-library android:name="android.test.runner" />
	...
	</application>
 

2、在对应的包(targetPackage)下面建立测试类需继承自AndroidTestCase

public class PersonSaxTest extends AndroidTestCase {
	private static final String TAG = "PersonSaxTest";

	public void testSAXgetPersons() throws Throwable {
		InputStream inStream = this.getClass()
				.getClassLoader()
				.getResourceAsStream("person.xml");

		SaxPersonService service = new SaxPersonService();
		List<Person> personList = service.getPersons(inStream);
		for (Person person : personList) {
			Log.i(TAG, person.toString());
		}
	}
}
 

你可能感兴趣的:(android)