TestMosaicBuilder
Fluent configuration for scoped TestMosaic execution with substituted dependencies.
This class provides a fluent API for setting up test scenarios by configuring mock tiles with various behaviors. It supports both Tile and MultiTile mocks with different behaviors like success, failure, delays, and custom logic. Each withMosaic invocation inherits its calling coroutine context, including the Job, dispatcher, and scheduler when called inside runTest.
Basic Usage
mosaicBuilder()
.withMockTile(MyTile, "test data")
.withFailedTile(OtherTile, RuntimeException("Test error"))
.withDelayedTile(SlowTile, "delayed data", 1000) // 1 second delay
.withMosaic { /* compose and assert here */}MultiTile Usage
mosaicBuilder()
.withMockTile(UserTile, mapOf("user1" to user1, "user2" to user2))
.withCustomTile(ProfileTile) { keys ->
// Custom logic based on requested keys
keys.associateWith { key -> createMockProfile(key) }
}
.withMosaic { /* compose and assert here */}Functions
Borrows a caller-owned source for the canvas with the specified object.
Borrows a caller-owned source for the canvas with the specified object and qualifier.
Borrows a caller-owned source for the canvas with the specified class and object. Allows for passing in a superclass as the retrieval type.
Borrows a caller-owned source for the canvas using a CanvasKey.
Borrows a caller-owned source for the canvas with the specified class, qualifier, and object.
Adds a mock MultiTile that fails with the specified exception.
Adds a mock Tile that fails with the specified exception.
Executes block with a fresh cache and a snapshot of this builder's configuration. Inherits the calling coroutine's Job, dispatcher, scheduler, and other context elements. Every exit cancels unfinished producers and waits for their attached children to clean up. Supplied Canvas sources are borrowed: they remain owned by the caller and are never closed. Configure this builder from one coroutine at a time; later changes affect only later executions.