TestApplicationEngine

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

Constructors

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

Types

Link copied to clipboard
class Configuration : BaseApplicationEngine.Configuration

Test application engine configuration

Functions

Link copied to clipboard
fun createCall(readResponse: Boolean = false, closeRequest: Boolean = true, setup: TestApplicationRequest.() -> Unit): TestApplicationCall

Creates an instance of test call but doesn't start request processing

Link copied to clipboard
fun handleRequest(closeRequest: Boolean = true, setup: TestApplicationRequest.() -> Unit): TestApplicationCall

Make a test request

Link copied to clipboard
fun handleWebSocket(uri: String, setup: TestApplicationRequest.() -> Unit): TestApplicationCall

Make a test request that setup a websocket session and wait for completion

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

Make a test request that setup a websocket session and invoke callback function that does conversation with server

Link copied to clipboard
fun hookRequests(processRequest: TestApplicationRequest.(setup: TestApplicationRequest.() -> Unit) -> Unit, processResponse: TestApplicationCall.() -> Unit, block: () -> Unit)

Install a hook for test requests

Link copied to clipboard
open override fun start(wait: Boolean): ApplicationEngine
Link copied to clipboard
open override fun stop(gracePeriodMillis: Long, timeoutMillis: Long)
open fun stop(gracePeriod: Long, timeout: Long, timeUnit: TimeUnit)

Properties

Link copied to clipboard
open val application: Application
Link copied to clipboard
var callInterceptor: PipelineInterceptor<Unit, ApplicationCall>

interceptor for engine calls. can be modified to emulate certain engine behaviour (e.g. error handling)

Link copied to clipboard
val client: HttpClient

A client instance connected to this test server instance. Only works until engine stop invocation.

Link copied to clipboard
open override val coroutineContext: CoroutineContext
Link copied to clipboard
val engine: HttpClientEngine

An instance of client engine user to be used in client.

Link copied to clipboard
override val environment: ApplicationEngineEnvironment
Link copied to clipboard
val pipeline: EnginePipeline

Extensions

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

Keep cookies between requests inside the callback.

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

Make a test request