Skip to content

Instantly share code, notes, and snippets.

@designatednerd
Last active August 29, 2015 14:13
Show Gist options
  • Save designatednerd/2ec5b4e5685075f8498f to your computer and use it in GitHub Desktop.
Save designatednerd/2ec5b4e5685075f8498f to your computer and use it in GitHub Desktop.
How Not To Write A Test
/*
The most horrendous test case I've ever found in client code, and a great example
of why "Your code must have X% test coverage" is a dangerous way to evaluate
whether something is properly tested.
Class prefixes have been changed to CLT (for Client) to protect the guilty. All
else is from the original.
*/
- (void)testShouldLogResponseOnSuccess
{
id<CLTServerDirectRequest> request = mockProtocol(@protocol(CLTServerDirectRequest));
id<CLTServerDirectResponse> response = mockProtocol(@protocol(CLTServerDirectResponse));
[given(request.debug) willReturnBool:YES]; // improve test coverage (logging line)
completion_block_t completionHandler = [self.dispatcher completionHandler:request];
completionHandler(response, nil);
// so yeah, we don't actually assert anything
// this is just to hit the sucess branch where we log the response for code coverage reports
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment