Testing void methods using OCMock in iOS
<p>I am trying to write a test case for a method in Objective-C class which returns void. The method <code>mobileTest</code> just creates another object of class <code>AnotherClass</code> and calls a method <code>makeNoise</code>. How to test this ? </p>

<p>I tried to use OCMock to create test this. Created a mock object of <code>AnotherClass</code>, and called <code>mobileTest</code> method. Obviously, the <code>OCMVerify([mockObject makeNoise])</code> won't work, as I am not setting this object anywhere in the code. So, how to test in such cases ? </p>

<pre><code>@interface Hello
@end

@implementation HelloWorldClass()

-(void)mobileTest{
    AnotherClass *anotherClassObject = [AnotherClass alloc] init];
    [anotherClassObject makeNoise];
}
@end


@interface AnotherClass
@end

@implementation AnotherClass()
-(void) makeNoise{
    NSLog(@"Makes lot of noise");   
}
@end
</code></pre>

<p>Test case for the above is as follows : </p>

<pre><code>-(void)testMobileTest{
    id mockObject = OCMClassMock([AnotherClass class]);
    HelloWorldClass *helloWorldObject = [[HelloWorld alloc] init];
    [helloWorldObject mobileTest];
    OCMVerify([mockObject makeNoise]);
}
</code></pre>