I've done a nuget install like this:
Install-Package xunit.runner.visualstudio -Version 2.2.0
On my test project.
I have a test similar to this:
public class When_Doing_Stuff_I_Want_To_Test
{
[Fact]
public void Can_Do_Stuff()
{
var result = DoStuff();
result.ShouldNotBeNull();
result.Success.ShouldBeTrue();
}
}
Although that I have done numerous VS restarts, laptop reboots, left a day in between, VS 2017 is still not able to discover my tests:
What can I do to fix this and see my tests?
Addendum
I'm working under 4.6.1, so not yet Core.
Questions regarding the same topic that did not help:
So there's a lot going round, none of it helped ...
Update
I can't get NUnit to work either, won't show up in test explorer as well.
Update 2
I wiped my project and recreated the projects like so:
Then I copied my original code and added all necessary references, no difference.
Run tests in Test Explorer If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer (or press Ctrl + E, T). As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of Project, Namespace, and Class.
To start debugging: In the Visual Studio editor, set a breakpoint in one or more test methods that you want to debug. Because test methods can run in any order, set breakpoints in all the test methods that you want to debug. In Test Explorer, select the test method(s) and then choose Debug on the right-click menu.
Sometimes, you want to write tests and ensure they run against several target application platforms. The xUnit.net test runner that we've been using supports . NET Core 1.0 or later, . NET 5.0 or later, and .
It's an open source unit testing tool for . Net framework that's compatible with ReSharper, CodeRush, TestDriven.Net, and Xamarin. You can take advantage of xUnit.Net to assert an exception type easily.
After trawling the internet, it appears that targeting NETStandard.Library can't be used for test projects...
These were the links I got information from:
What can be done is have the project you want to test use NETStandard.Library and have your test project target Microsoft.NETCore.App. Your test project can then reference the project to test and the tests will run.
The .csproj for your test project will look something like this (versions might change):
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>
The project to test would be this:
<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
</PropertyGroup>
Lately I've had to run dotnet restore on the solution to get the tests to run, so you may need to do the same. Turns out .NET Core SDK 1.0.1 was being targeted instead of 1.0.4 (I didn't have the x86 version installed).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With