Questions tagged [ocmock]
OCMock is an Objective-C implementation of mock objects.
484
questions
0
votes
0
answers
42
views
OCMVerify class method name conflict
The code to be test:
@interface A: NSObject
@end
@implementation A
+ (void)start {
[B start];
}
@interface B: NSObject
@end
@implementation B
+ (void)start {
// xxx
}
UnitTest code:
+ (...
0
votes
1
answer
369
views
Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_OCMArg"
I added OCMock version 3.9.1 to my project.
The LibPods-* file seems to be linked (checked Target->Build Phases->Link Binary). But during runtime the OCMock framework isn't getting recognized.
I ...
0
votes
0
answers
72
views
[OCMock]A question about the andDo function
1.code show as below:
[[OCMExpect([[self.mockDelegate ignoringNonObjectArgs] adLoaded:OCMOCK_ANY statusChanged:statusStarted]) ignoringNonObjectArgs] andDo:^(NSInvocation *invocation) {
...
...
0
votes
1
answer
169
views
[OCMock][OCMProtocolMock][OCMStub]When I OCMProtocolMock a protocol(This protocol has a method),How can I invoke the real implementation of the method
code show as below:
- (void)test_method {
id mockDelegate = OCMProtocolMock(@protocol(adDelegate));
OCMExpect([mockDelegate adLoaded:OCMOCK_ANY error:OCMOCK_ANY]);
self.delegate = ...
0
votes
1
answer
339
views
[OCMock][OCMVerify]Why does OCMVerify still pass when I don’t call a method?
for example:
id mockDelegate = OCMProtocolMock(@protocol(managerDelegate));
self.vc.delegate = mockDelegate;
OCMExpect([mockDelegate someMethod:OCMOCK_ANY]);
... Execute some methods to make vc.m ...
0
votes
0
answers
68
views
OCMVerify crashes test after a mocked callback
I have a method from a class under tests which takes two delegates: the second delegate will call a method after the first delegate will be called with a callback function as input.
@implemenation ...
0
votes
2
answers
859
views
Did not record an invocation in OCMStub/OCMExpect/OCMReject
I'm trying to mock a Singleton class in one of my unit tests. The way I'm creating my mock is like this:
MySingletonController *mockController = OCMClassMock([MySingletonController class]);
OCMStub([...
2
votes
1
answer
553
views
Test if a function is called in Unit Testing for Objective C
In the implementation file (.mm) I have a function that calls different APIs depending on the value of a boolean isTrue which is set in other APIs
@implementation Controller
-(void) setProperty:(Id)...
0
votes
1
answer
374
views
In Objective-C, how can I make a typedef for a composed object?
I'm using OCMProtocolMock to mock a protocol. After some clean up, my object conforms to 3 protocols:
id<MyProtocolA, MyProtocolB, MyProtocolC>
OCMProtocolMock takes only 1 arg, so I'd like to ...
0
votes
1
answer
168
views
'OCMock/OCMockObject.h' file not found
When I using OCMock in the project, the Xcode shows that 'OCMock/OCMockObject.h' file not found, however I did not modify anything in the OCMock group(folder). As picture shows, the OCMockObject.h ...
0
votes
0
answers
168
views
Proper usage of OCMock with Singleton
I am wondering what the proper way to use singleton.
I have read the following Mocking Singletons
The post is old and for right now we are using OCMock with the help of OCMPartialMock for instance:
@...
0
votes
1
answer
254
views
How to mock a C++ function in Objective C testing
I am trying to write test case for an objective-C function that uses a C++ function with return type bool. Inside the Objective-C function, I am simply calling the C++ function in a conditional ...
0
votes
1
answer
75
views
OCMock test if method does nothing but is called
Using OCMock, how do I test if a method does nothing?
- (void)myMethod:(BOOL)active
{
if (active) {
// Set property or do whatever
}
// Do nothing -- I need to test this scenario
}
2
votes
0
answers
99
views
How can I get a nested objective-c async method to execute under test using mocks and expectations?
Here is my test
- (void)test_IsOverLimit {
id myCoordinator = OCMPartialMock([[MyCoordinator alloc] init]);
XCTestExpectation *expectationLimitResult = [self expectationWithDescription:...
1
vote
1
answer
201
views
OCMock/OCMVerify - Expression result unused
Calls like the following don't compile because of Expression result unused warning/error:
id object = [Foo new];
id mockObject = OCMPartialMock(object);
...
OCMExpect([mockObject doTheThing]);
...
...
0
votes
2
answers
456
views
OCMock for dispatch_async without callback
I have a method on my view controller that uses dispatch_async. After some time, it calls another method. In my test, I want verify that the followup method gets called.
It appears that most people's ...
0
votes
1
answer
783
views
OCMock: invokeBlockWithArgs vs checkWithBlock
I'm reading the OCMock reference and I'm confused about these two OCMArg methods invokeBlockWithArgs (section 2.6)
The mock object will invoke the block passed as an argument to the
stubbed method. ...
0
votes
1
answer
264
views
OCMock: OCMVerify times gets wrong count when using OCMPartialMock
OCMock Version: 3.6
Hi, I use OCMPartialMock to mock a config object. When I use the reference to the real object, it is right to verify the times the function networkStatusCacheTime in the object is ...
0
votes
1
answer
31
views
OCMock constraints const char * arguments
OCMVerify function invocation, one of the parameters is const char *, how to constraits this type
[mock xxx:filter file:file func:__FUNCTION__];
OCMVerify([mock xxxxx:OCMArg.any file:OCMArg.any]);
...
1
vote
1
answer
464
views
Is there a way to test an instance variable in objective c?
I need to test an instance variable in Objective C.
I have this snippet in myViewController.m
@implementation myViewController
{
NSView *myView;
}
I need to add a test in myViewControllerTest.mm ...
0
votes
0
answers
357
views
Using OCMock to mock an internal object and change the behavior of a instance selector
I'm trying to use OCMock to modify the behavior of an instance selector for a specific class where I don't have a direct pointer to the instance of the class in question.
I've found a few posts ...
0
votes
0
answers
118
views
Adding a mocked UIView to a view hierarchy
I'm trying to write unit tests in which I pass a mocked UIView that is added to the view hierarchy. Here's a basic reproduction:
- (void)testUIView {
UIView *realView = [UIView new];
UIView *...
0
votes
2
answers
466
views
OCMock class category not working as expected
I have the following UIImage category:
@implementation UIImage (Exception)
+ (nullable UIImage *)imageCanThrowWithData:(NSData *)data error:(NSError **)errorPtr
{
UIImage *image = nil;
@try ...
1
vote
1
answer
363
views
How to partial mock objects of the same class twice in OCMock 3.4.2?
EKSource *source1 = [[EKSource alloc] init];
EKSource *source2 = [[EKSource alloc] init];
id source1Mock = OCMPartialMock(source1);
[[[source1Mock stub] andReturnValue:@(EKSourceTypeBirthdays)] ...
0
votes
0
answers
92
views
OCMock giving error with Key Value Observing
-(void)testPause_trial
{
MyMediaPlayer *player = [[MyMediaPlayer alloc]init];
id mock = [OCMockObject partialMockForObject:player];
AVQueuePlayer* result = [[AVQueuePlayer alloc]init];
...
1
vote
1
answer
40
views
OCMock3 Integration Issue with IOS
enter image description here
I added OCMock framework in my project and I wasn't able to take test Success or fail and code coverage.
I got Error like "Error Generating Code Coverage"
Anybody knows ...
2
votes
1
answer
157
views
OCMock: return the same value as get by parameter
I have faced with a bit specific issue while writing unit tests with the OCMock framework.
Let's say I have some method with one parameter. What I need is to stub that method and get the same value ...
0
votes
1
answer
199
views
I can mock NSHTTPURLResponse's status but not its allHeaderFields
I'm using OCMock to mock NSURLConnection/NSURLResponse (yes I do know these are deprecated) and everything is working as I want it mocking the http response code and the http body.
Now I'm trying to ...
2
votes
2
answers
621
views
Swift Unit test case - Mock framwork
I want to use mock framework for swift language in iOS. I have used OCMock framework for Objective C, But same was not working in swift. So, I need proper frameworks for handling mock object in swift.
0
votes
0
answers
116
views
OCMock returns method not invoked but I am sure it was
I am new to OCMock and I am having some issues. I have already read the official documentation, but coun't find how to solve my issue. I need to verify a method on a sharedInstance is called, and I am ...
0
votes
1
answer
147
views
OCMock notification observer - verifying the object
I've recently started working with OCMock framework and trying to figure out how to use the notification observer. So in my source code I'm observing some notification:
typedef enum {
...
0
votes
1
answer
31
views
stubbing init in ocmock3
creating init stubs was allowed in ocmock2 but is not allowed in ocmock3 (9.3)
Is there anyway to get around this restriction? We were earlier on ocmock2 and would like to update but a lot of our ...
1
vote
1
answer
209
views
How to stub a class method with response block using OCMock
HTTPResult *successResult = [[HTTPResult alloc] init];
successResult.success = YES;
successResult.content = @{@"key":@"value"};
id httpMock = OCMClassMock([HTTPUtility class]);
OCMStub(ClassMethod([...
0
votes
0
answers
93
views
OCmock expect/stub and doInvocation on class method
I have a class method with a completion block being called in the method under test. So I want to stub this method and call
[[[mock stub] loadImageForRelativeFilePath:[OCMArg any] completionBlock:[...
5
votes
1
answer
1k
views
How to use OCMock to verify that an asynchronous method does not get called in Objective C?
I want to verify that a function is not called. The function is executed in an asynchronous block call inside the tested function and therefore OCMReject() does not work.
The way I have tested if ...
0
votes
1
answer
2k
views
Calling OCMStub and OCMReject on the same method
I've been attempting to write some fail fast tests using OCMReject. However I've found that if OCMStub is used in conjunction with OCMReject, this test will pass
id _mockModel = OCMProtocolMock( @...
0
votes
1
answer
102
views
ARC error while stubbing [CLLocationManager authorizationStatus] using OCMock in Xcode9.1
I am using OCMock to stub [CLLocationManager authorizationStatus] for unit test cases. Seems like Xcode9.1 is getting confused with method name as same methods are present in other classes like ...
1
vote
1
answer
1k
views
OCMock and overriding stub value
mockModule = OCMPartialMock(module);
OCMStub([mockModule send:@"FOO"]).andReturn(YES);
OCMStub([mockModule send:@"FOO"]).andReturn(NO);
In this example I have a simple mock module, and I set some ...
0
votes
1
answer
278
views
Return primitive values in OCMock
I tried the documentation: http://ocmock.org/reference/#argument-constraints and I can't make work to return any value different of 0
My code is working with:
OCMStub([self.mockCurrentUser ...
0
votes
1
answer
126
views
Crash with Xcode 9 when mocking a NSManagedObject
Since downloading XCode 9, some of my unit tests have started to crash with a stack overflow (try searching for that these days!).
The problems seem to come from trying to create an OCMock of an ...
0
votes
1
answer
195
views
unit test local objects or dependency injection with OCMock?
Trying to create simple test for following function:
-(void)presentWithString:(NSString *)name
{
CustomVC *customVC = [[CustomVC alloc] initWithName:name];
UINavigationController *nav = [[...
0
votes
1
answer
247
views
Capturing Block passed into method when using OCMock
I'm looking to capture a block that is passed into a mock object. Here is the concrete function of class being mocked:
[self.imageFetcher fetchImageWithURL:url success:^(NSURL *successUrl, UIImage *...
2
votes
1
answer
1k
views
How to mock a class method of NSObject using OCMock
Is there a way to create an instance of an NSObject? I'm trying to mock a class method from NSObject and am getting an error that objc[86140]: no class for metaclass 0x1065c0e38.
- (void)...
0
votes
1
answer
567
views
Crash when using ignoringNonObjectArgs in OCMock in modern style
I am trying to mock a method mentioned bellow using the OCMock framework which takes an integer variable as the second argument. I also tried with old style OCMock stub call too with the same result. ...
0
votes
1
answer
139
views
Stubbing Methods does not work with OCMock3.4
Stubbing Methods works nicely With 'NSUserDefaults',but it just doesn't seem to work with My Custom Method.
My test code is as follows:
- (void)testExample
{
id userDefaultMock = OCMClassMock([...
0
votes
0
answers
76
views
How to perform verifyWithDelay on expected calls in OCMock <2.2.4
In OCMock the verifyWithDelay function was added in 2.2.4. I am working on a large project using an earlier version but need this functionality. Is anyone aware of a workaround for delaying a verify ...
0
votes
2
answers
241
views
How to extract an argument of 'function' type from NSInvocation
I am writing a unit test for the function that receives a protocol as input argument.
This function that I am testing calls some method of that protocol inside.
I want to mock this protocol and that ...
0
votes
0
answers
197
views
OCMock stub with args not returning expected value
I'm trying to write unit tests for https://github.com/jbavari/cordova-plugin-video-editor and I'm having some trouble.
In Xcode I'm trying to use OCMock (and Specta, Expecta) to test the getVideoInfo ...
4
votes
2
answers
666
views
Can OCMock mock a class such that it automatically uses the mocked instance in the code under test without injecting it
I'm new to OCMock and had a question.
Can we stub a method of a class, where calling that method over any instance/object of that class gets mocked
For Example : if Class_A has a non static ...
1
vote
1
answer
1k
views
Using primitive type parameter in OCMVerify
I am using OCMock as a mocking framework in my iOS project. When I try to use OCVerify functionality to test that a certain method is invoked, I came across a problem of passing primitive types as ...