Luuk D. Jansen
Luuk D. Jansen

Reputation: 4504

XCTest and the need for a special target to tweak App startup behaviour

I am trying to implement XCTest as I have a bug in an iOS App which I don't seem to figure out so want to start building up get cases.

The App however, when loaded, will automatically connect to a server to update data. For the tests however, I would like this not to happen, as I need to clear the CoreData database and populate for each test.

Is there a way to know when e.g. building (on the target) if tests are going to be ran? Ie so I can use a flag to to leave out certain actions when testing?

Or should I just duplicate my normal target specifically for tests, and put in a flag that way? (e.g. #if TESTING instead of #if DEBUG)

Upvotes: 0

Views: 194

Answers (1)

Mikael
Mikael

Reputation: 3612

Not a direct answer to your question, but it might be a solution to your problem.

You could mock your class that does the server connection (ie fake the server connection).

You can do this by using OCMock that you can find here or OCMockito that can be found here.

Currently, I find OCMock easier to implement with XCTest than OCMockito. However, there might be some issues with OCMock as well, but those can be ironed out be looking at this site.

Upvotes: 1

Related Questions