Must be able to assert result from Polly in unit tests
See original GitHub issueThere’s the noOp policy that is recommended to be used in tests. This class allows your code to bypass polly itself, ignoring timeouts for example (which is our case).
This is all great, but we must be able to assert the TimeoutRejectedException from polly. I guess what we want to do is to “fake” the noOp policy to always have a FinalException
set. Is this possible?
In essence, we want to;
- Write code dependent on the timeout policy.
- Inject
noOp
policy in our tests - Make polly return
TimeoutRejectedException
, even though not applying the real timeout policy (because of obvious reasons) - Assert our code behaves correctly on the policy result. (We make decisions based on the
FinalException
property on the policy result)
I’ve tried to narrow this down as much as I can while still making it useful and hopefully understandable.
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
c# - Polly retry unit test
It allows you to inject exceptions, return BadRequests and etc. in order to trigger Polly's fault and resilience policies such as WaitAndRetry ....
Read more >Testing Your Code When Using Polly | no dogma blog
What my code should do if there was no policy in place. I have a few classes to demonstrate these scenarios, BusinessLogic.cs and ......
Read more >Must be able to assert result from Polly in unit tests
There's the noOp policy that is recommended to be used in tests. This class allows your code to bypass polly itself, ignoring timeouts...
Read more >Build a resilient .NET service with Polly Retry Policy and ...
Writing a solid and resilient cloud service requires writing quality unit tests. Good unit tests will give developers confidence and improve code quality....
Read more >Retry and fallback policies in C# with Polly - Jacob Duijzer
Let's try and create a unit test to test the behavior of the circuit breaker. After adding some logging to the service and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jiimaho Added to the Polly [unit-testing documentation)(https://github.com/App-vNext/Polly/wiki/Unit-testing-with-Polly), to reflect this approach.
Close via #317