jeudi 5 mars 2015

Tests get blocked when testing asynchronous network stuff with Nocilla

I'm trying to test a class that has a method responding asynchronously that makes a network call, stubbed by Nocilla.


The tests runs fine when I run the test alone. But as soon as I launch my whole test suite, it blocks here for a while and finishes with a:



Thread 1: signal SIGABRT


Here is my test class:



@interface SMIMyServiceTests : XCTestCase

@property (strong, nonatomic) SMIMyService *service;

@end


@implementation SMIMyServiceTests

+ (void)setUp {
[[LSNocilla sharedInstance] start];
}

+ (void)tearDown {
[[LSNocilla sharedInstance] stop];
}

- (void)setUp {
[super setUp];

self.service = [[SMIMyService alloc] init];
}

- (void)tearDown {
[[LSNocilla sharedInstance] clearStubs];
self.service = nil;
[super tearDown];
}

- (void)testFetch {
stubRequest(@"GET", @"http://ift.tt/1w78g4g").andReturn(200).withBody([MyUtil jsonFromFile:@"json-file" sender:self]);

XCTestExpectation *expectation = [self expectationWithDescription:@"Fetch"];

[self.service fetch:^(NSArray *data) {
XCTAssertTrue(data != nil);
XCTAssertEqual(data.count, 7);
[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:5.0 handler:nil];
}

@end


Any idea what's going wrong?


Aucun commentaire:

Enregistrer un commentaire