Package io.ktor.server.testing

Types

Link copied to clipboard

A builder for a test that uses TestApplication.

Link copied to clipboard
expect abstract class BaseTest
actual abstract class BaseTest
actual abstract class BaseTest
Link copied to clipboard
interface ClientProvider

A client attached to TestApplication.

Link copied to clipboard
expect abstract class EngineTestBase<TEngine, TConfiguration>(applicationEngineFactory: <ERROR CLASS><TEngine, TConfiguration>) : BaseTest, CoroutineScope
actual abstract class EngineTestBase<TEngine, TConfiguration> : BaseTest, CoroutineScope
actual abstract class EngineTestBase<TEngine, TConfiguration>(applicationEngineFactory: <ERROR CLASS><TEngine, TConfiguration>) : BaseTest
Link copied to clipboard
class ExternalServicesBuilder

Registers mocks for external services.

Link copied to clipboard
class HighLoadHttpGenerator(host: String, port: Int, numberOfConnections: Int, queueSize: Int, highPressure: Boolean, builder: RequestResponseBuilder.() -> Unit)

This HTTP generator produces huge amount of requests however it doesn't validate responses and doesn't measure any time characteristics.

Link copied to clipboard
object It

it function receiver object

Link copied to clipboard
object On

on function receiver object

Link copied to clipboard
class StressSuiteRunner(klass: Class<*>) : Runner, Filterable, Sortable
Link copied to clipboard
class TestApplication : ClientProvider

A configured instance of a test application running locally.

Link copied to clipboard
open class TestApplicationBuilder

A builder for TestApplication.

Link copied to clipboard
class TestApplicationCall(application: <ERROR CLASS>, readResponse: Boolean, closeRequest: Boolean, coroutineContext: CoroutineContext) : CoroutineScope

A test application call that is used in withTestApplication and handleRequest.

Link copied to clipboard
class TestApplicationEngine(environment: <ERROR CLASS>, configure: TestApplicationEngine.Configuration.() -> Unit) : CoroutineScope

A test engine that provides a way to simulate application calls to the existing application module(s) without actual HTTP connection.

Link copied to clipboard
class TestApplicationRequest(call: TestApplicationCall, closeRequest: Boolean, method: <ERROR CLASS>, uri: String, port: Int?, version: String) : CoroutineScope

A test application request

Link copied to clipboard
class TestApplicationResponse(call: TestApplicationCall, readResponse: Boolean) : CoroutineScope

A test call response received from a server.

Link copied to clipboard
object TestEngine

An ApplicationEngineFactory providing a CIO-based ApplicationEngine.

Functions

Link copied to clipboard
fun TestApplicationResponse.awaitWebSocket(duration: Duration)

Wait for websocket session completion

Link copied to clipboard
fun TestApplicationResponse.contentType(): <ERROR CLASS>

Returns a parsed content type from a test response.

Link copied to clipboard
fun TestApplicationEngine.cookiesSession(callback: () -> Unit)

Keeps cookies between requests inside the callback.

Link copied to clipboard
fun createTestEnvironment(configure: <ERROR CLASS>.() -> Unit = {}): <ERROR CLASS>

Creates an engine environment for a test application.

Link copied to clipboard
fun TestApplicationEngine.handleRequest(method: <ERROR CLASS>, uri: String, setup: TestApplicationRequest.() -> Unit = {}): TestApplicationCall

Makes a test request.

Link copied to clipboard
fun TestApplicationEngine.handleWebSocketConversation(uri: String, setup: TestApplicationRequest.() -> Unit = {}, awaitCallback: Boolean = true, callback: suspend TestApplicationCall.(incoming: ReceiveChannel<Frame>, outgoing: SendChannel<Frame>) -> Unit): TestApplicationCall

Makes a test request that sets up a WebSocket session and invokes the callback function that handles conversation with the server

Link copied to clipboard
inline fun On.it(description: String, body: It.() -> Unit)

DSL function for a test case assertions

Link copied to clipboard
fun on(comment: String, body: On.() -> Unit)

DSL for creating a test case

Link copied to clipboard
fun TestApplicationRequest.setBody(value: <ERROR CLASS>)

Set HTTP request body from ByteReadPacket

fun TestApplicationRequest.setBody(value: ByteArray)

Sets an HTTP request body bytes.

fun TestApplicationRequest.setBody(value: String)

Sets an HTTP request body text content.

fun TestApplicationRequest.setBody(boundary: String, parts: List<<ERROR CLASS>>)

Sets a multipart HTTP request body.

Link copied to clipboard
fun testApplication(block: suspend ApplicationTestBuilder.() -> Unit)

Creates a test using TestApplication. To test a server Ktor application, do the following:

Link copied to clipboard
fun <R> withApplication(environment: <ERROR CLASS> = createTestEnvironment(), configure: TestApplicationEngine.Configuration.() -> Unit = {}, test: TestApplicationEngine.() -> R): R

Starts a test application engine, passes it to the test function, and stops it.

Link copied to clipboard
fun <R> withTestApplication(test: TestApplicationEngine.() -> R): R
fun <R> withTestApplication(moduleFunction: <ERROR CLASS>.() -> Unit, test: TestApplicationEngine.() -> R): R
fun <R> withTestApplication(moduleFunction: <ERROR CLASS>.() -> Unit, configure: TestApplicationEngine.Configuration.() -> Unit = {}, test: TestApplicationEngine.() -> R): R

Starts a test application engine, passes it to the test function, and stops it.