r/iOSProgramming • u/psychophysix • Dec 21 '15
Question Help with using OCMock.
How can I mock out dependencies (classes) that cannot be injected in?
Background: I am a beginner iOS programmer (not new to programming, just Objective-C) who's starting development on a legacy code base that doesn't have much test coverage. I've done a fair bit of unit testing in python using the MagicMock library.
In python, if the code under test imports a class (say foobar), and i wish to mock out the 'foobar.baz' method, i could do something like this:
with mock.patch.object(foobar, 'baz') as mocked_baz:
mocked_baz.return_value = 'some_value'
code_under_test_method()
now the method in the code under test would have the foobar.baz method mocked out, and will return 'some_value' when the test is run.
Does OCMock support similar functionality?
Thanks for reading and any help you can provide!
View all comments
Show parent comment
3
u/psychophysix Dec 21 '15
Thanks for your response.
I'd tried what you suggested in the test code, but since the code under test still uses the unmocked version of the class...