To install NUnit3TestAdapter in Visual Studio 2017, follow the steps below: Right click on Project - Click 'Manage Nuget Packages.' From context menu Go to Browse tab and search for NUnit Select NUnit3TestAdapter - Click Install at the right side - Click OK from Preview pop up.

Unit testing tools using your MacOS terminal

I’ve been a MacOS user for many years and I’ve been working /suffering with Visual Studio for Mac and Mono Studio and let me say that their integrated tools to work with unit testing IMHO are not enough so I had to include new tools to make my work easy.

When I run my tests in a terminal window or in Visual Studio for Mac, the information they give me it’s only the final test result, i.e. how many tests are in red or how many tests are in green but I didn’t know which lines of code or which classes were covered by the unit testing.

It’s good but maybe it’s not enough so, how can we get more information about our unit testing? There are some tools that help us to get more information like:

Coverlet

Coverlet is a cross platform code coverage framework for .NET, with support for line, branch and method coverage. It works with .NET Framework on Windows and .NET Core on all supported platforms.

It has different integrations with VsTest, MSBuild and dotnet global tool but let me show you only the MSBuild one. To use it, we have to add the coverlet.msbuild nuget package in our test project and after that we can run the unit test collecting code coverage data (/p:CollectCoverage=true).

As you can see the last lines are regarding with the code coverage calculation. Please take into account the 20%, it’s only a demo.

Coverlet has multiple interesting options but my two favorites are:

Setup the output format because it’s compatible with: React-native build issues android for mac free.

  • json (default one)
  • lcov
  • opencover
  • cobertura

So if we want to create a report with the opencover format in the directory ./coverage/ we should execute:

In my case, I don’t usually want to check the code coverage in my Views (xaml files because I’m a Xamarin Forms developer) so I exclude all files (xaml/ xaml.cs) in the Views namespace.

ReportGenerator

Visual studio unit testing framework

ReportGenerator converts coverage reports generated by Coverlet, OpenCover, dotCover, Visual Studio, NCover, Cobertura, JaCoCo, Clover, gcov or lcov into human readable reports in various formats.

Depends on our platform and needs, we have to install a different package, in this case, I’m going to use the dotnet global tool.

So, if we want to export our previous opencover report in HTMLInline format we should execute:

If you open the generated htm file (src/coverage/report/index.htm’) you can see a summary of the code coverage and you can click on every namespace or class to navigate to the detail.

Nice!