问题
There is some data stored by main target in app groups container directory. And i'am running some xcui tests. Is it possible to access the data of the container from test runner? Alternatives?
It seems like for me that the answer is NO, because containerURL(forSecurityApplicationGroupIdentifier:)
method returns nil
.
Thank you!
回答1:
Actually, you can!
Simulator: Write / duplicate your shared data to this location; it should be accessible to both the UITestRunner and your application. Remember to have a mechanism to ensure this does not make it to production code.
NSString * pathAsString = [NSProcessInfo processInfo].environment[@"SIMULATOR_SHARED_RESOURCES_DIRECTORY"];
Device: Your UITestRunner should share the same Group Identifier as the app under test. Then you can access the shared resources folder. This does not work on Simulator because the UITestRunner is not signed for simulator targets, and it must be signed and part of the Shared Group in order to access the group.
NSURL *containerURL = [NSFileManager.defaultManager containerURLForSecurityApplicationGroupIdentifier:groupIdentifier];
Paulo Andrade has a nice blog post on how to do this: https://pfandrade.me/blog/managing-ios-ui-testing-fixtures/
回答2:
I agree, you can't. You can create a kind of Debug View to display content and enable it only for UITest execution.
来源:https://stackoverflow.com/questions/57962035/access-app-groups-container-directory-from-test-runner