Async teardown logic in swift-testing

Using XCTest I can have a func tearDown() async throws however with swift-testing, we are forced to do teardown logic in the deinit, which supports neither throwing nor async code.

What's the best way to run some common async teardown logic after each test using swift-testing?

It looks like this is an active discussion here.

Looking forward to this landing, @smontgomery!

The other option is the withXXX approach we're using in Vapor, works well with structured concurrency

Have a link to an example? Did a cursory search in the vapor repo but couldn't find what you're referring to.

There's an example here jwt/Tests/JWTTests/Helpers/withApp.swift at main · vapor/jwt · GitHub. This function is then simply used as a wrapper in the tests jwt/Tests/JWTTests/JWTTests.swift at main · vapor/jwt · GitHub

2 Likes