https://kotlinlang.org logo
Title
b

BryanT

04/17/2023, 1:23 PM
I found this code in the wild on a github issue, but it isn't clear to me how one would reference the HttpClient that is supposedly passed in.
private fun testApplicationWrapper2(testBlock: suspend ApplicationTestBuilder.(HttpClient) -> Unit) {
        testApplication {
            application {
...
What I'm attempting to do... handle custom HttpClient creation at the class level so that each test case need not create it. I have that working using a lateinit var, but was hoping the set up could be done and passed in via the testApplicationWrapper.
private fun testApplicationWrapper2(testBlock: suspend ApplicationTestBuilder.(HttpClient) -> Unit) {
    testApplication {
        application {
            configureRouting()
            configureSerialization()
        }
        val client: HttpClient = createClient {
            install(ContentNegotiation) {
                json()
            }
        }

        testBlock(client)
        // usage found at <https://youtrack.jetbrains.com/issue/KTOR-4773>
    }
}
a

Aleksei Tirman [JB]

04/18/2023, 9:02 AM
So has the
testApplicationWrapper2
method solved your problem?
b

BryanT

04/18/2023, 2:25 PM
Not for modifying the httpclient, that seems to be getting instantiated every time application test builder is called.