I am working on testing an API through Alamofire. I need to make a single call to the server to prepare it for the integration test. Once that is done, I am ready to start running tests.

The usual `override setUp()` is run for every test, so I do not want to do that.

I have therefore chosen to override the `class setUp()` as described here: <https://developer.apple.com/reference/xctest/xctestcase>

That's all well and good, but now, I no longer can use the standard `waitForExpectations`. (In the `class override setUp())` I get several compiler errors that tell me that I am no longer calling the same `waitForExpectations` because I am in a class method, not a test case.

To try to get around this, I wanted to use a semaphore like so:

```
class ServiceLayerTests: XCTestCase {
    static var apiService: APIService = APIService()
    let sessionManager = SessionManager(serverTrustPolicyManager: ServerTrustPolicyManager(policies: ["http://localhost:3000/": .disableEvaluation]))
    static var companyManger: UserWebResource?
    static var companyManagerID = -1
    override class func setUp() {
        apiService.baseURL = "http://localhost:3000/"
        beginIntegrationTests()
    }

    class func beginIntegrationTests() {
        var semaphore = DispatchSemaphore(value: 0)
        apiService.beginIntegrationTests(completion: {resource, error in
            if let resource = resource {
                if let manager = resource as? UserWebResource {
                    companyManger = manager
                    companyManagerID = manager.id
                    semaphore.signal()

                }
            }
        })
        _ = semaphore.wait(timeout: DispatchTime.distantFuture)
  }
}

```

This does not work. Under the hood, there is an alamo fire call to the server and it responds with the user to use for the integration tests. I do see the server spinning, so I know that the actual communication is happening, but I never get into the completion closure.

I suspect I am not understanding how Swift does semaphores and that I have created a deadlock somehow. If somebody has a better solution, I'd be more than happy to hear it.