Adnroid单元测试

1.进行单元测试需要在Manifest.xml文件里添加如下内容:

(1)在application内添加

<uses-library android:name="android.test.runner"/>

(2)在application外添加

<instrumentation 
android:name="android.test.InstrumentationTestRunner"
android:targetPackage
="com.archermind.activity"
android:label
="test by kelei"
/>

其中android:targetPackage="com.archermind.activity"要于manifest里的package="com.archermind.activity"一致

2.建立单元测试类,单元测试类继承AndroidTestCase类

public class StudentDAOTest extends AndroidTestCase
{

private static final String TAG = "StudentDAOTest";

public void testAdd()
{
StudentDAO studentDAO = new StudentDAO(this.getContext());
Student student = new Student(1, "kelei");
studentDAO.add(student);
Log.i(TAG, "add success");
}

public void testUpdate()
{
fail("Not yet implemented");
}

public void testFind()
{
StudentDAO studentDAO = new StudentDAO(this.getContext());
Student student = studentDAO.find(1);
if(student==null)
{
Log.i(TAG, "not find");
}
else
{
Log.i(TAG, student.toString());
}
}
}




你可能感兴趣的:(单元测试)