Skip to content

Function

withApp(configure:_:)

Perform a test while handling lifecycle of the application. Feel free to create a custom function like this, tailored to your project.
@discardableResult func withApp<T>(configure: ((Application) async throws -> Void)? = nil, _ test: (Application) async throws -> T) async throws -> T

Parameters

configure

A closure where you can register routes, databases, providers, and more.

test

A closure which performs your actual test with the configured application.

Discussion

Usage:

@Test
func helloWorld() async throws {
    try await withApp(configure: configure) { app in
        try await app.testing().test(.GET, "hello", afterResponse: { res async in
            #expect(res.status == .ok)
            #expect(res.body.string == "Hello, world!")
        })
    }
}