In .NET Framework 4.5 and below, I've got a Unit Testing Library that I like to pass around to Unit/Implementation testing projects to reduce overhead when starting a new test project.
Tonight I attempted to make a .NET Core version of it. During development, I had my Unit Test project added to the Console App solution as a local reference. After a bunch of struggling with xUnit's loss of the test runner that used to come bundled with xUnit (but was abandoned around 2.3) I came up with the following package list for the UnitTesting library.
Unit Test Library Package List
<ItemGroup>
<PackageReference Include="AutoFixture.AutoMoq" Version="4.5.0" />
<PackageReference Include="AutoFixture.Xunit2" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
<PackageReference Include="Shouldly" Version="3.0.1" />
<PackageReference Include="System.ComponentModel.TypeConverter" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.4.0" />
</ItemGroup>
Console App Follow-Up
Due to the new test adapter situation, I found that the only way to get the console app to see the unit tests was to add the following package to the app.
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0">
If this package was included in the library instead, it would not find the tests.
Problem solved.
The Problem was Not Solved
I deployed this all as a nuget package for .Net Core 2.1, unloaded the library from the console application, and pulled in the nuget package as a Dependency.
At this point the package has a build warning and it cannot reference what it had just referenced several times while as a local solution project. It suggests downshifting the version to .net Framework 4.6.1, which I think is where .net Framework starts to enter into .net Standard 2.0? This might be okay to target to achieve what I want, but I'd prefer to use .net core exclusively as this is a home project that I am doing in .net Core to learn more about it. (This may not be a hill worth dying on, I'm open to that feedback.)
I've read a lot about how .net core was using implicit versioning for its packages and it wasn't being applied correctly. I've seen several threads that I'll try and link below to show various things I've tried, but in the end, I cannot use the library if it is deployed as a nuget package, and I can if it's loaded manually into the solution.
xUnit research before I got the unit tests to be discovered
- https://learn.microsoft.com/en-us/visualstudio/releasenotes/vs2017-relnotes#testadapterextension
- https://developercommunity.visualstudio.com/content/problem/315835/unit-tests-are-not-running.html
- https://xunit.github.io/docs/nuget-packages
.NET Core 2.1 Library not Compiling in .NET Core 2.1 Application Research
- https://github.com/aspnet/Docs/issues/6430 --I believe this is the most relevant discussion of all the links for my issue
- https://forums.xamarin.com/discussion/123160/nugets-giving-error-restored-using-netframework-version-4-61-instead-of-the-target-framework
- https://github.com/dotnet/standard/issues/481
- https://github.com/xunit/xunit/issues/1767
There is some overlap on the little bits and pieces I've found under either topic. One of the more wild suggestions was to change the Project SDK to be instead of and to add to the application (or the Library? I tried both in various permutations).
I feel like I solved getting xUnit working in .NET Core 2.1, I just can't deploy it as a nupkg.
Has anyone conquered this yet? I was unable to find an answer that worked for me in any of the above, or in any of the searching on StackOverflow.
I may be mistaken, but all of the packages I have referenced, I believe, do work with .NET Core 2.1, or should based on their descriptions prior to install. This is evidenced by the application working when the unit test project is in the solution with the application.
Thanks to anyone who takes the time to read this.
-Omni