Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable unit testing for Dapr Workflows #1035

Merged
merged 2 commits into from
Feb 16, 2023
Merged

Conversation

cgillum
Copy link
Contributor

@cgillum cgillum commented Feb 14, 2023

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
Copy link
Contributor

@halspang halspang left a comment

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.

@codecov
Copy link

codecov bot commented Feb 15, 2023

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
Signed-off-by: Chris Gillum <cgillum@microsoft.com>
Signed-off-by: Chris Gillum <cgillum@microsoft.com>
@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 <cgillum@microsoft.com>

* Sample workflow unit testing project

Signed-off-by: Chris Gillum <cgillum@microsoft.com>

---------

Signed-off-by: Chris Gillum <cgillum@microsoft.com>
@mylona79
Copy link

Hi Dapr team, @cgillum ,

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

@cgillum
Copy link
Contributor Author

cgillum commented Feb 21, 2024

@halspang do you know the answer?

@mylona79
Copy link

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