views:

19

answers:

1

hi, I need to write unit test cases for my views.Using some apple demo projects i learnt how to write a unit test case for simple functions(which includes mathematical logic like GCD,Prime etc). now i need to understand the same for Appdelegates and views.

so I need to know 1.how to start writing cases for delegates,views and learn the approach for the same. 2.any related demo projects or study guide for the same is appreciated.

please explain the approach for the code below:

//test suite
#import "SampleUnitTestCase.h"
#import "HelloWorldViewController.h"
#import "HelloWorldAppDelegate.h"
@implementation SampleUnitTestCase

- (void) setUp {
    appDelegate    = [[UIApplication sharedApplication] delegate];
    viewController = appDelegate.viewController;

}

- (void) testAppDelegate {
    STAssertNotNil(appDelegate, @"Cannot find the application delegate");
}

I am getting this errors

"((appDelegate) != nil)" should be true. Cannot find the application delegate in SampleUnitTestCase.m"

"Command /bin/sh failed with exit code 1"

//HelloWorldViewController.m file

#import "HelloWorldViewController.h"

@implementation HelloWorldViewController


- (IBAction)submitYourNamw 
{

    IblUserTypedName.text = txtUserName.text;
    //NSLog(IblUserTypedName.text);
}

......

@end
A: 

Don't have enough time to start providing code, but the two kits I use are GHUnit and OCMock. GHUnit because it runs on the simulator and device where as (last time I looked) SEN kit only runs in xcode. OCMock because it allows you to mock other classes. For example you could mock a framework class or controller etc.

Have a read of the the GHUnit and OCMock web sites and you will get a better idea of how they work and what they can do for you.

Derek Clarkson
I didn't get this line "OCMock because it allows you to mock other classes. For example you could mock a framework class or controller etc." can you explain in a simple way.
darshan
Do some reading on mock objects and their uses within unit testing.
Derek Clarkson