You often want to unit test non-public methods and classes in .NET, but you don’t want to make them public. The most common solution is to make the methods and classes internal and access them from your unit test project using the InternalsVisibleTo attribute.
There are three different versions of the NUnit Console runner on NuGet. This can be confusing for new users who don’t know which one to pick. The NUnit team has tried to make it easier to pick by changing the titles and descriptions, but Visual Studio shows the package name. Extensions add to the confusion, thus this guide. (more…)
Most .NET developers write code using Visual Studio, so it is convenient to be able to run and debug your NUnit tests from within Visual Studio. There are commercial products like TestDriven.NET, NCrunch and Resharper that can run your tests, but the NUnit Visual Studio Adapter is free and works in all current editions of Visual Studio. (more…)
In the last post, we setup an NUnit test project and ran it in Visual Studio. In this post we are going to expand on that code to add more unit tests using the NUnit TestCase attribute.
Looking back at the last post, we are testing a method that converts an enum value to a friendly string by splitting the enum name at capitals. In that post, we only tested with one enum value. In this post, we will test with multiple enum values to ensure that the method handles every type of input. We will then remove code duplication by using the [TestCase] attribute to run one test many times with different data. (more…)
Update: I have released beta 1 of dotnet-test-nunit which has been updated to the RTM of .NET Core 1.0. I have updated this post and the code on GitHub to reflect the changes.
The NUnit team has been working hard since .NET Core RC2 and ASP.NET Core RC2 was released last month to add full NUnit testing for .NET Core, and we are happy to announce the second alpha release of dotnet-test-nunit.
In my previous blog posts, I explained how to use NUnit to test .NET Core using NUnitLite which worked, but was not the ideal solution. The new dotnet-test-nunit allows you to test from the command line using the
dotnet test command and allows you to run your tests within Visual Studio. (more…)