Build/Test Issues

Xunit issue with ICollectionFixture<T>

Started by Denny on 5,531 views

My intention is to create a single test context and share it among my integration tests in several test classes, and have it cleaned up after all the tests in the test classes have finished.

Based on this article my implementation should work;
Xunit v2+
NCrunch V2.6 introduced direct integration with Xunit V2. Xunit V1 tests will continue to execute using the older Gallio adapter, while Xunit V2+ tests are run through NCrunch calling directly into the Xunit test runner.


My current versions:
NCrunch Version: 4.1.0.1
NCrunch # of CPU Core: 1
NCrunch Max Processing Threads: 1
Xunit Version: 2.3.1

Study Cases:

  • When I run multiple times my tests using the option `Run selected test(s) with debugger` all my tests (more than 700) pass correctly.
  • When I run my tests using `Run selected test(s) in a new process` all my tests fail.
  • When I run my tests using `Run all test(s) visible here` all my tests fail.




public class IntegrationTestServer : IDisposable{
 public IntegrationTestServer()
        {           
            InitialiazeDataBases(); 
            InitializeIdentityServer();
            InitializeClientApi();
        }
          ......
}

[CollectionDefinition("IntegrationTestServer")]
public class DatabaseCollection : ICollectionFixture<IntegrationTestServer>
{
        // This class has no code, and is never created. Its purpose is simply
        // to be the place to apply [CollectionDefinition] and all the
        // ICollectionFixture<> interfaces.
}

[Collection("IntegrationTestServer")]
public class EventEntriesControllerIntegrationTest
{       
    private readonly IntegrationTestServer _fixtureServer;
    public EventEntriesControllerIntegrationTest(IntegrationTestServer fixtureServer)
   {
        _fixtureServer = fixtureServer;
   }
  
    [Fact]
    public async Task Should_RemoveEvent(){
       .....
    }
}





Hi, thanks for posting!

Can you share any more specific details of the failure? Does any logging code on the CollectionFixture indicate things being called out of order? This all happens under the hood for us in Xunit, we simply tell it which tests to execute.
Hi, this is what I get:

When I run all the tests in debug mode everything is ok.
When I run only one test everything is ok.
When I run all the tests (without debug) this is what I get from the trace output:

Xunit.Sdk.TestClassException: The following constructor parameters did not have matching fixture data: IntegrationTestServer integrationTestServer

thanks in advance
I've had a go at trying to reproduce this problem using the same structure and configuration as you've described above. Unfortunately, the tests seem to work correctly every time for me.

Are you able to reproduce this with a sample solution that you can share with me? You can submit code in ZIP form through the contact form.

My guts says that this may be a sequencing issue in Xunit itself, perhaps surfaced by something in the environment or solution. We don't do any messing with test collection in NCrunch - we simply give Xunit a list of tests to run. If you haven't already, I suggest upgrading to the latest version of Xunit to see if this solves the problem (I think we're up to 2.4 now).

Post a reply

Log in to reply.