TransmissionTest
Comprehensive testing framework for Transmission components with a fluent DSL.
TransmissionTest provides a sophisticated testing framework specifically designed for testing Transformer components in isolation or with controlled dependencies. It supports mocking data holders, computations, executions, and checkpoint validation while providing a clean fluent API for test setup and assertions.
Key Features:
Transformer Isolation: Test transformers in isolation with mocked dependencies
Mock Support: Mock data holders, computations, and executions from other transformers
Checkpoint Testing: Support for testing experimental checkpoint-based flow control
Stream Capture: Automatic capture of data and effect streams for assertions
Coroutine Testing: Built-in integration with kotlinx-coroutines-test
Initial Processing: Support for processing transmissions before the main test
Type-Safe Assertions: Type-safe methods for asserting on specific data/effect types
Basic Usage:
Testing Signal Processing:
@Test
fun testUserLogin() = runTest {
val transformer = UserTransformer()
transformer.test()
.testSignal(UserSignal.Login("username", "password")) {
// Assert that login data was emitted
val userData = lastData<UserData.LoggedIn>()
assertNotNull(userData)
assertEquals("username", userData.user.name)
}
}
Testing with Mocked Dependencies:
@Test
fun testUserProfile() = runTest {
val transformer = ProfileTransformer()
transformer.test()
.withData(UserRepository.userContract) {
UserData.LoggedIn(User("John", "john@example.com"))
}
.withComputation(ProfileService.profileContract) {
UserProfile("John", 25, "Engineer")
}
.testSignal(ProfileSignal.LoadProfile) {
val profileData = lastData<ProfileData.Loaded>()
assertNotNull(profileData)
assertEquals("John", profileData.profile.name)
}
}
Testing Effect Processing:
@Test
fun testCacheInvalidation() = runTest {
val transformer = CacheTransformer()
transformer.test()
.testEffect(CacheEffect.Invalidate("user_data")) {
// Assert that cache was cleared
val clearEffect = lastEffect<CacheEffect.Cleared>()
assertNotNull(clearEffect)
}
}
Testing with Initial Processing:
@Test
fun testWithInitialState() = runTest {
val transformer = DataTransformer()
transformer.test()
.withInitialProcessing(
UserSignal.Login("user", "pass"),
DataSignal.Initialize
)
.testSignal(DataSignal.Refresh) {
// Test behavior after initial processing
assertTrue(dataStream.size >= 2)
}
}
Parameters
The transformer to test
The test dispatcher for controlling coroutine execution
See also
for creating test instances
for assertion methods
Types
Contains the captured streams and provides assertion methods for test validation.
Functions
Executes a test with the given effect transmission and runs the provided assertions.
Executes a test with the given signal transmission and runs the provided assertions.
Adds a default checkpoint that will be validated during testing.
Adds a checkpoint with arguments that will be validated during testing.
Adds a mock computation with arguments that provides computed results for the specified contract during testing.
Adds a mock computation that provides computed results for the specified contract during testing.
Adds a mock data holder that provides data for the specified contract during testing.
Sets up initial transmissions that should be processed before the main test transmission.