How to test an object's methods in an viewcontroller class?

79 views Asked by At

I am looking for a way to test an videoplayer's methods, which is in an viewcontroller class.

When the app launched, I can get the viewcontroller class, but the videoplayer object in it is my testing object, I need to test all of the methods for it.

I can alloc and init one new videoplayer object and call its method one by one, but how can I verify the method running right? I mean how can I let the movie/video play to check the play related method is working well or not? So I want to use the object which launched by app, and give some input to the method which needs to let it work, but I do not know how to do it.

1

There are 1 answers

2
Ben Flynn On

If you are using a standard video player, like MPMoviePlayerViewController, you should only need to test that you are calling to the video player as expected. If the video player is property of your VC, create a partial mock of the VC and have it return a mocked video player. Then set up expectations on your mocked video player that its "play" method is called when a "play" IBAction occurs in the VC and programmatically call that action. On the other hand, if you have in fact implemented your own video player, you can use unit tests to verify behavior at a per-method level.

You can use unit tests to determine that your methods behave properly when called with a spectrum of input. So if your movie player has a "load" method that takes an NSURL, you might ensure it will set an error object if it fails to load -- it might fail to load due to the lack of network connection, for example, which you can mock.

Testing that the movie player is actually presenting a real movie and not just playing garbage will be harder. You could put a delay in your test and make sure the play cursor is advancing. You could also look into a UI testing framework that could take a screenshot during the movie which you could verify later by hand.

Hopefully that helps get you started. If you want a more specific answer, please share some of the code you are trying to test and exactly what you expect it to do and I or someone else can provide more detail.