Allow Bypass or Apple Mock Dialog Boxes During Testing

I am having problems getting my test suite to pass completely when running in CircleCI. Everything will take place locally at startup as a bundle and at startup separately. Eventually I ran into the issue causing the issues, the Apple Notification / Location permission dialog. The tests are still running, but any test waiting for the warning fails because the Apple dialog is still on the screen. This happens every time you run a complete package on a new device or uninstall an app.

My question is, what is the best way to handle these dialogues? I'm pretty sure writing UI tests is impossible, as all UI tests are pretty strict about order and what's on screen. The tests are randomized and the dialog is only shown for the first test that invokes it, the rest doesn't need to worry about that.

My current thinking, but not sure how to proceed:

  • Check the location alert / push request so that it never starts a conversation. Difficult for me as I have a class that does all the work for push and location. Am I making fun of Apple classes or my own?
  • Write a separate target for tests with only 1 test that starts the dialog and can close it. This will only be used when run on a CI server. This may not work as the same simulator cannot be used between test runs. I would have thought it would, but no guarantees.
  • Add debug code to live code to bypass some of these dialogs and permissions. I already have code when running in DEBUG for notifications, since you are not actually getting a successful token on the simulator. I just close the fake return when I start debugging to continue testing. What a little more? I am not honestly considering this question if I can help him. There is already enough "test" code in the live codebase that I would like to prevent it, if at all possible.

If anyone had any ideas, you would love some feedback or examples of how to proceed.

Installation details:

  • ObjC
  • Latest version of Xcode, supports iOS 8 and above.
  • Using KIF and OCMock for testing
+3


source to share


1 answer


We had several ways to work around this:



  • In beforeEach / setUp, check for an alert box and then use the KIF API for support.
  • https://github.com/plu/JPSimulatorHacks just works!
  • Use XCUITest to run permission streams and enable all permissions before moving on to the target test suite.
0


source







All Articles