nunit / nunit3-vs-adapter

NUnit 3.0 Visual Studio test adapter for use under VS 2012 or later
https://nunit.org
MIT License
203 stars 105 forks source link

NUnit3TestAdapter Could not load file or assembly 'System.Xml.XPath.XmlDocument #589

Closed nojaf closed 5 years ago

nojaf commented 5 years ago

Description

When running dotnet test ./src/Fantomas.Tests/Fantomas.Tests.fsproj -c Release --no-build --no-restore --test-adapter-path:. --logger:nunit;LogFilePath=../../TestResults.xml I receive binding redirect problems when --test-adapter-path:. --logger:nunit;LogFilePath=../../TestResults.xml is listed.

I run dotnet test in Docker container with Mono.

root@1557e3fc5b04:/var/fantomas# dotnet test ./src/Fantomas.Tests/Fantomas.Tests.fsproj -c Release --no-build --no-restore --test-adapter-path:. --logger:nunit;LogFilePath=../../TestResults.xml
Test run for /var/fantomas/src/Fantomas.Tests/bin/Release/net452/Fantomas.Tests.dll(.NETFramework,Version=v4.5.2)
Microsoft (R) Test Execution Command Line Tool Version 15.9.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
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' or one of its dependencies.
File name: 'System.Xml.XPath.XmlDocument, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
  at NUnit.VisualStudio.TestAdapter.AdapterSettings.Load (Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter.IDiscoveryContext context) [0x0002c] in <f493a5db9def4c1aabc9cacba002189d>:0
  at NUnit.VisualStudio.TestAdapter.NUnitTestAdapter.Initialize (Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter.IDiscoveryContext context, Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.IMessageLogger messageLogger) [0x00054] in <f493a5db9def4c1aabc9cacba002189d>:0
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' or one of its dependencies.
  at NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor.RunTests (System.Collections.Generic.IEnumerable`1[T] sources, Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter.IRunContext runContext, Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter.IFrameworkHandle frameworkHandle) [0x0005c] in <f493a5db9def4c1aabc9cacba002189d>:0
No test is available in /var/fantomas/src/Fantomas.Tests/bin/Release/net452/Fantomas.Tests.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
Results File: /var/fantomas/src/Fantomas.Tests/TestResults/TestResults.xml

I think the problem is that NUnitTestAdapter cannot find System dll in Mono. Workaround might be including netfx.props.

Info

Workaround

Leave the --test-adapter-path:. --logger:nunit;LogFilePath=../../TestResults.xml out.

Steps to reproduce.

docker run -it -w "/var" dcurylo/fsharp-mono-netcore:2.1.503 bash

In container:

git -c http.sslVerify=false clone -b fake-5 https://github.com/nojaf/fantomas.git cd fantomas bash install.sh

Maybe should need chmod 755 *.sh, if you cannot run the script.

Run tests:

dotnet test ./src/Fantomas.Tests/Fantomas.Tests.fsproj --test-adapter-path:. --logger:nunit;LogFilePath=../../TestResults.xml

OsirisTerje commented 5 years ago

Hi! There are a bit too many moving parts here. Is it possible to try to reduce the complexity to see what is really going on? The error message says it can't read the runsettings file, and that seems to be due to the fact it cant load the systems xml component, which is weird. If you run this in a windows .net environment, does it then work?

(I assume this error will be the same with the latest adapter version, that is, I don't know of any changes there that would affect this)

rprouse commented 5 years ago

I'm curious, why are you using dotnet test to run your tests when they target .NET 4.5.2? It should work but we don't do much testing of that scenario with Mono. Normally people would use the NUnit Console to run tests in that scenario.

The odd thing is, dotnet test running against a 4.5.2 target should load the .NET Framework version of the adapter which references version 4.0.0.0 of System.Xml.XPath.XmlDocument. Even if it was loading the .NET Core version of the adapter, that has a dependency on System.Xml.XPath.XmlDocument version =>4.3.0.

nojaf commented 5 years ago

Hi, so this works on Windows. I'm guessing on full framework it cannot resolve the System.Xml.XPath.XmlDocument dll when the full framework is Mono. Same reason my own code uses netfx.props. I believe this could actually fix it.

I use dotnet test to tackle both targets in one command.