【发布时间】:2016-07-01 18:17:49
【问题描述】:
运行我的插桩单元测试后,我发现 SQLite 数据似乎已自动清除,但 SharedPreferences 文件仍保留在我的设备中。我错了吗?在这两种情况下,我都使用相同的模拟上下文来创建 SQLiteOpenHelper 和 SharedPreferences。
下面列出了简化的代码sn-p。
@RunWith(AndroidJUnit4.class)
public class MyTest {
Context mMockContext;
@Before
public void setUp() {
mMockContext = new RenamingDelegatingContext(InstrumentationRegistry.getInstrumentation().getTargetContext(), "test_");
}
@Test
public void testSQLite() throws Exception {
MySQLiteOpenHelper dbHelper = new MySQLiteOpenHelper(mMockContext);
...
}
@Test
public void testSharedPreferences() throws Exception {
SharedPreferences settings = mMockContext.getSharedPreferences("Foo", 0);
...
}
}
【问题讨论】:
标签: java android sqlite android-studio