I want to share data between the Main app target and the XCUITest target. I didn't find any solution. Is dis possible?
Asked
Active
Viewed 1,170 times
2
-
4Depend on how is yours data is presented. – Cy-4AH Nov 15 '19 at 13:00
3 Answers
2
You should be able to accomplish this if you have a shared container between your UITest runner and the app being tested.

ablarg
- 2,400
- 1
- 24
- 32
-
Writing to/reading from the SIMULATOR_SHARED_RESOURCES_DIRECTORY works for me as of Xcode 12.3. – ryanipete Jan 11 '21 at 01:25
-
yes, but that won't work on a real device. Your UITest will fail because that directory does not exist. – ablarg Jan 22 '21 at 22:56
1
UI Tests are black boxed, so you cant have access to your code.
You can use @testable import in Unit Tests, so full access will be provided. When you're running UITests this is not working, because during a UITest your test class cannot access your app's code.
Please see this for reference: How do I access my swift classes from my UI tests?

chakravatisingh
- 41
- 1
- 4
-1
Like they already told you in the comments it depends on how is your data is presented.
But usually in your test file, you should import the main module:
import XCTest
@testable import <YOUR_MODULE_NAME>
Your module name is the name of your main Target.

Andrea Miotto
- 7,084
- 8
- 45
- 70