The code used for this test is sqlite for data manipulation.
##### #右键选择要进行单元测试的应用
############ #弹出选择框, choose Android>test module>next
########## #Finish
# # # #现在回到项目目录
######## #同样出现的还有运行的Run, has been automatically configured for us.
########## #回到HomeActivityTest. In Java
###############
######## #这是我们最后的测试代码
Packagecom.op.teachingliteapp.activity;ImportAndroid.annotation.TargetApi;Importandroid.content.ContentValues;ImportAndroid.os.Build;ImportAndroid.test.ActivityInstrumentationTestCase2;Importcom.op.teachingliteapp.common.database.CourseTable;ImportCom.op.teachingliteapp.common.database.DBHelper;ImportCom.op.teachingliteapp.common.database.dao.CourseDao;/*** A simple framework for a test of a application. See {@linkandroid.test.ApplicationTestCase * Applicationtestcase} For more information on what to write and extend application T ESTs. * <p/> * To run this test, you can type:adb shell am instrument-w \-E class Com.op.teachingliteapp.activity.HomeA Ctivitytest * \ com.op.teachingliteapp.tests/android.test.instrumentationtestrunner*/@TargetApi (build.version_codes. Cupcake) Public classHomeactivitytestextendsActivityinstrumentationtestcase2{dbhelper dbhelper; @TargetApi (build.version_codes. Cupcake) Publichomeactivitytest () {Super("Com.op.teachingliteapp", homeactivity.class); } @Override Public voidSetUp ()throwsException {Super. SetUp (); DBHelper=NewDBHelper (Getactivity ()); } Public voidTestcoursedaoinsert ()throwsException {Coursedao Coursedao=NewCoursedao (DBHelper); Contentvalues contentvalues=Newcontentvalues (); Contentvalues.put (coursetable.column_id,"3300"); Contentvalues.put (Coursetable.column_course_name,"JAVA"); Contentvalues.put (coursetable.column_course_type_id,"2209"); Contentvalues.put (Coursetable.column_credit,"4"); Contentvalues.put (Coursetable.column_create_time,"2015-06-21 17:35:00.000");//hoursContentvalues.put (Coursetable.column_period, "78"); Contentvalues.put (Coursetable.column_update_time,"2015-06-24 17:35:00.000"); Contentvalues.put (coursetable.column_dept_id,"4044"); Assertequals (1, Coursedao.insert (contentvalues)); }}
########### #运行测试, testing requires the assistance of a virtual machine, but there is no activation of the activity during the test (we do not see anything on the interface).
############ #测试在跑了
############# #测试出错了, modify the code (think that already has a table already has a data, all row line number is not 1, but 2, now to change it to 3)
Assertequals (3, Coursedao.insert (contentvalues));
########## #现在再跑一遍测试 and succeeded.
######### #最后的表是这样的.
Android unit test in IntelliJ idea