title: Issues running asynchronous code in unit tests
body: <p>So I am having issues running asynchronous code in the unit tests of my app. I am using expectations in order to wait for the code to execute before the test completes. The asynchronous code runs through heroku in order to get the values and then should return them in the app. With this unit test, I am trying to make sure the connection through heroku is working. Here is a look at my code:</p>
  
  <pre><code>func test() {
      let url = "https://s.herokuapp.com/test"
  
      let params: [String: Any] = ["account_id": AppState.sharedInstance.user.accounttoken]
  
      let expectation = self.expectation(description: "Testing returning value")
  
      let totalBalance = ""
      Alamofire.request(url, method: .post, parameters: params)
          .validate(statusCode: 200..&lt;300)
          .responseJSON { response in
              switch response.result {
              case .success:
                  print("Returned with success")
              case .failure(let error):
                  let status = response.response?.statusCode
                  print("Failed, status: \(status)")
                  print("Here is the error: \(error)")
              }
  
              if let result = response.result.value {
                  let balance = result as! NSDictionary
                  let totalBalance = String(describing: "\(balance["Balance"]!)")
              }
              XCTAssert(totalBalance != "")
              expectation.fulfill()
      }
      waitForExpectations(timeout: 10, handler: nil)
      XCTAssert(totalBalance != "")
  }
  </code></pre>
  
  <p>The reason I am confused is because I have no error getting the asynchronous code to return values in the actual app. I only have the wait time issue in unit testing. I am getting two fail errors, one for the XCTAssert not being true and one for the waitForExpectations going longer than 10 seconds. Here is some of the errors that are popping up as well if that helps find the solution:</p>
  
  <p><img src="https://i.stack.imgur.com/O6oBm.png" alt="Error Messages"></p>
  
  <p>Here is the error messages in text form:</p>
  
  <blockquote>
    <p>2019-07-01 09:44:38.181971-0400 Spotbirdparking[49677:4306598] TIC TCP
    Conn Failed [6:0x6000030b7cc0]: 3:-9816 Err(-9816) 2019-07-01
    09:44:38.188607-0400 Spotbirdparking[49677:4306598]
    NSURLSession/NSURLConnection HTTP load failed
    (kCFStreamErrorDomainSSL, -9816) 2019-07-01 09:44:38.188819-0400
    Spotbirdparking[49677:4306598] Task
    .&lt;1> HTTP load failed (error
    code: -1200 [3:-9816]) 2019-07-01 09:44:38.189215-0400
    Spotbirdparking[49677:4306623] Task
    .&lt;1> finished with error - code:
    -1200 /Users/drewloughran/Desktop/SpotBird/SpotbirdparkingTests/SpotbirdparkingTests.swift:117:
    error: -[SpotbirdparkingTests.SpotbirdparkingTests test_stripe] :
    Asynchronous wait failed: Exceeded timeout of 10 seconds, with
    unfulfilled expectations: "Testing stripe returning value".</p>
  </blockquote>
  
  <p>I am also fairly new to swift so any help would be appreciated with this problem.</p>