0

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://mydevserver.192.168.1.15.xip.io/api/data.json").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?

4

0 回答 0