Is it possible to test the Client Websocket?
# ktor
j
Is it possible to test the Client Websocket?
a
You can test WebSockets interaction with the testApplication.
j
Thanks @Aleksei Tirman [JB]. I tried to copy the sample:
Copy code
@Test
fun test() {
    testApplication {
        val client = createClient {
            install(WebSockets)
        }

        client.webSocket("/echo") {
            val greetingText = (incoming.receive() as? Frame.Text)?.readText() ?: ""
            assertEquals("Please enter your name", greetingText)

            send(Frame.Text("JetBrains"))
            val responseText = (incoming.receive() as Frame.Text).readText()
            assertEquals("Hi, JetBrains!", responseText)
        }
    }
}
However, running this test gives me an exception:
Copy code
WebSocket connection failed
java.lang.IllegalStateException: WebSocket connection failed
	at io.ktor.server.testing.TestApplicationEngineJvmKt$handleWebSocketConversationNonBlocking$5.invokeSuspend(TestApplicationEngineJvm.kt:75)
	at _COROUTINE._BOUNDARY._(CoroutineDebugging.kt:42)
	at io.ktor.server.testing.TestApplicationEngineJvmKt.handleWebSocketConversationNonBlocking(TestApplicationEngineJvm.kt:67)
Do I need to configure something additionally?
Oh, nvm I need to configure the routes manually since I don't actually have a server in my project
After playing around a little bit and writing tests, I don't think
testApplication
is suited at all for testing client websockets 😕