Я запускаю инструментальные тесты Android на API 34 и столкнулся с проблемой, когда getExternalFilesDir() возвращает значение null при использовании тестового контекста, но отлично работает с целевым контекстом. Проблема:
// This returns NULL
Context testContext = InstrumentationRegistry.getInstrumentation().getContext();
File dir = testContext.getExternalFilesDir("test-results"); // Returns null
// This works fine
Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
File dir2 = targetContext.getExternalFilesDir("test-results"); // Works
Что я пробовал:
Добавлены разрешения READ_EXTERNAL_STORAGE и WRITE_EXTERNAL_STORAGE
Я запускаю инструментальные тесты Android на API 34 и столкнулся с проблемой, когда getExternalFilesDir() возвращает значение null при использовании тестового контекста, но отлично работает с целевым контекстом. [b]Проблема:[/b] [code]// This returns NULL Context testContext = InstrumentationRegistry.getInstrumentation().getContext(); File dir = testContext.getExternalFilesDir("test-results"); // Returns null
// This works fine Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); File dir2 = targetContext.getExternalFilesDir("test-results"); // Works [/code] [b]Что я пробовал:[/b] [list] [*]Добавлены разрешения READ_EXTERNAL_STORAGE и WRITE_EXTERNAL_STORAGE