I need to be able to determine whether a class method was called or not. How can I do this with OCMock?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Dependencies while implementing Mocking in Junit4
- back button text does not change
- iOS (objective-c) compression_decode_buffer() retu
相关文章
- 现在使用swift开发ios应用好还是swift?
- How to replace file-access references for a module
- How to mock methods return object with deleted cop
- What is a good way of cleaning up after a unit tes
-
EF6 DbSet
returns null in Moq - TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
Starting with OCMock release 2.1 this is supported out of the box. You can now stub class methods in the same way as you stub instance methods.
Alternatively, lets assume that you have the class:
and you want to mock this class method. One option is to create a category on this class which defines and implements testing support. Then, you can swap the implementation of the class method in the class under test with your mock one from the category.
One approach is to wrap the class method in a method on your own class. So let's say your class has to call
[SomeOtherClass classMethod:someString]
. You could create a methodinvokeClassMethod:
on your class like this:Then in your test, you create a partial mock and expect
invokeClassMethod:
If you want to verify that
invokeClassMethod
isn't called, you can throw an exception:The excpetion will cause the test to fail if
invokeClassMethod
is called.As zneak mentioned in their comment to your question, have a look at this answer,
And from the comments there, checkout this block-based implementation of class method swizzling.
OCMock
doesnt seem to directly support what you want to do, but this solution is quite nice!