Skip to content

//workflow/com.squareup.workflow1.testing

Package com.squareup.workflow1.testing

Types

Name Summary
RenderIdempotencyChecker [jvm]
Content
object RenderIdempotencyChecker : WorkflowInterceptor
More info
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.


RenderTester [jvm]
Content
abstract class RenderTester<PropsT, StateT, OutputT, RenderingT>
More info
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 calls.


RenderTestResult [jvm]
Content
interface RenderTestResult<PropsT, StateT, OutputT, RenderingT>
More info
Result of a RenderTester.render call that can be used to verify that a WorkflowAction was processed and perform assertions on that action.


WorkerSink [jvm]
Content
class WorkerSink<T>(name: String, type: KClass<*>) : Worker<T>
More info
Implementation of Worker for integration tests (using launchForTestingFromStartWith or launchForTestingFromStateWith) that need to simply push values into the worker from the test.


WorkerTester [jvm]
Content
interface WorkerTester<T>


WorkflowTestParams [jvm]
Content
@TestOnly()

class WorkflowTestParamsStateT>(startFrom: WorkflowTestParams.StartMode<StateT>, checkRenderIdempotence: Boolean)
More info
Defines configuration for workflow testing infrastructure such as testRender, testFromStart.


WorkflowTestRuntime [jvm]
Content
class WorkflowTestRuntime<PropsT, OutputT, RenderingT>
More info
Runs a Workflow and provides access to its renderings, outputs, and snapshots.


Functions

Name Summary
expectSideEffect [jvm]
Content
fun <PropsT, StateT, OutputT, RenderingT> RenderTester<PropsT, StateT, OutputT, RenderingT>.expectSideEffect(key: String): RenderTester<PropsT, StateT, OutputT, RenderingT>
More info
Specifies that this render pass is expected to run a particular side effect.


expectWorker [jvm]
Content
inline fun <PropsT, StateT, OutputT, RenderingT, WorkerOutputT, WorkerT : Worker<WorkerOutputT>> RenderTester<PropsT, StateT, OutputT, RenderingT>.expectWorker(expected: WorkerT, key: String = “”, output: WorkflowOutput<WorkerOutputT>? = null, description: String = “”): RenderTester<PropsT, StateT, OutputT, RenderingT>
More info
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.


[jvm]
Content
inline fun <PropsT, StateT, OutputT, RenderingT, WorkerOutputT, WorkerT : Worker<WorkerOutputT>> RenderTester<PropsT, StateT, OutputT, RenderingT>.expectWorker(workerClass: KClassWorkerT>, key: String = “”, crossinline assertWorker: (WorkerT) -> Unit = {}, output: WorkflowOutput<WorkerOutputT>? = null, description: String = “”): RenderTester<PropsT, StateT, OutputT, RenderingT>
More info
Specifies that this render pass is expected to run a Worker with the given workerClass.


[jvm]
Content
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>
More info
Specifies that this render pass is expected to run a Worker whose KType matches workerType.


expectWorkerOutputting [jvm]
Content
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>
More info
Specifies that this render pass is expected to run a Worker with the given outputType.


expectWorkflow [jvm]
Content
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>
fun <ChildOutputT, ChildRenderingT, PropsT, StateT, OutputT, RenderingT> RenderTester<PropsT, StateT, OutputT, RenderingT>.expectWorkflow(identifier: WorkflowIdentifier, rendering: ChildRenderingT, output: WorkflowOutput<ChildOutputT>?, key: String = “”, description: String = “”, assertProps: (props: Any?) -> Unit = {}): RenderTester<PropsT, StateT, OutputT, RenderingT>
inline fun <ChildPropsT, ChildOutputT, ChildRenderingT, PropsT, StateT, OutputT, RenderingT> RenderTester<PropsT, StateT, OutputT, RenderingT>.expectWorkflow(workflowType: KClass<out Workflow<ChildPropsT, ChildOutputT, ChildRenderingT>>, rendering: ChildRenderingT, key: String = “”, crossinline assertProps: (ChildPropsT) -> Unit = {}, output: WorkflowOutput<ChildOutputT>? = null, description: String = “”): RenderTester<PropsT, StateT, OutputT, RenderingT>
More info
Specifies that this render pass is expected to render a particular child workflow.


launchForTestingFromStartWith [jvm]
Content
@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
More info
Creates a WorkflowTestRuntime to run this workflow for unit testing.


launchForTestingFromStateWith [jvm]
Content
@TestOnly()

fun <StateT, OutputT, RenderingT> StatefulWorkflow<Unit, StateT, OutputT, RenderingT>.launchForTestingFromStateWith(initialState: StateT, context: CoroutineContext = EmptyCoroutineContext, block: WorkflowTestRuntime<Unit, OutputT, RenderingT>.() -> Unit)
@TestOnly()

fun <T, PropsT, StateT, OutputT, RenderingT> StatefulWorkflow<PropsT, StateT, OutputT, RenderingT>.launchForTestingFromStateWith(props: PropsT, initialState: StateT, context: CoroutineContext = EmptyCoroutineContext, block: WorkflowTestRuntime<PropsT, OutputT, RenderingT>.() -> T): T
More info
Creates a WorkflowTestRuntime to run this workflow for unit testing.


launchForTestingWith [jvm]
Content
@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
More info
Creates a WorkflowTestRuntime to run this workflow for unit testing.


test [jvm]
Content
fun <T> Worker<T>.test(timeoutMs: Long = DEFAULT_TIMEOUT_MS, block: suspend WorkerTester<T>.() -> Unit)
More info
Test a Worker by defining assertions on its output within block.


testRender [jvm]
Content
fun <PropsT, OutputT, RenderingT> Workflow<PropsT, OutputT, RenderingT>.testRender(props: PropsT): RenderTester<PropsT, *, OutputT, RenderingT>
More info
Create a RenderTester to unit test an individual render pass of this workflow, using the workflow’s initial state.


[jvm]
Content
fun <PropsT, StateT, OutputT, RenderingT> StatefulWorkflow<PropsT, StateT, OutputT, RenderingT>.testRender(props: PropsT, initialState: StateT): RenderTester<PropsT, StateT, OutputT, RenderingT>
More info
Create a RenderTester to unit test an individual render pass of this workflow.


WorkerSink [jvm]
Content
inline fun <T> WorkerSink(name: String): WorkerSink<T>