JoshKeegan / xRetry

Retry running tests via Xunit and Specflow
MIT License
46 stars 15 forks source link

Retry does not work with Xunit.DependencyInjection #131

Closed ildar-shamilov-clearscale closed 1 year ago

ildar-shamilov-clearscale commented 2 years ago

I have reference to Xunit.DependencyInjection version in my project "8.3.0". After hours of struggling to get Retry work - i removed this package from test project and got it work.

Is it possible to fix? Any workaround? Maybe update documentation that this libs are incompatible?

Thank you.

JoshKeegan commented 2 years ago

Hi, Sorry to hear you've had problems with getting these libraries to work together. Generally xRetry should work alongside other xunit plugins because we're adding new attributes (RetryFact and RetryTheory) rather than modifying the behaviour of the built-in ones and xunit is designed to be extensible in this way.

I've had a quick look at Xunit.DependencyInjection and it looks like it needs to modify the test discovery process which is likely what is causing this issue. e.g. it may only be looking for FactAttribute rathern than for any attribute that has an XunitTestCaseDiscoverer attribute itself, which would prevent it from picking up the RetryFact. Are you able to raise the issue with Xunit.DependencyInjection? Someone familiar with that codebase should be able to explain whether this incompatibility is by design or a bug.

JoshKeegan commented 2 years ago

Any update on this @ildar-shamilov-clearscale?

JoshKeegan commented 1 year ago

Will require a new package in Xunit.DependencyInjection that integrates with xRetry. Have started work on this here.

Basic functionality is working, retry theory with non-serializable test data needs doing (failing test case added).

JoshKeegan commented 1 year ago

PR raised to integrate with Xunit.DependencyInjection: https://github.com/pengweiqhca/Xunit.DependencyInjection/pull/75

Once released, it would be used by adding the nuget package Xunit.DependencyInjection.xRetry to your project, and then updating the DI wireup in your tests (usually Startup.cs) to add xRetry support, e.g.

public void ConfigureServices(IServiceCollection services) =>
    services.AddXRetrySupport();

[RetryFact] and [RetryTheory] can then be used as normal throughout your test project, as well as being able to inject dependencies into your test classes. Transient & scoped dependencies are isolated to each attempt, so each attempt runs as if it were an independant test, only sharing state if the dependency is registered as a singleton.

pengweiqhca commented 1 year ago

https://www.nuget.org/packages/Xunit.DependencyInjection.xRetry/

JoshKeegan commented 1 year ago

I've tested the pre-release packages together and it's all working fine 👍. Thanks for releasing it so quickly @pengweiqhca.

xRetry v1.9 is now released, and the PR to make Xunit.DependencyInjection.xRetry not prerelease any more is raised: https://github.com/pengweiqhca/Xunit.DependencyInjection/pull/77 so I'll close this.

@ildar-shamilov-clearscale please let us know how you get on using these together and re-open this if you still have problems.

pengweiqhca commented 1 year ago

Xunit.DependencyInjection.xRetry 8.0.0 has released.