Search code examples
iosswiftxcodexcuitest

XCUITest: How to set a specific state when creating iOS UI Tests for an app using GraphQL?


I'm new to iOS development. My question is how can I send data to my API so that I can set a state in iOS. For example if I have an app that can create and delete contacts. How can I send data to the API so that if I want to test just deleting a contact when I launch the test a contact has already been created so that I can just test deleting it? My app uses a GraphQL API. I tried calling the function that creates contacts by hardcoding the data needed and putting the function within a launch argument then using that launch argument in my test but that doesn't seem to work. So I'm not sure if this is possible to do within xcuitest. Any suggestions?


Solution

  • I think you can use mock services like open source wiremock

    Connect the app with wiremock and stub the data for API calls that you want to use :

    http://wiremock.org/docs/stubbing/

    You can send data to wiremock and wiremock return the same data when you want to use it

    http://wiremock.org/docs/stateful-behaviour/