Using NUnit’s TestCase Attribute

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…)

Read more

NUnit 3 Tests for .NET Core RC2 and ASP.NET Core RC2

Update 2: The switch from the project.json format to the new csproj format and the associated tooling changes made the dotnet-test-nunit adapter obsolete by switching the test adapter API. I have released an update to the NUnit Visual Studio Adapter that implements the new test API and supports .NET Core. If you are using Visual Studio 2017 and/or the new .NET Core tooling, see Testing .NET Core with NUnit in Visual Studio 2017.

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…)

Read more

Testing .NET Core RC2 Using NUnit 3

Update: full NUnit 3 support for .NET Core and ASP.NET Core has been released.

Things have changed since I wrote Testing .NET Core Using NUnit 3, so it is time to update the steps for .NET Core RC2.

The code from this post is on GitHub in the nunitlite and test_assembly branches. For those interested in an early peek at the new dotnet-test-nunit runner, there is an example on the master branch. (more…)

Read more

Using Ninject for Prism for Xamarin.Forms

I started a Xamarin.Forms mobile project recently and decided to use the Prism for Xamarin.Forms framework. I followed the directions for getting started with Prism for Xamarin.Forms and was up and running in no time.

My only issue was that the only IoC container that was supported was Unity. I won’t debate the merits of various IoC containers, but I prefer Ninject, so I submitted a large pull request adding Ninject support to Prism for Xamarin.Forms which is now available on NuGet as Ninject for Prism. (more…)

Read more

Testing Xamarin Projects using NUnit 3

NUnit Tests on AndroidWhen testing Xamarin using NUnit 3, you have two choices.

  1. A Portable Library that you reference from the test runner for each platform, or
  2. A Shared Project with your tests referenced from the platform specific test runners.

I prefer the Shared Project approach because it also allows you to run your tests from within Visual Studio by also creating a .NET 4.5.x test project. As of NUnit 3.0.1, you cannot run tests that use the portable version of the NUnit Framework from the console or within Visual Studio, so the .NET 4.5.x test project gets around that limitation. (more…)

Read more