TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by Unclaimed.
NISERuntimeFake
is an NSObject
category which creates fake objects at runtime.
It makes fake objects which can have different behaviour than real objects.
You can define different behaviour by overriding implemented instance methods.
//Creating fake object
YourClass *fakeObject = [YourClass fake];
//Overriding instance method
__block NSString *capturedString;
[fakeObject overrideInstanceMethod:@selector(doSomethingWithString:) withImplementation:^(YourClass *_self, NSString *string){
capturedString = string;
}];
//Use your fake object as you would normally use a real object
[fakeObject doSomethingWithString:@"Whatever"];
NSLog(@"%@", capturedString); //Output will be "Whatever"
//If you want to make new fake object with original implementation just create new one
fakeObject = [YourClass fake];
//Create fake object with protocol methods
YourClass *fakeObjectWithProtocol = [YourClass fakeObjectWithProtocol:@protocol(YourProtocol) includeOptionalMethods:YES];
//Create fake class
Class *fakeClass = [YourClass fakeClass];
//Create fake object with cusotm initializer
YourClass *fakeObject = [[fakeYourClass alloc] initWithWhatever:whatever];