NUnit3TestAdapter errors when running xUnit tests
See original GitHub issueMy .NET Core codebase has a mix of xUnit and NUnit tests which all get built into the same directory with something like:
dotnet build -o c:\some\shared\dir .\my.sln
When I try to run some xUnit tests with:
dotnet vstest c:\some\shared\dir\xunit-test.dll
…the tests pass but I see an error in the console:
Error initializing RunSettings. Default settings will be used
System.IO.FileNotFoundException: Could not load file or assembly 'System.Xml.XPath.XmlDocument, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.Xml.XPath.XmlDocument, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at NUnit.VisualStudio.TestAdapter.AdapterSettings.Load(String settingsXml)
at NUnit.VisualStudio.TestAdapter.NUnitTestAdapter.Initialize(IDiscoveryContext context, IMessageLogger messageLogger) in D:\repos\nunit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnitTestAdapter.cs:line 126
Exception System.IO.FileNotFoundException, Exception thrown executing tests
Could not load file or assembly 'System.Xml.XPath.XmlDocument, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
at NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor.RunAssembly(String assemblyPath, TestFilter filter)
at NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor.RunTests(IEnumerable`1 sources, IRunContext runContext, IFrameworkHandle frameworkHandle) in D:\repos\nunit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnit3TestExecutor.cs:line 99
It seems that NUnit’s test adapter is selected first and fails, so dotnet test moves on to the xUnit adapter, which runs the tests. Note that I don’t see this error if:
- I use
dotnet publishinstead ofdotnet build(System.Xml.XPath.XmlDocument.dll is copied into the target directory) - I use
dotnet testinstead ofdotnet vstest
The error is similar to what’s described in #589, but the repro seems very different so I didn’t want to muddy that issue.
Environment
NUnit 3.11.0 NUnit3TestAdapter 3.11.0 .NET Core SDK 2.2.202 Windows 10.0.17763 (RS5)
Repro (from PowerShell)
mkdir ~\projects\xunit-nunit-clash
cd ~\projects\xunit-nunit-clash
dotnet new xunit -n xunit-test
dotnet new nunit -n nunit-test
dotnet build .\xunit-test\ -f netcoreapp2.2 -o ..\bin\
dotnet build .\nunit-test\ -f netcoreapp2.2 -o ..\bin\
dotnet vstest .\bin\xunit-test.dll
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (9 by maintainers)
Top Results From Across the Web
NUnit won't run my unit tests; says that the test adapter is ...
I have a C# solution containing an NUnit test project. This project is refusing to run any tests; they are found by discovery...
Read more >Tests not running in Test Explorer
Setting it as x64 caused a "The framework 'Microsoft.NETCore.App', version '3.1.0' was not found." error in the test error output.
Read more >nunit tests discovered but not running
Hi, I have NUnit 3.12 and Nunit3TestAdaptor 3.15.1 installed, using VS2019 community. I am able to discover the tests in the test explorer ......
Read more >NUnit tests is not found or do not run in Visual Studio's ...
Almost always when I face this issue, the problem is that the project does not have any Test Adapter or Runner installed, and...
Read more >Adapter V3 Release Notes
648 NUnit3TestAdapter 3.15.0 fails to run test: "NUnit failed to load" (when ... 222 NUnit3TestAdapter errors when running xUnit tests.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Noticed the release this morning…thanks!
Ahh… I see. I’m trying to get the dates correct, but I got a few days delayed here due to travels during the summer vacation. Normally a good time for releasing stuff, but not this year 😉
Hope it works for your production code 😃