Package io.ktor.server.testing

Types

Link copied to clipboard
abstract class EngineTestBase<TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configuration>(applicationEngineFactory: ApplicationEngineFactory<TEngine, TConfiguration>) : CoroutineScope
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 TestApplicationCall(application: Application, readResponse: Boolean, closeRequest: Boolean, coroutineContext: CoroutineContext) : BaseApplicationCall, CoroutineScope

Represents a test application call that is used in withTestApplication and handleRequest

Link copied to clipboard
class TestApplicationEngine(environment: ApplicationEngineEnvironment, configure: TestApplicationEngine.Configuration.() -> Unit) : BaseApplicationEngine, CoroutineScope

ktor test engine that provides way to simulate application calls to existing application module(s) without actual HTTP connection

Link copied to clipboard
class TestApplicationRequest(call: TestApplicationCall, closeRequest: Boolean, method: HttpMethod, uri: String, version: String) : BaseApplicationRequest, CoroutineScope

Represents a test application request

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

Represents test call response received from server

Link copied to clipboard

Functions

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

Wait for websocket session completion

Link copied to clipboard
fun TestApplicationResponse.contentType(): ContentType

Return parsed content type from the test response

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

Keep cookies between requests inside the callback.

Link copied to clipboard

Creates test application engine environment

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

Make a test request

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

DSL function for test 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: ByteArray)

Set HTTP request body bytes

fun TestApplicationRequest.setBody(value: String)

Set HTTP request body text content

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

Set multipart HTTP request body

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

Start test application engine, pass it to test function and stop it

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

Start test application engine, pass it to test function and stop it