Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit Testing for AFNetworking calls which are in my code #99

Open
asefnoor opened this issue Dec 15, 2014 · 0 comments
Open

Unit Testing for AFNetworking calls which are in my code #99

asefnoor opened this issue Dec 15, 2014 · 0 comments

Comments

@asefnoor
Copy link

Hi,
I have read this article for unit testing API calls and I understood the concept of unit testing with mock objects to test API calls.
http://www.infinite-loop.dk/blog/2011/09/using-nsurlprotocol-for-injecting-test-data/
Inside code of above article sample

[self loadCannedResultWithName:@"MiddleOfNowhere"];
mockParser = [OCMockObject partialMockForObject:parser];
[[[mockParser stub] andCall:@selector(returnCannedResultForRequest:)
onObject:self] sendRequestWithURLString:[OCMArg any]];

// Perform code under test
[parser findNearbyPlaceNameForLatitude:-10.0 longitude:-10.0];

// Validate result
STAssertTrue([self waitForCompletion:3.0], @"Failed to get any results in time");
STAssertNotNil(searchResult, @"Didn't expect an error");
STAssertEquals([searchResult count], (NSUInteger)0, @"Should not find any results in the middle of nowhere: %@", searchResult);
STAssertEquals(totalFound, 0U, @"Unexpected number of total results");

It calls that method which is in my code and under test
// Perform code under test
[parser findNearbyPlaceNameForLatitude:-10.0 longitude:-10.0];

above method is in code file rather than test class but when I look at Nocilla samples, it does not call actual methods of code. It samples are all in test file and independent of method which I actually want to test.
My goal is to test a webservice call, validate its url, host etc, body parameters and only mock that part which interact with live server. How can I achieve that.

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant