搭建Android Junit单元测试环境
主配置文件中:
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.exe.androidcontentprovider"
</instrumentation>
在application中添加子标签。<uses-library android:name="android.test.runner" />
自定义测试类:extends AndroidTestCase
实现以下方法:
protected void setUp() throws Exception {
// TODO Auto-generated method stub
super.setUp();
service = new StudentService(getContext()); // 初始化服务类
}
搭建三层架构,Dao(context) service(context),Domain
domain:为了给 数据封装以及存贮
service:对外提供数据库操作
dao:实际直接操作数据库的类
无论是dao 还是 services 都需要上下文
github实例代码:https://github.com/mikelkl/SQLiteTest