fork
Creates a forked test scenario from the current ExpectStage.
This extension function enables branching of test execution from a verified aggregate state, allowing testing of alternative command sequences or error conditions. The fork creates an isolated test context that starts from the verified state of the current stage.
When verifyError is true, the fork expects an error to have occurred in the parent stage. When verifyError is false, the fork expects successful execution in the parent stage.
Return
a DynamicNode representing the forked test container, or a failed DynamicTest if an exception occurs
Parameters
the state type of the aggregate being tested
the name to display for this forked test branch in test reports
the DSL context for managing shared state across test stages
whether to verify that an error occurred before forking (true) or successful execution (false)
the test scenario to execute in the forked context using ForkedVerifiedStageDsl
Throws
if an error occurs during fork setup or execution (wrapped in DynamicTest for reporting)
Example usage:
expectStage.fork("Test Error Handling", context, verifyError = true) {
whenCommand(ErrorCommand()) {
expectErrorType(IllegalArgumentException::class)
}
}