我在Android库(AAR)的开发过程中看到了我不期待的行为,想知道是否有人可以解释它。 我的图书馆结构是:
src/
androidTest/
assets/
my_assets/
java/
com/
...
main/
java/
com/
...
我的测试正在执行以下操作:
final String assetsSubfolder = "my_assets";
Context targetContext = InstrumentationRegistry.getTargetContext();
String[] targetAssets = targetContext.getResources().getAssets().list("");
Context testContext = InstrumentationRegistry.getContext();
String[] testAssets = testContext.getResources().getAssets().list("");
Assert.assertTrue("target should not have assets now", !Arrays.asList(targetAssets).contains(assetsSubfolder));
Assert.assertTrue("test should have assets now", Arrays.asList(testAssets).contains(assetsSubfolder));
由于目标(即库生产代码)包含我的测试资产文件夹,测试失败。我认为使用getTargetContext我将看不到assets文件夹,因为我的生产代码中没有assets文件夹。有人可以解释一下吗?