Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Xunit issue with ICollectionFixture<T>
Denny
#1 Posted : Friday, December 13, 2019 4:45:26 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/12/2019(UTC)
Posts: 2
Location: United States of America

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;
Quote:
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.


Code:


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(){
       .....
    }
}





Remco
#2 Posted : Friday, December 13, 2019 10:32:35 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
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.
Denny
#3 Posted : Monday, December 16, 2019 5:12:01 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/12/2019(UTC)
Posts: 2
Location: United States of America

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
Remco
#4 Posted : Monday, December 16, 2019 11:22:18 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
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).
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.034 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download