Skip to content

Would like updated docs on Unit Testing or a Fakeable/Mockable Polly #685

Description

@CreepyGnome

In your doc about Unit Testing with Polly, you provide only broad information, you provide no concrete examples of how.

https://github.com/App-vNext/Polly/wiki/Unit-testing-with-Polly

Could you please provide more specifics and actual examples of how to unit test around Polly and a NoOpPolicy helps in any way.

Either I am using Polly wrong (but I am following your docs on how to use it so I assume I am not) but there is no way to swap out a Policy as you create them via static methods on the Policy class and this is usually inside private areas of classes or at least within a public method. Typically, in my experience at least, Polly is encapsulated within classes so how can I swap out my policy generated based on business rules with this NoOp one?

I don't want to test Polly but I do need to test things around it and make sure Polly is removed. I mean if you had an IPolicy that I can inject via a constructor into a class and then I can inject a NoOp / Null type policy that then pretends to do the work, but that I can then capture the Func that needs to be executed.

This brings up another issue that since the Func contains our code that we would like to test is correct and has not changed there is no mention of how to do that. So this could use concrete examples of how to do this as well.

The doc also talks about using your ISyncPolicy, ISyncPolicy, IAsyncPolicy and IAsyncPolicy interfaces however I see no way to do this in my code as I never am returned any of these interfaces and I don't see anything I use that takes them. Everything is Policy, PolicyBuilder, or a Func for what I use in Polly. So this could use concrete examples as well of how to do what you are briefly describing.



Describe your proposed or preferred solution:

To either update the docs to show how to unit test around Polly or to make Polly be Mockable via interfaces. Currently, you don't have an IPolicy or IPolicyBuilder interfaces if you did and these are what drove the start of all policies then it would be easy to understand and use common unit testing practices to mock them.



Describe any alternative options you've considered:
Only alternatives I can see is passing in a Policy to the constructor of a repository or service and then but expect it to be null always, except for unit tests. If null just use the static methods as they are, otherwise use the one provided however this seems challenging as I still have to call those static methods that are on the abstract base class Policy.

It seems that you expect the developers to mock your concrete classes and didn't really make the Polly library Unit Test friendly so that it can easily be mocked or faked away easily.

So I guess I have been using Polly wrong all these years as this is the first time I've wanted to test a class that uses Polly and I want to mock/fake away Polly as I only test my code, not external code. Which if I am having the concrete examples of how you expect us to write our code in a way that allows Polly to be easily mocked/faked away so that we can focus on testing just our code and not yours.



Any additional info?

No.

No activity

Activity on this issue will appear here.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions