Package io.ktor.server.testing

Types

EngineStressSuite

abstract class EngineStressSuite<TEngine : ApplicationEngine, TConfiguration : Configuration> : 
    EngineTestBase<TEngine, TConfiguration>

EngineTestBase

abstract class EngineTestBase<TEngine : ApplicationEngine, TConfiguration : Configuration> : 
    CoroutineScope

EngineTestSuite

abstract class EngineTestSuite<TEngine : ApplicationEngine, TConfiguration : Configuration> : 
    EngineTestBase<TEngine, TConfiguration>

HighLoadHttpGenerator

class HighLoadHttpGenerator

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

It

object It

it function receiver object

On

object On

on function receiver object

StressSuiteRunner

class StressSuiteRunner : Runner

TestApplicationCall

class TestApplicationCall : 
    BaseApplicationCall,
    CoroutineScope

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

TestApplicationEngine

class TestApplicationEngine : 
    BaseApplicationEngine,
    CoroutineScope

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

TestApplicationRequest

class TestApplicationRequest : 
    BaseApplicationRequest,
    CoroutineScope

Represents a test application request

TestApplicationResponse

class TestApplicationResponse : 
    BaseApplicationResponse,
    CoroutineScope

Represents test call response received from server

TestEngine

An ApplicationEngineFactory providing a CIO-based ApplicationEngine

Functions

contentType

Return parsed content type from the test response

cookiesSession

fun TestApplicationEngine.cookiesSession(
    callback: () -> Unit
): Unit

Keep cookies between requests inside the callback.

createTestEnvironment

fun createTestEnvironment(
    configure: ApplicationEngineEnvironmentBuilder.() -> Unit = {}
): ApplicationEngineEnvironment

Creates test application engine environment

handleRequest

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

Make a test request

it

fun On.it(description: String, body: It.() -> Unit): Unit

DSL function for test test case assertions

on

fun on(comment: String, body: On.() -> Unit): Unit

DSL for creating a test case

setBody

fun TestApplicationRequest.setBody(value: String): Unit

Set HTTP request body text content

fun TestApplicationRequest.setBody(value: ByteArray): Unit

Set HTTP request body bytes

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

Set multipart HTTP request body

withApplication

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

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

withTestApplication

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

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