UI Testing - Xcode


Hey Community, I have created a JSON file and need its data to perform UI Testing, can anyone suggest me an answer?

Make sure to include the json in your testing bundle!
It’s probably in your main app bundle right now

Screenshot 2022-01-18 at 8.52.32 PM
Its in my testing bundle itself, still its not working

And when looking at the right pane it’s checked in the UI testing bundle?

But also that’s not really UI testing that you’ve written, it’s more of a unit test, but also even then you should be testing production code as opposed to writing code in the test

Actually I’m getting a little data which is required for UI Testing in that json file , I have written a unit test to check if I’m going to get the data or not, it’s not working. That’s the reason why I have posted this question. If i would have been using unit test , then I would have mentioned ‘@testable import’ in my code . I’m trying to access json data in UI Test , but for some reason it’s not working. The process is correct but it’s not reading the file path / url. Can you please suggest a solution for this.

Can you show me what the right pane looks like when selecting TestData.json

Also double check the spelling of everything

Also try:
bundle.path(forResource: "TestData", ofType: "json")

If that doesn’t work, I used OHHTTPStubs for network calls, in UI testing, make sure this is in the right target otherwise it’d mock things that you don’t want to be mocked

1 Like