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

Notification

Icon
Error

Xunit.DependencyInjection and OperationCanceledException
GreenMoose
#1 Posted : Wednesday, October 30, 2024 11:38:24 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 6/17/2012(UTC)
Posts: 507

Thanks: 145 times
Was thanked: 66 time(s) in 64 post(s)
[v5.10.0.7]

I bumped into a test project that is using Xunit.DependencyInjection which is quite impossible to run with NCrunch.

I tried creating a separate project with just below content, and the test fails if NCrunch runs it in an existing test runner process (but succeeds when running in a new process).

Code:

//XUnit                                  2.9.2
//xunit.runner.visualstudio      2.8.2
//Xunit.DependencyInjection   9.5.0

public class Startup
{
    
        public void ConfigureServices(IServiceCollection services)
        {
            //services.AddTransient<IDependency, DependencyClass>();
        }
    
}

public class DummyTest
{
    [Fact]
    public void DoSomething()
    {
/* test error when running in existing test runner process:
System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.Threading.CancellationToken.ThrowIfCancellationRequested()
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Xunit.DependencyInjection.DependencyInjectionTestFrameworkExecutor.RunTestCases(IEnumerable`1 testCases, IMessageSink executionMessageSink, ITestFrameworkExecutionOptions executionOptions) in S:\GitHub\Xunit.DependencyInjection\src\Xunit.DependencyInjection\DependencyInjectionTestFrameworkExecutor.cs:line 51
*/
    }
}


Is this a known issue and/or workaround for this behavior?

Thanks.
GreenMoose
#2 Posted : Wednesday, October 30, 2024 1:09:57 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 6/17/2012(UTC)
Posts: 507

Thanks: 145 times
Was thanked: 66 time(s) in 64 post(s)
FWIW, I probably can remove the package all together for this project so it isn't a big issue for now, but it seems to be quite a popular nuget package so it maybe can be interesting to look into if it is NCrunch's behavior or the package itself that is causing it.
Remco
#3 Posted : Wednesday, October 30, 2024 11:14:44 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,147

Thanks: 961 times
Was thanked: 1294 time(s) in 1200 post(s)
Hi, thanks for sharing this issue.

This tool seems to be deeply integrated with Xunit. It implements its own runner classes and changes the behaviour of the test framework itself. I don't know of a way to use this with NCrunch out of the box. We'd probably need to undertake a small project to introduce a separate test adapter for it, which probably isn't worth the effort given that Xunit v3 changes all of this anyway.

Sorry, we can't support this tool.
1 user thanked Remco for this useful post.
GreenMoose on 10/31/2024(UTC)
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.025 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download