Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add async support for class tearDown() function #415

Open
shepazon opened this issue Jul 14, 2022 · 1 comment
Open

Add async support for class tearDown() function #415

shepazon opened this issue Jul 14, 2022 · 1 comment

Comments

@shepazon
Copy link

While we now have async versions of the per-test setUp() and tearDown() functions, we don't yet have an async version of the class-wide tearDown(). Adding this would allow tests that are able to ensure that any artifacts left behind by the main testing are cleaned up before the test suite ends:

override class func tearDown() async {
    super.tearDown()

    do {
        await someCleanupFunction()
    } catch {
        /* do error handling */
    }
}

I've tried using a Task() and a semaphore in the class tearDown(), but the task gets terminated early when the main test program exits.

@grynspan
Copy link
Contributor

grynspan commented Sep 5, 2023

Sorry for the late reply. If you are blocked on a solution here, consider using addTeardownBlock() instead:

func testWhatever() {
  addTeardownBlock {
    await someTeardownWork()
  }
  XCTAssertTrue(whatever())
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants