0

I think this is a really a question about the difference in the run time loop when running the app target vs running a unit test for for my view controller.

I know that reloadData is being called but the delegate methods are never called, even the method to ask in the first place how many rows there are is never called in unit test but it does when running as a application.

What am i missing in the wide world of iOS?

EDIT John was correct but for me the real issue was understanding that view controller's view is not instantiated until the views will actually be painted in the window. Since i was loading the view from a xib this requires that i actually call loadView (simple i know) from the unit test. Since objective c does not complain when you send a message to nil it never complained when i sent reloadData on a table that didn't exist

Ethan Allen
  • 255
  • 4
  • 8

1 Answers1

2

What I do is mock the table view controller, and ensure that reloadData is called on it.

In separate tests, I confirm what happens when the delegate methods are called.

There's no need to test that Apple will call the delegate methods.

Jon Reid
  • 20,545
  • 2
  • 64
  • 95
  • Sure, but i was more curious about the technical nature behind it..for future knowledge of stuff. Do we not expect some some sort of run loop? Even in a unit test if i called reloadData on a UITableView shouldn't it reach out to its delegates anyway? – Ethan Allen Jan 21 '14 at 14:44
  • Most things work without a run loop. The only time I've had to use them is for a) testing whether a text field has received focus, or b) testing asynchronous networking (which is an integration test, not a unit test, but can be written with unit testing tools). – Jon Reid Jan 21 '14 at 15:43
  • So based on some other comments would you agree that I'm running into a async issue where i need to block so and give the framework time to call my delegate methods before i end my test? – Ethan Allen Jan 21 '14 at 17:27
  • No. I've rewritten my answer to try to explain better. – Jon Reid Jan 22 '14 at 00:07
  • Ok so you are indeed calling reloadData manually in your unit test and that in turn is calling the delegate methods? – Ethan Allen Jan 22 '14 at 20:02
  • No, at least two different tests. One test confirms that `reloadData` is called. The other tests invoke the delegate methods directly, _as if Cocoa Touch had done so_. – Jon Reid Jan 23 '14 at 02:39