ocmockito

OCMockito anything() for primitive types

故事扮演 提交于 2020-01-04 02:22:07
问题 For method signature - (void)insertValue:(NSUInteger)value; I'm trying to see if insertValue for any value never gets called. [verifyCount(test, never()) insertValue:0]; Since compiler complains anything() primitive types, how do I test this? 回答1: It's just like https://stackoverflow.com/a/20524472/246895 [[verifyCount(test, never()) withMatcher:anything()] insertValue:0]; OCMockito does all argument checking using OCHamcrest matchers. Normally, OCMockito turns a primitive argument into an

How does one unit test code that interacts with the Core Bluetooth APIs?

时光毁灭记忆、已成空白 提交于 2019-12-23 12:36:30
问题 I would like to unit test a class that acts as a CBPeripheralManagerDelegate to the CBPeripheralManager class. Typically, in order to stub out an external class dependency, I would use either a form of dependency injection by passing in via the class initializer or via a property. When dealing with singleton-based API's, I have been able to use libraries like Kiwi to stub the class level method that returns the singleton (i.e. [ClassName stub:@selector(sharedInstance) andReturn

Feature tests with KIF: beforeEach is called after my view controller is loaded?

主宰稳场 提交于 2019-12-11 10:43:45
问题 i have got simple (i guess) question. I want to make a feature test in my app with Specta and KIF. The problem is that i am setting dependency in viewDidLoad method of my View Controller, and in beforeEach method of my spec i'm injecting fake object just to not hit the network. The result is wrong because viewDidLoad is being called before beforeEach method in specs. Is there a possibility to set dependencies before AppDelegate loads root view controller so everything is set up properly? 回答1:

How do I stub a class method with OCMockito?

半腔热情 提交于 2019-12-06 08:57:30
The OCMockito documentation claims it's possible to mock class objects , but I'm damned if I can work out how. The following test fails with Expected "Purple" but was "" : - (void)testClassMethodMocking { Class stringClassMock = mockClass([NSString class]); [given([stringClassMock string]) willReturn:@"Purple"]; assertThat([NSString string], equalTo(@"Purple")); } If the answer to the abovelinked FAQ section "How do you mock a class object?" does not imply it's possible stub the return value of a class method, what is it used for? EDIT: Of course the above is a degenerate example, the real

OCMockito capturing primitive types?

此生再无相见时 提交于 2019-12-05 01:15:24
问题 How do I use OCMockito to capture argument with primitive values? MKTArgumentCaptor seems to be able to capture only object types? Xcode says "Incompatible pointer to integer conversion". 回答1: For primitive arguments, you have to do a little dance. Let's say we mocked NSMutableArray and wanted to verify calls to - (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject; Instead of [verify(mockArray) replaceObjectAtIndex:[argument capture] withObject:anything()]; which gives you

OCMockito capturing primitive types?

孤街醉人 提交于 2019-12-03 16:26:46
How do I use OCMockito to capture argument with primitive values? MKTArgumentCaptor seems to be able to capture only object types? Xcode says "Incompatible pointer to integer conversion". For primitive arguments, you have to do a little dance. Let's say we mocked NSMutableArray and wanted to verify calls to - (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject; Instead of [verify(mockArray) replaceObjectAtIndex:[argument capture] withObject:anything()]; which gives you the type conflict, we just have a dummy value (0 will do fine) but add an OCMockito call to override the