Skip to content

Enable unit testing for Dapr Workflows#1035

Merged
halspang merged 2 commits into
dapr:masterfrom
cgillum:workflow-testing
Feb 16, 2023
Merged

Enable unit testing for Dapr Workflows#1035
halspang merged 2 commits into
dapr:masterfrom
cgillum:workflow-testing

Conversation

@cgillum

@cgillum cgillum commented Feb 14, 2023

Copy link
Copy Markdown
Contributor

Description

An early user of Dapr Workflow pointed out that they aren't able to unit test their workflows. This PR addresses that problem by:

  1. Making WorkflowContext a mockable abstract base class
  2. Providing an example app that shows how to unit test workflows

The new unit test project isn't meant as an actual test to be run by us, but as a reference for developers so that they can learn how to write their own unit tests for workflows.

Note that the unit test project references the workflow console app sample, so I made many of the types in that sample public so that they could be easily tested from another project.

I also found a bug while refactoring the WorkflowContext - calls to WorkflowContext.SendEvent() would have resulted in a StackOverflowException. That is fixed in this PR too.

Issue reference

Resolves #1034

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

@cgillum
cgillum requested review from a team as code owners February 14, 2023 21:43

@halspang halspang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is fine overall, hooray testing! Just some nit-picks you can feel free to ignore. However, you do have a build issue that you'll need to look into.

Comment thread examples/Workflow/WorkflowUnitTest/Usings.cs Outdated
Comment thread examples/Workflow/WorkflowUnitTest/WorkflowUnitTest.csproj Outdated
@codecov

codecov Bot commented Feb 15, 2023

Copy link
Copy Markdown

Codecov Report

Merging #1035 (f9381ff) into master (9dcae7b) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #1035   +/-   ##
=======================================
  Coverage   69.47%   69.47%           
=======================================
  Files         162      162           
  Lines        5432     5432           
  Branches      585      585           
=======================================
  Hits         3774     3774           
  Misses       1518     1518           
  Partials      140      140           
Flag Coverage Δ
net6 69.38% <ø> (ø)
net7 69.38% <ø> (ø)
netcoreapp3.1 69.44% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@halspang
halspang changed the base branch from master to release-1.10 February 16, 2023 17:45
@halspang
halspang changed the base branch from release-1.10 to master February 16, 2023 18:23
halspang
halspang previously approved these changes Feb 16, 2023
@halspang
halspang merged commit aa38b05 into dapr:master Feb 16, 2023
@cgillum
cgillum deleted the workflow-testing branch February 16, 2023 23:22
yash-nisar pushed a commit to yash-nisar/dotnet-sdk that referenced this pull request Feb 27, 2023
* Workflow SDK changes to enable unit testing

Signed-off-by: Chris Gillum <[email protected]>

* Sample workflow unit testing project

Signed-off-by: Chris Gillum <[email protected]>

---------

Signed-off-by: Chris Gillum <[email protected]>
@mylona79

Copy link
Copy Markdown

Hi Dapr team, @cgillum ,

In which release version of .Net SDK we have that available?

@cgillum

cgillum commented Feb 21, 2024

Copy link
Copy Markdown
Contributor Author

@halspang do you know the answer?

@mylona79

Copy link
Copy Markdown

Hi @halspang ,

Kindly provide the Dapr sdk release where this feature is available.

Thanks a lot!
Maria

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Workflow testability

3 participants