Force test class to run tests in serial.
[TestFixture]
[NonParallelizable]
Make production assembly internals visible through Info.cs
file to unit test assemblies:
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("MyProj.UnitTests")]
// Assert contains
Assert.That(ex.InnerException.Message, Does.Contain("Issue cannot be empty" ).IgnoreCase);
// Assert property throws exception
Assert.Throws<Exception>(() => { var i = sut.ExistsButIsNotInt; });
// Assert that two IEnumable lists have equal contents
Assert.That(result, Is.EquivalentTo(headerList));
Create new .NET Core project, then:
- Delete any
Program.cs
- Remove any output type in .csproj
- Add required references to nuget packages:
- Microsoft.NET.Test.Sdk
- NUnit
- NUnit3TestAdapter
Bare bones test .csproj file example:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\MyProj\MyProj.csproj" />
</ItemGroup>
</Project>