Menu

Integrate NUnit test with Universal Agent

Overview

In this article, we will walk you through an example to integrate, execute, and schedule test executions for your NUnit test project with the Universal Agent.

Create and Integrate an Agent with an NUnit Framework Video

Note: For highest quality, watch the video in full-screen mode.

Notes

The test project used in this article is stored on github at https://github.com/QASymphony/dotnet-samples containing:

  • Dotnet core test projects that target .NET Core 2.2+: xUnitSample, MSTestSample, NUnitSample
  • Dotnet project that targets .NET 4.5 (Windows only): UnitTestSample

This article will integrate NUnitTestSample project with Universal Agent.

Prerequisites

  1. Activate Automation Integration.
  2. Install and Register the Automation Host.
  3. Your machine needs to have .NET Core 2.2+ installed.
  4. Your machine needs to have git installed.
  5. This article uses a Selenium example that opens a Chrome browser, so make sure you also install Google Chrome on the machine where your Automation Host is running.

Step 1: Create a new Universal Agent for your NUnit test project

Access your Automation Host UI. Select Add to create a new agent. The New Agent dialog displays.

create-agent.png

Next, enter the following to the "New Agent" dialog:

General Information

  • Agent Name: enter the name of the agent, e.g. NUnit Agent
  • qTest Manager Project: select a qTest Manager project from which the agent is going to execute scheduled tests, e.g. qConnect Sample Project
  • Agent Type: select Universal Agent

Pre-Execute Script

Next, we are going to configure a pre-execute script to either clone the sample code from github or pull the latest updates of that repo if it already exists in the host machine.

Enter the script below in the Pre-Execute Script editor, which is specific to the Operating System that the automation host is running:

Windows

if not exist "C:\dotnet-samples" (
 cd /d C:\
 git clone https://github.com/QASymphony/dotnet-samples
) else (
 cd /d "C:\dotnet-samples"
 git pull --all
)

Linux or Mac

#!/bin/bash
if [ ! -d "/usr/local/var/dotnet-samples" ]
then
cd "/usr/local/var"
git clone https://github.com/QASymphony/dotnet-samples
else
cd /usr/local/var/dotnet-samples
git pull --all
fi

Execute Command

Executor: select node as the script executor

Working Directory

  • If your host machine is running on Linux or Mac, enter /usr/local/var/dotnet-samples
  • If your host machine is running on Windows, enter C:\dotnet-samples

Execute Command

We are going to create a script written in NodeJS to:

  • obtain the automation content(s) of scheduled test runs by resolving the value of magic variable TESTCASES_AC. Refer to this article to learn more about MAGIC VARIABLES in Universal Agent.
  • if the value of the TESTCASES_AC variable is empty, meaning there are no test runs being scheduled for execution (e.g. when this Universal Agent is executed in the first time), we will let the agent execute whole tests in our NUnitSample project and then create test run logs within qTest Manager as the execution result.
  • if TESTCASES_AC variable has value, these being the automation contents of scheduled test runs, we will instruct Universal Agent to only execute tests that match those automation contents.

Enter the code snippet below to the Execute Command editor.

Path to Results

Enter the value below to specify the path to the test results generated when the execution completes:

  • If your host machine is running on Linux or Mac: /usr/local/var/dotnet-samples/TestResults
  • If your host machine is running on Windows: C:\dotnet-samples\TestResults

Result Parser

Select NUnit as the Result Parser.

Note: if you do not find the NUnit parser in the Result Parser list, follow the below steps to make it available to the Universal Agent:

  1. Temporarily save the NUnit agent. You'll be returned back to the Automation Host dashboard.
  2. Download NUnit parser HERE.
  3. Access qTest Launch, and follow this article to upload the Parser to qTest Launch.
  4. Go back to Automation Host UI and refresh the page so to load the new parsers.
  5. Select to edit NUnit agent and you'll find the NUnit parser from the Result Parser list.
  6. Select SAVE to finish creating the agent.
    Below is how NUnit Agent looks like, on Mac.

nunit-agent.png

Step 2: Execute the Agent

From the Agents list, locate the NUnit Agent and select Run Now.

run-now.png

The agent execution dialog will display:

nunit-execution-dlg.png

Select Execute to execute the agent. Once the execution completes, the Console Log shows all that test results have been submitted to qTest Manager, as highlighted in the screenshot below.

nunit-execution-dlg-result.png

Next, access qTest Manager. Select qConnect Sample Project and then access the Test Execution module. You'll see the test results submitted to qTest Manager as Test Runs under a Test Suite named "Automation YYYY-MM-DD," where YYYY-MM-DD is the date the agent is executed, as below.

nunit-execution-result.png

Now we are going to schedule test execution for some selected test runs with the NUnit Agent and verify that it only executes tests that match the scheduled test runs as well as submitting the test run results.

Step 3: Schedule Test Execution for Specific Test Runs

From qTest Manager, select the project qConnect Sample Project and select the Test Execution tab. Then, do the following:

  1. Select the newly created test suite. In our example, it is Automation 2019-01-15.
  2. From the test run list on the right, select the first four (4) test runs.
  3. Select MORE, and choose Schedule from the drop-down menu.

nunit-schedule-test.png

In the SCHEDULE AUTOMATION TEST EXECUTION dialog, enter the following:

  1. Name: name of the schedule, e.g. Execute NUnit Test with Universal Agent
  2. Agent: select the NUnit Agent 
  3. Select OK to complete test execution scheduling for the selected three test runs.

nunit-schedule-test-dlg.png

Now go back to the Automation Host UI. Select Poll Now.

poll-now.png

At this stage, the Automation Host does the following:

  • immediately polls to qTest Manager to load schedule jobs and
  • executes the job execution for the test methods in the NUnitTestSample project that match the automation content of the four scheduled test runs

Wait for the execution completes. Then, select the View Log icon to view the execution log.

view-log-icon.png

A log screen will display that shows the latest execution logs. Verify that the log reported only two (2) tests being executed.

view-log.png

Now, access the Test Execution module of the qConnect Sample Project in qTest Manager. Select each test run that was scheduled to be executed and you'll see that the Execution History of each test run was updated with 2 test run logs: one test log created when the agent was first executed and one test log from the scheduled execution.

nunit-scheduled-test-exec-result.png

You have successfully scheduled a test execution for specific tests in your NUnit test project using the Universal Agent and had it reported the test execution to qTest Manager.

 

Powered by Zendesk