Package-level declarations

Types

Link copied to clipboard

Intercepts the render pass of the root workflow and runs it twice to ensure that well-written unit tests catch side effects being incorrectly performed directly in the render method.

Link copied to clipboard

The props must be specified, the initial state may be specified, and then all child workflows and workers that are expected to run, and any outputs from them, must be specified with expectWorkflow and (optionally) expectWorker and expectSideEffect calls. If one needs to verify all workers explicitly, perhaps to verify that a worker is not run, then use requireExplicitWorkerExpectations. Likewise requireExplicitSideEffectExpectations for side effects. Then call render and perform any assertions on the rendering. An event may also be sent to the rendering if no workflows or workers emitted an output. Lastly, the RenderTestResult returned by render may be used to assert on the WorkflowActions processed to handle events or outputs by calling verifyAction or verifyActionResult.

Link copied to clipboard

Result of a RenderTester.render call that can be used to verify that a WorkflowAction was processed and perform assertions on that action.

Link copied to clipboard
class WorkerSink<T>(name: String, type: KClass<*>) : Worker<T>

Implementation of Worker for integration tests (using launchForTestingFromStartWith or launchForTestingFromStateWith) that need to simply push values into the worker from the test.

Link copied to clipboard
interface WorkerTester<T>
Link copied to clipboard
@TestOnly
class WorkflowTestParams<out StateT>(val startFrom: WorkflowTestParams.StartMode<StateT> = StartFresh, val checkRenderIdempotence: Boolean = true)

Defines configuration for workflow testing infrastructure such as testRender, testFromStart. and test.

Link copied to clipboard

Runs a Workflow and provides access to its renderings, outputs, and snapshots.

Link copied to clipboard
class WorkflowTurbine<RenderingT>(val firstRendering: RenderingT, receiveTurbine: ReceiveTurbine<RenderingT>)

Simple wrapper around a ReceiveTurbine of RenderingT to provide convenience helper methods specific to Workflow renderings.

Functions

Link copied to clipboard

Specifies that this render pass is expected to run a particular side effect.

Link copied to clipboard

Specifies that this render pass is expected to run a Worker that has the same type of the given worker and for which the actual worker's doesSameWorkAs method returns true. If a worker is ran that matches the type of expected, but the actual worker's doesSameWorkAs returns false, then an AssertionError will be thrown. If you need to perform custom assertions, use the overload of this method that takes an assertWhen parameter.

inline fun <PropsT, StateT, OutputT, RenderingT, WorkerOutputT, WorkerT : Worker<WorkerOutputT>> RenderTester<PropsT, StateT, OutputT, RenderingT>.expectWorker(workerClass: KClass<out WorkerT>, key: String = "", crossinline assertWorker: (WorkerT) -> Unit = {}, output: WorkflowOutput<WorkerOutputT>? = null, description: String = ""): RenderTester<PropsT, StateT, OutputT, RenderingT>

Specifies that this render pass is expected to run a Worker with the given workerClass. The worker's output type is not taken into consideration.

fun <PropsT, StateT, OutputT, RenderingT> RenderTester<PropsT, StateT, OutputT, RenderingT>.expectWorker(workerType: KType, key: String = "", assertWorker: (Worker<*>) -> Unit = {}, output: WorkflowOutput<*>? = null, description: String = ""): RenderTester<PropsT, StateT, OutputT, RenderingT>

Specifies that this render pass is expected to run a Worker whose KType matches workerType.

Link copied to clipboard
inline fun <PropsT, StateT, OutputT, RenderingT> RenderTester<PropsT, StateT, OutputT, RenderingT>.expectWorkerOutputting(outputType: KType, key: String = "", crossinline assertWorker: (Worker<*>) -> Unit = {}, output: WorkflowOutput<*>? = null, description: String = ""): RenderTester<PropsT, StateT, OutputT, RenderingT>

Specifies that this render pass is expected to run a Worker with the given outputType.

Link copied to clipboard
inline fun <ChildRenderingT, PropsT, StateT, OutputT, RenderingT> RenderTester<PropsT, StateT, OutputT, RenderingT>.expectWorkflow(identifier: WorkflowIdentifier, rendering: ChildRenderingT, key: String = "", description: String = "", noinline assertProps: (props: Any?) -> Unit = {}): RenderTester<PropsT, StateT, OutputT, RenderingT>

Specifies that this render pass is expected to render a particular child workflow.

Link copied to clipboard
fun <OutputT, RenderingT> Workflow<Unit, OutputT, RenderingT>.headlessIntegrationTest(coroutineContext: CoroutineContext = UnconfinedTestDispatcher(), interceptors: List<WorkflowInterceptor> = emptyList(), runtimeConfig: RuntimeConfig = RuntimeConfigOptions.DEFAULT_CONFIG, onOutput: suspend (OutputT) -> Unit = {}, testTimeout: Long = WORKFLOW_TEST_DEFAULT_TIMEOUT_MS, testCase: suspend WorkflowTurbine<RenderingT>.() -> Unit)

Version of headlessIntegrationTest that does not require props. For Workflows that have Unit props type.

fun <PropsT, OutputT, RenderingT> Workflow<PropsT, OutputT, RenderingT>.headlessIntegrationTest(props: StateFlow<PropsT>, coroutineContext: CoroutineContext = UnconfinedTestDispatcher(), interceptors: List<WorkflowInterceptor> = emptyList(), runtimeConfig: RuntimeConfig = RuntimeConfigOptions.DEFAULT_CONFIG, onOutput: suspend (OutputT) -> Unit = {}, testTimeout: Long = WORKFLOW_TEST_DEFAULT_TIMEOUT_MS, testCase: suspend WorkflowTurbine<RenderingT>.() -> Unit)

This is a test harness to run integration tests for a Workflow tree. The parameters passed here are the same as those to start a Workflow runtime with renderWorkflowIn except for ignoring state persistence as that is not needed for this style of test.

Link copied to clipboard
@TestOnly
fun <T, OutputT, RenderingT> Workflow<Unit, OutputT, RenderingT>.launchForTestingFromStartWith(testParams: WorkflowTestParams<Nothing> = WorkflowTestParams(), context: CoroutineContext = EmptyCoroutineContext, block: WorkflowTestRuntime<Unit, OutputT, RenderingT>.() -> T): T
@TestOnly
fun <T, PropsT, OutputT, RenderingT> Workflow<PropsT, OutputT, RenderingT>.launchForTestingFromStartWith(props: PropsT, testParams: WorkflowTestParams<Nothing> = WorkflowTestParams(), context: CoroutineContext = EmptyCoroutineContext, block: WorkflowTestRuntime<PropsT, OutputT, RenderingT>.() -> T): T

Creates a WorkflowTestRuntime to run this workflow for unit testing.

Link copied to clipboard

Creates a WorkflowTestRuntime to run this workflow for unit testing. If the workflow is stateful, initialState is not called. Instead, the workflow is started from the given initialState.

Link copied to clipboard
@TestOnly
fun <T, PropsT, StateT, OutputT, RenderingT> StatefulWorkflow<PropsT, StateT, OutputT, RenderingT>.launchForTestingWith(props: PropsT, testParams: WorkflowTestParams<StateT> = WorkflowTestParams(), context: CoroutineContext = EmptyCoroutineContext, block: WorkflowTestRuntime<PropsT, OutputT, RenderingT>.() -> T): T

Creates a WorkflowTestRuntime to run this workflow for unit testing.

Link copied to clipboard
fun <T> Worker<T>.test(timeoutMs: Long = DEFAULT_TIMEOUT_MS, block: suspend WorkerTester<T>.() -> Unit)

Test a Worker by defining assertions on its output within block.

Link copied to clipboard

Create a RenderTester to unit test an individual render pass of this workflow, using the workflow's initial state.

Create a RenderTester to unit test an individual render pass of this SessionWorkflow, using the workflow's initial state, in the workflowScope.

Create a RenderTester to unit test an individual render pass of this workflow.

Link copied to clipboard
inline fun <T> WorkerSink(name: String): WorkerSink<T>