XCTest sending information from the app (under test) back to XCTests

161 views Asked by At

Situation:

Consider an ios/swift/app that is being tested using xcode/XCTests. The app also includes some logging to console (and to Google/Firebase/Crashlytics as nonfatal exceptions: works great!).

For this a custom written logging class is being used that accepts logging as debug, info and error. The point: it's easy to add some custom code each time an error log is being done.

Question:

When, during XCTests, an error is being logged, we want to send this to the running XCTest so that the XCTest can see this as a failure. Basically this means we need a way to send information from the app under test back to the running XCTest.

We thought about using the notification center but this does not apply because the XCTest is not running in the app's process. How could this be done?

1

There are 1 answers

1
Roman Zakharov On BEST ANSWER

I suggest you try several options:

  1. Dirty one. Set the pasteboard in these error logging functions. Then check the pasteboards within the XCTest.
  2. A better option – set up a tiny error logging server and catch errors in XCTest.
  3. Finally, if you use Simulators – you should use their feature – read/write access inside their sandbox. You can write logs somewhere and read them in test code.