title: Wait for XCTestExpectation before starting next unit test in XCode
body: <p>I have a number of asynchronous unit tests which work correctly on their own using expectations.  However when I run all the tests in the suit, they do not wait for each other to complete - the asynchronous callbacks are still pending when the next tests start running.  What I want is for each test to wait for the expectations in the previous test before running.  These tests use a shared database, so having them overlap leads to annoying additional complexity, and failing tests when run as a suite.</p>
  
  <pre><code>- (void)testSignIn {
  // This is an example of a functional test case.
  // Use XCTAssert and related functions to verify your tests produce the correct results.
  
  XCTestExpectation *expectation =
  [self expectationWithDescription:@"Expectations"];
  
  [_userManager signInWithUsername:kUserEmail andPassword:kUserPassword
                           success:^{
                               XCTAssertNotNil([_userManager getCurrentUser]);
  
                               XCTAssertNotNil([_userManager getCurrentUser].plan);
                               XCTAssertTrue([_userManager getCurrentUser].plan.liveStream == TRUE);
  
                               [expectation fulfill];
  
                           } failure:^(EDApiError *apiError) {
                               XCTAssertTrue(FALSE); // Should not fail
                               [expectation fulfill];
  
                           }];
  
  [self waitForExpectationsWithTimeout:5.0 handler:^(NSError *error) {
      if (error) {
          NSLog(@"Timeout Error: %@", error);
      }
  }];
  </code></pre>
  
  <p>}</p>