NUnit 3 test reporting

If you are not using NUnit but are using C# for your tests view the C# documentation.

Installation

The package is hosted in NuGet Gallery. Run this command in Package Manager Console.

Install-Package Tesults.NUnit

Alternatively install Tesults.NUnit using the GUI in Visual Studio.

Configuration

.NET (.NET Core) Instructions

Additional configuration is required for NUnit to recognize the Tesults NUnit extension. A file with the extension .addins must be created, the name doesn't matter, we call it tesults.addins here. This file contains just one line: 'Tesults.NUnit.dll'. This references the Tesults NUnit extension made available following the NuGet package installation.

tesults.addins
Tesults.NUnit.dll

Next create a file with .runsettings extension. Again the name does not matter and we call it test.runsettings here. Include your Tesults target token in this file:

test.runsettings
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<TestRunParameters>
  <Parameter name="tesults-target" value="token" />
</TestRunParameters>
</RunSettings>

Ensure tesults.addins, test.runsettings, Tesults.NUnit.dll (the package installed from NuGet) and the .dll containing your tests are all in the same directory (generally your build output directory). We suggest you add tesults.addins and test.runsettings to your Visual Studio project and set these files to be copied to your build output directory automatically. Now you can run your tests and NUnit will recognize the Tesults listener and upload test results data to Tesults:

dotnet test <Tests-containing>.dll -s test.runsettings

Basic configuration complete

At this point the Tesults.NUnit extension will push results to Tesults. The Tesults.NUnit extension requires the tesults-target arg be supplied in the test.runsettings file to indicate which target to use otherwise the extension is effectively disabled and you will see this message in the console output 'Tesults disabled. No tesults-target param supplied.'

Example:

dotnet test <Tests-containing>.dll -s test.runsettings

The 'token' in test.runsettings should be replaced with your Tesults target token. Tesults target tokens can be copied on project creation, new target creation or can be regenerated from the configuration menu.

You can use multiple test.runsettings files to report results to different Tesults targets if required.


.NET Framework Instructions

Install the NUnit.ConsoleRunner NuGet package (along with NUnit and Tesults.NUnit packages).

Install-Package NUnit.ConsoleRunner

Additional configuration is required for NUnit to recognize the Tesults NUnit extension. A file with the extension .addins must be created, the name doesn't matter, you can call it tesults.addins. This file must be added to the NUnit.ConsoleRunner package. Open your test project in Explorer and navigate to packages > NUnit.ConsoleRunner > tools. This directory contains the nunit3-console.dll and others. This is where the tesults.addins file must be added. The contents of the file must provide the path to Tesults.NUnit.dll, where the path is relative to the addins file, in most cases the contents would be:

tesults.addins

../../Tesults.NUnit.1.1.0/lib/net472/Tesults.NUnit.dll

If you are experiencing difficulties with this step, please contact us and we will help guide you. Unfortunately this is a necessary step for registering extensions with NUnit. Please also note that this extension is intended for use with the NUnit.ConsoleRunner, and not the Visual Studio NUnit3TestAdapter, because the test adapter does not recognize extensions. You will need to run your tests with the NUNIT3-CONSOLE command if you want result to upload to Tesults, whether locally or within your build and continuous integration system.

tesults-targetRequired

A target token must be provided to upload to Tesults, if this arg is not provided Tesults.NUnit does not attempt upload, effectively disabling it. Get your target token from the configuration menu in the Tesults web interface.

Inline method

NUNIT3-CONSOLE ./bin/Release/tests.dll --tp tesults-target=eyJ0eXAiOiJ

In this case, the target token is supplied directly or inline in the commandline args. This is the simplest approach.

Key method

NUNIT3-CONSOLE ./bin/Release/tests.dll --tp tesults-target=target1

In this case, Tesults.NUnit will automatically look up the value of the token based on a key value from a configuration file. The config file should be a typical .config file for C# and the path must be passed in using the tesults-config arg. See below for details.


tesults-configOptional (.NET Framework)

Example

NUNIT3-CONSOLE [inputfiles] [options] --tp tesults-config=C:\path-to-config

Example config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
  <add key="target1" value="eyJ0eXAiOiJKV1..."/>
  <add key="target2" value="eyJ0eXAiOiJKV2..."/>
  <add key="tesults-files" value="C:\path-to\files"/>
  <add key="tesults-build-name" value="1.0.0"/>
  <add key="tesults-build-desc" value="build description here"/>
  <add key="tesults-build-result" value="pass"/>
  <add key="tesults-build-reason" value="reason here"/>
</appSettings>
</configuration>

Or something more descriptive about the targets:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
  <add key="web-qa-env" value="eyJ0eXAiOiJKV1..."/>
  <add key="web-staging-env" value="eyJ0eXAiOiJKV12..."/>
  <add key="web-prod-env" value="eyJ0eXAiOiJKV13..."/>
  <add key="ios-qa-env" value="eyJ0eXAiOiJKV14..."/>
  <add key="ios-staging-env" value="eyJ0eXAiOiJKV15..."/>
  <add key="ios-prod-env" value="eyJ0eXAiOiJKV16..."/>
  <add key="android-qa-env" value="eyJ0eXAiOiJKV17..."/>
  <add key="android-staging-env" value="eyJ0eXAiOiJKV18..."/>
  <add key="android-prod-env" value="eyJ0eXAiOiJKV19..."/>
</appSettings>
</configuration>

The config file can contain values not just for target look up but for all of the args below too. If the same arg is provided in both the command and in a config file the command arg takes priority.

Basic configuration complete

At this point the Tesults.NUnit extension will push results to Tesults when you run the NUNIT3-CONSOLE command. The Tesults.NUnit extension requires the tesults-target arg be supplied to indicate which target to use otherwise the extension is effectively disabled and you will see this message in the console output 'Tesults disabled. No tesults-target param supplied.' See above for complete details.

Example:

NUNIT3-CONSOLE ./bin/Release/tests.dll --tp tesults-target=token --tp tesults-config=C:\path-to-config

The 'token' should be replaced with your Tesults target token. Tesults target tokens can be copied on project creation, new target creation or can be regenerated from the configuration menu.

Files generated by tests

tesults-filesOptional

Provide the top-level directory where files generated during testing are saved for the running test run. Files, including logs, screen captures and other artifacts will be automatically uploaded.

.NET (.NET Core) Instructions

dotnet test <Tests-containing>.dll -s test.runsettings

Where the test.runsettings file includes the tesults-files parameter:

test.runsettings
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<TestRunParameters>
  <Parameter name="tesults-target" value="token" />
  <Parameter name="tesults-files" value="C:\path-to-files\temporary" />
</TestRunParameters>
</RunSettings>

Ensure tesults.addins is also present in the same directory as the test containing dll so that NUnit recognizes the Tesults listener. As before this file contains just one line:

tesults.addins
Tesults.NUnit.dll


.NET Framework Instructions

NUNIT3-CONSOLE [inputfiles] [options] --tp tesults-files=C:\path-to-files\temporary

This is one area where Tesults.NUnit is opinionated and requires that files generated during a test run be saved locally temporarily within a specific directory structure.

Store all files in a temporary directory as your tests run. After Tesults upload is complete, delete the temporary directory or just have it overwritten on the next test run.

Within this temporary directory create subdirectories matching the test case name.

The suite name matches the [TestFixture] and test case name matches the [Test] method name.

Caution: If uploading files the time taken to upload is entirely dependent on your network speed. Typical office upload speeds of 100 - 1000 Mbps should allow upload of even hundreds of files quite quickly, just a few seconds, but if you have slower access it may take hours. We recommend uploading a reasonable number of files for each test case. The upload method blocks at the end of a test run while uploading test results and files. When starting out test without files first to ensure everything is setup correctly.

During a test run, save test generated files such as logs and screenshots to a local temporary directory. At the end of the test run all files will automatically be saved to Tesults as long as you save files in the directory structure below. Omit test suite folders if not using test suites.
  • expanded temporary folder
    • expanded Test Suite A
      • expanded Test 1
        • test.log
        • screenshot.png
      • expanded Test 2
        • test.log
        • screenshot.png
    • expanded Test Suite B
      • expanded Test 3
        • metrics.csv
        • error.log
      • expanded Test 4
        • test.log

Build

tesults-build-nameOptional

Use this to report a build version or name for reporting purposes.


tesults-build-resultOptional

Use this to report the build result, must be one of [pass, fail, unknown].


tesults-build-descOptional

Use this to report a build description for reporting purposes.


tesults-build-reasonOptional

Use this to report a build failure reason.


.NET (.NET Core) Instructions

dotnet test <Tests-containing>.dll -s test.runsettings

Where the test.runsettings file includes the build parameters:

test.runsettings
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<TestRunParameters>
  <Parameter name="tesults-target" value="token" />
  <Parameter name="tesults-build-name" value="1.0.0" />
  <Parameter name="tesults-build-desc" value="Build description" />
  <Parameter name="tesults-build-result" value="pass" />
  <Parameter name="tesults-build-reason" value="reason here if build has failed" />
</TestRunParameters>
</RunSettings>

Ensure tesults.addins is also present in the same directory as the test containing dll so that NUnit recognizes the Tesults listener. As before this file contains just one line:

tesults.addins
Tesults.NUnit.dll

.NET Framework Instructions

NUNIT3-CONSOLE [inputfiles] [options]--tp tesults-build-name=1.0.0 tesults-build-result=pass

Result Interpretation

Result interpretation is not currently supported by this integration. If you are interested in support please contact help@tesults.com.

Consolidating parallel test runs

If you execute multiple test runs in parallel or serially for the same build or release and results are submitted to Tesults within each run, separately, you will find that multiple test runs are generated on Tesults. This is because the default behavior on Tesults is to treat each results submission as a separate test run. This behavior can be changed from the configuration menu. Click 'Results Consolidation By Build' from the Configure Project menu to enable and disable consolidation by target. Enabling consolidation will mean that multiple test runs submitted with the same build name will be consolidated into a single test run.

Dynamically created test cases

If you dynamically create test cases, such as test cases with variable values, we recommend that the test suite and test case names themselves be static. Provide the variable data information in the test case description or other custom fields but try to keep the test suite and test name static. If you change your test suite or test name on every test run you will not benefit from a range of features Tesults has to offer including test case failure assignment and historical results analysis. You need not make your tests any less dynamic, variable values can still be reported within test case details.

Proxy servers

Does your corporate/office network run behind a proxy server? Contact us and we will supply you with a custom API Library for this case. Without this results will fail to upload to Tesults.

Have questions or need help? Contact us