In this article we will walk you through an example to integrate, execute and schedule test execution for your MSTest test project with Universal Agent.
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 MSTestSample project with Universal Agent.
- Activate Automation Integration
- Install and Register the Automation Host
- You machine needs to have .NET Core 2.2+ installed
- This article uses Selenium that opens Chrome browser, so make sure you also install Google Chrome to the machine where Automation Host is running
Step 1: Create a new Universal Agent for your MSTest test project
Access to your Automation Host UI. Click on Add button to create a new agent. The New Agent dialog will be shown.
Next, enter the following to the New Agent dialog:
- Agent Name: enter name of the agent, e.g. MSTest 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
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 to the host machine.
Enter the script below to the Pre-Execute Script editor, which is specific to the Operating System that the automation host is running:
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
if [ ! -d "/usr/local/var/dotnet-samples" ]
git clone https://github.com/QASymphony/dotnet-samples
git pull --all
Executor: select node as the script executor
- 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
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 TESTCASES_AC variable is empty, which means there is no test runs being scheduled to be executed (e.g. when this Universal Agent is executed in the first time), we will let the agent execute the whole tests in our MSTestSample project then create test run logs to qTest Manager as the execution result
- if TESTCASES_AC variable has value, which are 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
Select NUnit as the Result Parser. Note: if you do not find the NUnit parser in the Result Parser list, follow below steps to make it available to Universal Agent:
- Temporarily save the MSTest Agent. You'll be return back to Automation Host dashboard
- Download NUnit parser HERE
- Access qTest Launch and follow this article to upload the Parser to qTest Launch
- Go back to Automation Host UI, refresh the page for it to load the new parsers
- Select to edit MSTest Agent and you'll find the NUnit parser from the Result Parser list
Select SAVE to finish creating the agent. Below is how MSTest Agent looks like, on Mac.
Step 2: Execute the Agent
From Agents list, locate the MSTest Agent and click on Run Now button.
The agent execution dialog will display.
Click on the Execute button to execute the agent. Once the execution completes, the Console Log shows all the test results have been submitted to qTest Manager, as highlighted in the screenshot below.
Next, access to qTest Manager. Select qConnect Sample Project then go to Test Execution module. You'll see the test results submitted to qTest Manager as Test Runs under a Test Suite naming Automation YYYY-MM-DD, where YYYY-MM-DD is the date the agent is executed, as below.
Now we are going to schedule test execution for some selected test runs with the MSTest Agent and verify it only executes tests that match the scheduled test runs as well submits results to those test runs.
Step 3: Schedule Test Execution for specific Test Runs
From qTest Manager, select the project qConnect Sample Project, then click on Test Execution tab and do the followings:
- Select the newly created test suite, in our example, it is Automation 2019-01-15.
- From the test run list on the right, select the first four (4) test runs
- Click on MORE button, then select Schedule
On the opening SCHEDULE AUTOMATION TEST EXECUTION dialog, enter the followings:
- Name: name of the schedule, e.g. Execute MSTest Test with Universal Agent
- Agent: select the MSTest Agent
- Click OK button to complete test execution scheduling for the selected three test runs
Now go back to Automation Host UI. Click Poll Now button.
At this stage, the Automation Host does the followings:
- immediately polls to qTest Manager to load schedule jobs and
- execute the job execution for the tests methods in MSTestSample project that match the automation content of the four scheduled test runs
Wait a while for the execution completes, then click on View Log icon to view execution log.
A log screen will display that shows the latest execution logs. Verify that the log reported only two (2) tests being executed.
Now get back to Test Execution module of qConnect Sample Project project in qTest Manager. Click on each test run that was scheduled to be executed, you'll see 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.
You have successfully scheduled test execution for specific tests in your MSTest test project using Universal Agent, and have it report the test execution to qTest Manager.