Access App Groups container directory from test runner

感情迁移 提交于 2020-05-14 09:15:00

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!