test
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
The test dispatcher to use for coroutine execution
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
How long an await waits for work running on other dispatchers before failing.
Deprecated
Use testEffect() instead
Replace with
import com.yigitozgumus.transmissiontest.TransmissionTest
test().testEffect(effect, scope)Receiver
The TestSuite instance
Parameters
The effect transmission to test
Lambda with test assertions
Deprecated
Use testSignal() instead
Replace with
import com.yigitozgumus.transmissiontest.TransmissionTest
test().testSignal(signal, scope)Receiver
The TestSuite instance
Parameters
The signal transmission to test
Lambda with test assertions