danielgerlag / danielgerlag/workflow-core
UnitTesting a workflow - step by step
- Dominant language
- C#
- Stars
- 5.9k
- Forks
- 1.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 5
Description
**Is your feature request related to a problem? Please describe.**
When unit testing a workflow it is currently only possible to start the workflow and the workflow runs concurrently until the end or in an error, see [Test helpers for Workflow Core](https://workflow-core.readthedocs.io/en/latest/test-helpers/)
When testing a bigger workflow with many steps which also uses services vi DI the mocking and verifying of the service gets very cumbersome.
**Describe the solution you'd like**
For testing purpose it would be nice to have an implicit wait step after each workflow step so a unittest can be structured like
1. Start workflow() -> waits directly before first step
2. Setup mocks for first step
3. ProceedOneStep() -> executes one step and waits again
4. Verify mocks/result data
5. Setup mocks for next step
6. ProceedOneStep() -> executes next step and waits again
7. Verify mocks/result data
8. -> continue until workflow is finished
In the test the expected workflow is known so the "ProceedOneStep()" calls will match the expected steps. If they doesn't match or the workflow changed then "ProceedOneStep()" will timeout and throw.
**Describe alternatives you've considered**
I am currently investigating the built workflow steps and try to instrument them, so injecting a "WaitFor" step with a fixed event key after each step. For simple workflows with sequential flow it works almost but problematic are the more difficult ones.
It would be much simpler if the "IWorkflowBuilder" would provide interceptor events like "OnBeforeStepAdded" and "OnAfterStepAdded". Then in unittests this events could be used for instrumentation.
What do you think?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the linked Test helpers for Workflow Core documentation and inspect IWorkflowBuilder, then trace how workflow steps are added and executed. The issue does not settle whether to add step-control APIs or builder interceptor events; done would require an agreed design, implementation, and tests covering step-by-step execution and mock verification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend, testing-qa
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100