2

我想在我的仪器测试用例中创建一个 tmp 目录。我试过 this.getInstrumentation().getContext().getDir("tmp", 0)了,但是在 data/data/package-name 目录下创建目录失败。我想,仪器测试包和普通包之间存在一些差异。

有人可以帮我吗?

4

1 回答 1

2

假设您的应用程序项目有包名com.example,而您的测试项目有包名com.example.test

// This will create app_tmp1 directory under data/data/com.example.test/
this.getInstrumentation().getContext().getDir("tmp1", 0);

// This will create app_tmp2 directory under data/data/com.example/
this.getInstrumentation().getTargetContext().getDir("tmp2", 0);

希望这可以帮助。

于 2012-05-07T02:21:21.353 回答