Do not crash when your server lies
We all know that the API has a specification. We all write tests to cover “happy paths” and to cover “unhappy paths” when work with the API.
It may seem that we’re pretty safe if we have tests and follow the specification. Well, actually no. Usually it works well in theory, but doesn’t really work in practice.
We can write as many tests as we need to cover all edge cases, but that is both time consuming and error prone. The best choice would be is to automate this process.
from Crash-free code with Fuzzer
- (void)test {
NSDictionary *sample = @{
@“name” : @“John Doe”,
@“age” : @42
};
UserDeserializer *deserializer = [UserDeserializer new];
FZRRunner *runner = [FZRRunner runnerWithBuiltinMutationsForSample:sample];
NSArray *reports = [runner enumerateMutantsUsingBlock:^(NSDictionary *mutant) {
[deserializer deserializeUser:mutant];
}];
XCTAssertEqual(reports.count, 0);
}
Get the latest component .make file for Fuzzer.
pod 'Fuzzer', '0.3.0'
Pull requests are more than welcome!
Removes random key/value pair from a dictionary
Takes random key from dictionary and replaces its value with a value provided by Node Replacement
- integer replacement: replaces value with 'random' integer
- float replacement: replaces value with 'random' float
- string replacement: replaces value with 'random' string
- boolean replacement: replaces value with 'random' boolean
- array replacement: replaces value with 'random' array
- dictionary replacement: replaces value with 'random' dictionary
- null replacement: replaces value with
[NSNull null]
- nil replacement: replaces value with
nil
(leads to removing key/value from dictionary)
MIT, see LICENSE
for details