TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | BSD |
ReleasedLast Release | Dec 2014 |
Maintained by Unclaimed.
ITO SOFT DESIGN Inc. http://www.itosoft.com/
Katsuyoshi Ito [email protected]
February 10, 2012
Surikae replace a method by blocks.
It’s helpful for unit testing for Objective-C.
Import Surikae folder to you project.
Use +surikaeWithSelector:surikae:context of NSObject.
It replace the selector of the Class by surikae block.
If you want to replace an instance method, use -surikaeWithSelector:surikae:context of NSObject.
This effect is available in the context block only.
[NSDate surikaeWithSelector:@selector(date)
surikae:^()
{
return [NSDate dateWithYear:2012 month:2 day:17 hour:0 minute:0 second:second];
}
context:^()
{
[self.stopWatch start];
second = 1;
[self.stopWatch stop];
ASSERT_EQUAL_DOUBLE(1.0, self.stopWatch.time);
}
];
If you need these effect more long period, use +registedSurikaeWithSelector:surikae of NSObject.
In this case IUTSurikae class retains UITSurikae object.
When you retrieve all replaced methods, call +[NSObject removeAllSurikaes].
- (void)setUp
{
[super setUp];
second = 0;
[NSDate registedSurikaeWithSelector:@selector(date)
surikae:^()
{
return [NSDate dateWithYear:2012 month:2 day:17 hour:hour minute:minute second:second];
}
];
self.stopWatch = [StopWatch new];
}
- (void)tearDown
{
self.stopWatch = nil;
[NSDate removeAllSurikaes];
[super tearDown];
}
Please see a sample project
BSD Licence
hayashi311: implementation blocks