test

fun Transformer.test(dispatcher: CoroutineDispatcher = StandardTestDispatcher()): TransmissionTest(source)

Extension function to create a TransmissionTest for this transformer.

This provides a more readable and fluent API for creating tests directly from transformer instances. Uses UnconfinedTestDispatcher for immediate coroutine execution.

Receiver

The transformer to test

Return

A new TransmissionTest instance

Example:

val transformer = UserTransformer()
transformer.test()
.withData(UserRepository.currentUserContract) { UserData.LoggedOut }
.testSignal(UserSignal.Login("user", "pass")) {
val loginData = lastData<UserData.LoggedIn>()
assertNotNull(loginData)
}

Extension function to create a TransmissionTest for this transformer with a custom dispatcher.

This provides a more readable and fluent API for creating tests with controlled coroutine execution. Useful for testing time-dependent behavior or controlling execution order.

Receiver

The transformer to test

Return

A new TransmissionTest instance

Example:

val testDispatcher = StandardTestDispatcher()
val transformer = TimerTransformer()
transformer.test(testDispatcher)
.testSignal(TimerSignal.Start(5000)) {
// Control timing with testDispatcher.scheduler
testDispatcher.scheduler.advanceTimeBy(5000)
val timerData = lastData<TimerData.Finished>()
assertNotNull(timerData)
}

Parameters

dispatcher

The test dispatcher to use for coroutine execution


fun Transformer.test(dispatcher: TestDispatcher = StandardTestDispatcher(), timeout: Duration = 5.seconds, block: suspend TransmissionTestScope.() -> Unit): TestResult(source)

Tests this transformer by sending messages and awaiting what it produces.

@Test
fun `address then payment places the order`() = checkoutTransformer(gateway, dispatcher).test(dispatcher) {
fake(Cart.summary) { cart }
val clear = fake(Cart.clear)
send(Checkout.Start)
send(SubmitAddress(address))
send(SubmitPayment(card))
assertEquals(Step.Confirmed("TS-1001"), awaitState(Checkout.state).step)
assertEquals(OrderPlaced("TS-1001", 3600), awaitEffect<OrderPlaced>())
assertEquals(1, clear.calls)
}

Create the transformer with the same dispatcher: processing then runs on the test scheduler, delays in fakes run in virtual time, and awaiting first lets every pending message be handled.

Parameters

timeout

How long an await waits for work running on other dispatchers before failing.


fun TestSuite.test(effect: Transmission.Effect, scope: suspend TransformerTestScope.(scope: TestScope) -> Unit)(source)

Deprecated

Use testEffect() instead

Replace with

import com.yigitozgumus.transmissiontest.TransmissionTest
test().testEffect(effect, scope)

Receiver

The TestSuite instance

Parameters

effect

The effect transmission to test

scope

Lambda with test assertions


fun TestSuite.test(signal: Transmission.Signal, scope: suspend TransformerTestScope.(scope: TestScope) -> Unit)(source)

Deprecated

Use testSignal() instead

Replace with

import com.yigitozgumus.transmissiontest.TransmissionTest
test().testSignal(signal, scope)

Receiver

The TestSuite instance

Parameters

signal

The signal transmission to test

scope

Lambda with test assertions