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

Notification

Icon
Error

xunit v3, missing xunit.v3.runner.inproc.console net6.0?
GreenMoose
#1 Posted : 26 days ago
Rank: Advanced Member

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

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

Trying out xunit v3 but NCrunch is returning error below for me
Quote:

An error occurred while analysing this project after it was built: Unable to resolve an assembly required for the execution of Xunit3 on this machine. The assembly was expected at the following path: C:\Users\myUser\.nuget\packages\xunit.v3.runner.inproc.console\2.0.0\lib\net6.0\xunit.v3.runner.inproc.console.dll


it is a library project (TargetFramework net8.0, referencing xunit.v3.extensibility.core 2.0.0) which is referenced by XUnit test project.

I have the library Ncrunch is requesting in C:\Users\myUser\.nuget\packages\xunit.v3.runner.inproc.console\2.0.0\lib\net8.0 and net472 (but not net6.0).

*Edit: Using xunit.v3.core instead of xunit.v3.extensibility.core seems to have solved it for NCrunch, but then it fails with dotnet test (related https://github.com/xunit/xunit/issues/3205 )
Remco
#2 Posted : 25 days ago
Rank: NCrunch Developer

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

Thanks: 975 times
Was thanked: 1313 time(s) in 1218 post(s)
I think the answer here depends on what you are trying to achieve.

There's a couple of constraints that you're probably now aware of:
- Using NCrunch with Xunit3 requires a reference to xunit.v3.core (I think this is reasonable, as we need to know where to resolve it via a primary dependency)
- The default non-NCrunch xunit runner requires all test projects to be EXEs with UseAppHost=true, which means that you can't have runnable xunit tests inside a DLL outside of NCrunch

So I guess the question is whether or not you intend to have tests inside this library be run by Xunit3. If you do, you'll need to set it up as an apphosted EXE so that Xunit stays happy outside of NCrunch.

If you don't, then you'll need to use NCrunch's configuration setting to turn off Xunit3 integration for this particular project, so NCrunch doesn't try to scan it for tests and complain with the error.
1 user thanked Remco for this useful post.
GreenMoose on 3/6/2025(UTC)
RyanSullivanNET
#3 Posted : 19 days ago
Rank: Newbie

Groups: Registered
Joined: 3/12/2025(UTC)
Posts: 9
Location: United States of America

Thanks: 1 times
I'm having the same issue as Green Moose. NCrunch is not working for me.

NCrunch simply won't run tests. Digging into this, I sometimes find an analysis failure in the NCrunch Processing Queue, sometimes I don't.

An error is sometimes reported in the NCrunch Tests window:

An error occurred while analysing this project after it was built: Unable to resolve an assembly required for the execution of Xunit3 on this machine. The assembly was expected at the following path: C:\Users\rjs\.nuget\packages\xunit.v3.runner.inproc.console\2.0.0\lib\net6.0\xunit.v3.runner.inproc.console.dll
Please ensure the package containing this assembly is installed on your machine. If you introduce an assembly reference directly to this binary in your test project, NCrunch will resolve it directly using your specified path.

I don't understand Remco's mention of the second constraint "The default non-NCrunch xunit runner requires all test projects to be EXEs with UseAppHost=true". I can't find any useful information about that in Google searches, and it's not in the xunit v3 documentation.

I tried turning off xUnit 3 integration in NCrunch configuration. It then effectively ignored all of my tests, which isn't helpful.

Unfortunately, Remco's post didn't help me much.

In the Test project, I added the following when we upgraded to xUnit v3:
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>

<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="xunit.v3" Version="2.0.0" />

Maybe this will help shed some light on why NCrunch is failing (stopping) during the analysis, and won't run any tests?
Remco
#4 Posted : 18 days ago
Rank: NCrunch Developer

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

Thanks: 975 times
Was thanked: 1313 time(s) in 1218 post(s)
Hi, thanks for sharing this problem.

Could you confirm which build of NCrunch you're running? If you aren't on 5.13, could you try the build posted in this thread and let me know if this solves the problem for you?
RyanSullivanNET
#5 Posted : 18 days ago
Rank: Newbie

Groups: Registered
Joined: 3/12/2025(UTC)
Posts: 9
Location: United States of America

Thanks: 1 times
I have been running NCrunch 5.12.0.10. I'll work on getting 5.13 installed (on the thread you mentioned), and will get back to you.
RyanSullivanNET
#6 Posted : 13 days ago
Rank: Newbie

Groups: Registered
Joined: 3/12/2025(UTC)
Posts: 9
Location: United States of America

Thanks: 1 times
I uninstalled NCrunch 5.12.0.10 for Visual Studio, and installed NCrunch_VS2022_5.13.0.1.msi.

NCrunch now builds and runs the tests, but I noted the following:
- The "Test Explorer" window no longer displays any tests in the window. I understand this is probably not your concern, but it is strange none-the-less.
- It is very slow. All the tests take minutes to run, where they used to take seconds.

I re-ran the configuration wizard, and allocated 75% of my 24 cores to NCrunch (previously 50%), and it helped a little, but still took a long time. I tried again, and noted that the Red stop button didn't stop the rest of the tests from running.

I noticed that the NCrunch Diagnostic Support log didn't note the start/stop times, so I used a Stopwatch to manually track the time it took to execute 2193 tests. It took 2 minutes, 21 seconds to finish.

Previous to doing this, MS Test was executing all of the unit tests in under 2 seconds.

At the command line, I ran the unit test project's output (xUnit v3 now makes the Test project an exe) executable. The output indicates that it ran the 2193 tests in 0.846 seconds.

RyanSullivanNET
#7 Posted : 13 days ago
Rank: Newbie

Groups: Registered
Joined: 3/12/2025(UTC)
Posts: 9
Location: United States of America

Thanks: 1 times
I tried turning off RDI (I set "Enable RDI" to False in the NCrunch Configuration) to see if performance would improve, and clicked "Reset" in the NCrunch Tests window in Visual Studio 2022. It took 3 minutes and 17 seconds to complete. I didn't see anything in the NCrunch Diagnostic Output.
Remco
#8 Posted : 13 days ago
Rank: NCrunch Developer

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

Thanks: 975 times
Was thanked: 1313 time(s) in 1218 post(s)
Could you share any more detail about the nature of your tests? Are you pushing a large amount of trace data through ITestOutputHelper? Does the NCrunch Hotspots view give any indication on where tests are taking so much time to run?
RyanSullivanNET
#9 Posted : 13 days ago
Rank: Newbie

Groups: Registered
Joined: 3/12/2025(UTC)
Posts: 9
Location: United States of America

Thanks: 1 times
Most of these tests are fairly simple xunit tests.

I'm not familiar with ITestOutputHelper.

I'm not familiar with NCrunch Hotspots, but I'll open that and watch it during the execution of the tests.
Remco
#10 Posted : 13 days ago
Rank: NCrunch Developer

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

Thanks: 975 times
Was thanked: 1313 time(s) in 1218 post(s)
There's a couple of key places to watch when analysing a performance issue like this one.

The first is in the execution of the test code itself. The coverage markers give an indication of line-by-line performance, and you can use the Hot Spots tab in the Tests Window to get an overview of where the test spent most of its time in the run.

The second is in the 'Execution Steps' tab under the Tests Window. This basically gives a tree of wall times around the entire test execution activity (which includes various build steps, infrastructure, and calling into the test framework itself).

Performance problems that are specific to your code will likely show up using the first one. If you see a wide difference in times being reported between these two analysis options, then it's quite likely that the performance issue is in Xunit itself or in how NCrunch is interacting with Xunit.
RyanSullivanNET
#11 Posted : 13 days ago
Rank: Newbie

Groups: Registered
Joined: 3/12/2025(UTC)
Posts: 9
Location: United States of America

Thanks: 1 times
I ran the tests with NCrunch Hot Spots open, and then refreshed it once the tests were run. I exported it, and copied the last three columns (for the first 66 lines) to put them here:


Max Execution Time Average Execution Time Total Execution Time
250 70 281
235 235 235
204 15 220
203 3 218
188 28 717
188 26 920
187 25 249
141 28 141
141 141 141
141 25 203
141 14 482
141 14 482
141 17 435
140 3 203
125 31 125
125 125 125
110 11 373
110 3 110
109 5 188
94 8 94
94 94 94
94 9 280
94 47 94
94 4 1107
94 24 94
79 79 79
79 79 79
78 78 78
78 4 218
78 11 78
78 78 78
78 9 94
63 1 95
63 40 79
63 5 63
63 32 126
63 63 63
63 40 79
62 5 124
62 5 124
62 16 62
62 62 62
62 62 62
62 16 62
47 2 220
47 1 63
47 12 47
47 3 47
47 1 111
47 5 47
47 32 63
47 4 47
47 8 47
47 47 47
47 1 47
47 24 47
47 47 47
47 47 47
47 47 47
47 47 47
47 9 47
47 5 95
47 47 47
47 2 47
47 2 47

I'm not familiar with NCrunch Hot Spots, so maybe there is better info elsewhere.

I ran a small number of unit tests, watching the 'Execution Steps' tab under the NCrunch Tests window, and didn't see anything in it. I then clicked the "Run all tests" button, watching the 'Execution Steps' tab, and didn't see anything in it.

I don't think there is a performance problem with my unit tests. When I run the unit tests by executing the Test project exe, I get the following output (names redacted):

xUnit.net v3 In-Process Runner v2.0.0+229879b765 (64-bit .NET 8.0.13)
Discovering: <redacted>
Discovered: <redacted>
Starting: <redacted>
Finished: <redacted>
=== TEST EXECUTION SUMMARY ===
<redacted> Total: 2193, Errors: 0, Failed: 0, Skipped: 0, Not Run: 0, Time: 0.565s

When I run "dotnet test redacted.sln" in the command line I get the following (names redacted):

Determining projects to restore...
All projects are up-to-date for restore.
<redacted> -> C:\work\<redacted>-project\<redacted>\<redacted>\bin\Debug\net8.0\<redacted>.dll
<redacted> -> C:\work\<redacted>-project\<redacted>\<redacted>\bin\Debug\net8.0\<redacted>.dll
Test run for C:\work\<redacted>-project\<redacted>\<redacted>\bin\Debug\net8.0\<redacted>.dll (.NETCoreApp,Version=v8.0)
VSTest version 17.11.1 (x64)

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.

Passed! - Failed: 0, Passed: 2193, Skipped: 0, Total: 2193, Duration: 475 ms - <redacted>.dll (net8.0)
Remco
#12 Posted : 13 days ago
Rank: NCrunch Developer

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

Thanks: 975 times
Was thanked: 1313 time(s) in 1218 post(s)
Thanks for these extra details.

It looks like there is a performance issue when running a large number of fast executing Xunit3 tests under NCrunch.

I'm raising this with the Xunit team to see what options are available. It isn't possible to fix this in NCrunch itself (the problem is related to how Xunit handles its internal messaging).

Sorry, I can't provide a workaround for this at the moment. If you have the option, I recommend downgrading to Xunit2 until we can provide a resolution.
1 user thanked Remco for this useful post.
RyanSullivanNET on 3/18/2025(UTC)
RyanSullivanNET
#13 Posted : 13 days ago
Rank: Newbie

Groups: Registered
Joined: 3/12/2025(UTC)
Posts: 9
Location: United States of America

Thanks: 1 times
Thanks for the recommendation (to downgrade xunit).
RyanSullivanNET
#14 Posted : 13 days ago
Rank: Newbie

Groups: Registered
Joined: 3/12/2025(UTC)
Posts: 9
Location: United States of America

Thanks: 1 times
I removed the xunit.v3 NuGet package and added the xunit NuGet package version 2.9.3. I also removed a couple things in the project file that were recommended by the xunit documentation when migrating to xunit3.

The performance problem still exists. Using a manual stopwatch, 2193 unit tests took 1 minute, 56 seconds to run with NCrunch 5.13.0.1 installed.

In a PowerShell window, I ran dotnet test .\<redacted>.sln. It took 5-10 seconds to run, but provided the following output (names redacted):

Determining projects to restore...
All projects are up-to-date for restore.
<redacted> -> C:\work\<redacted>-project\<redacted>\<redacted>\bin\Debug\net8.0\<redacted>.dll
<redacted> -> C:\work\<redacted>-project\<redacted>\<redacted>\bin\Debug\net8.0\<redacted>.
dll
Test run for C:\work\<redacted>-project\<redacted>\<redacted>\bin\Debug\net8.0\<redacted>.dll (.NETCoreApp,Version=v8.0)
VSTest version 17.11.1 (x64)

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.

Passed! - Failed: 0, Passed: 2193, Skipped: 0, Total: 2193, Duration: 590 ms - <redacted>.dll (net8.0)

As you can see, it took 590 milliseconds to run all of the tests, once the command hit it's stride (took a few seconds for it to do that).

I'll try reverting NCrunch back to 5.12, and see if the problem still exists.


RyanSullivanNET
#15 Posted : 13 days ago
Rank: Newbie

Groups: Registered
Joined: 3/12/2025(UTC)
Posts: 9
Location: United States of America

Thanks: 1 times
I reverted to NCrunch 5.12.0.10. Initially the long runtime of unit tests was the same.

At that point, I re-ran the Configuration Wizard, and on the RDI page, I turned off RDI for the solution.

Suddenly, unit tests ran faster. Now when I press the "Run all tests" button, they all run in 1-3 seconds.
Remco
#16 Posted : 13 days ago
Rank: NCrunch Developer

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

Thanks: 975 times
Was thanked: 1313 time(s) in 1218 post(s)
A couple of points here:

- I have cornered and confirmed that tests under Xunit3 are taking much longer to execute under NCrunch than they should be. An Xunit2 test that runs in 0ms takes about 100ms on my machine (this is the issue I've described above).

- RDI does have a significant performance impact, depending on the tests and code being run. There is quite a bit you can do to mitigate this (the RDI guide has more information here). It's likely that you have some tests impacted more than others, and there are also infrastructure considerations (i.e. RDI is much more I/O heavy than normal execution).
anemitoff
#17 Posted : 13 days ago
Rank: Newbie

Groups: Registered
Joined: 11/4/2017(UTC)
Posts: 3
Location: United States of America

I too had the problem with xunit.v3 and xunit.v3.runner.inproc.console not found.
Installing NCrunch 5.13.0.1 did allow the test projects to build and execute.

I have a few tests of Blazor components using BUnit where I get the following error (which doesn't occur under `dotnet test`). *This error is fine* as I expect the behavior of which thread is executing my code to vary:
`An exception was thrown in the Task Environment: System.InvalidOperationException: The current thread is not associated with the Dispatcher. Use InvokeAsync() to switch execution to the Dispatcher when triggering rendering or component state.`

*The Problem* is that on the test method line which triggers the exception, I do not see the "X". In fact my test method results in a failure, but no line is blamed for the failure. I need to debug with a break on "InvalidOperationException" enabled to find the source of the error. I swear that in the past when I encountered the same problem NCrunch was able to show me the source line of the error.
Remco
#18 Posted : 12 days ago
Rank: NCrunch Developer

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

Thanks: 975 times
Was thanked: 1313 time(s) in 1218 post(s)
Hi, thanks for sharing this issue.

Issues like this involving multiple threads can be difficult to diagnose as there are often environmental factors and race conditions involved.

It's possible the exception is being thrown in platform code in a place where there is no stack trace that aligns with your own code.

The inline exception reporting in NCrunch actually works by trapping and parsing exceptions that are shown in the Tests Window trace output. We take the exception, parse every line of it and then overlay it over your code.

If the exception doesn't contain any stack elements that align with your code, or NCrunch was unable to trap it, then there won't be any visible indication of the exception inline.
Remco
#19 Posted : 12 days ago
Rank: NCrunch Developer

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

Thanks: 975 times
Was thanked: 1313 time(s) in 1218 post(s)
I've raised the performance issue above with Brad Wilson (Xunit developer) and he's created a ticket for it: https://github.com/xunit/xunit/issues/3228.

The background for this is that Xunit has two modes of operation for reporting of test results. One is asynchronous (used by other test runners), the other is synchronous (used by NCrunch). NCrunch requires test results to be reported synchronously because we need to track the definite start and end point of each test, otherwise all our metrics tracking (code coverage, performance, RDI) goes askew.

This problem occurs in Xunit primarily when it's set to report results synchronously. Actually, it probably happens to a degree when it's asynchronous too, but the async architecture provides significant compensation by moving work onto background threads.

The mentioned ticket suggests a possible optimisation which would greatly reduce the overhead for reporting test results when working with an in-memory runner (such as NCrunch), thereby preventing the synchronous reporting from slowing down the runner.

Xunit3 is still very new and we're still working out the kinks here. I appreciate your patience with this issue.
1 user thanked Remco for this useful post.
erwinvandervalk on 3/19/2025(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.138 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download