简体   繁体   中英

Unit Test Cases for views/viewcontroller and Delegate functions for iPhone

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM