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

Tests using ICollectionFixture are still retried when fixture initialize fails #182

Open
vedion opened this issue Jun 30, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@vedion
Copy link

vedion commented Jun 30, 2023

Hi,

I have a case where an exception is thrown when initializing my fixture used in ICollectionFixture, ex:

[CollectionDefinition(nameof(MyCollectionFixture))]
public class MyCollectionFixture : ICollectionFixture<MyFixture>
{
}

public class MyFixture : IAsyncLifetime
{
   public async Task InitializeAsync()
   {
      throw new NullReferenceException("TEST");
   }
}

[Collection(nameof(MyCollectionFixture))]
public class MyTest
{
   public MyTest(MyFixture myFixture)
   {
       this.fixture = myFixture;
    }

    [RetryFact]
    public When_X_Then_Y()
    {
    }
}

I the above example MyFixture.InitializeAsync will be only be called once and the code in test "When_X_Then_Y" will be hit twice.

Would it be possible to look at "TestCollectionStarting" and "TestCollectionFinished" in MessageTransformer so the tests are not retried if the test failed between state "TestCollectionStarting" and "TestCollectionFinished":
https://github.com/xamarin/xunit/blob/master/src/xunit.execution/Sdk/Frameworks/Runners/TestCollectionRunner.cs

With the current code the exception in the fixture is hidden.

Best Regards,
Anders Havn

@JoshKeegan
Copy link
Owner

Hi Anders,
Thanks for reporting this, it isn't something I'd considered before now.

I wonder if we should also retry failures creating the fixture, that way a transient failure in the fixture creation would also be retried. I haven't yet looked into whether that would be possible, but would that work for your use-case?

@JoshKeegan JoshKeegan added the bug Something isn't working label Jul 5, 2023
@vedion
Copy link
Author

vedion commented Jul 5, 2023

Hi,

Thank you for the response. Yes, that would also work for my use-case :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants