In this article you will learn how to integrate JUnit for Java with the Universal Agent.
The sample source code of JUnit for Java project is located at a https://github.com/QASymphony/junit-sample
Create JUnit for Java Universal Agent
- From Launch, open the host machine where you want to create the new agent.
- Select the + New Agent button.
- You will be presented with a New Agent dialog.
- Enter the information listed below to create the new agent.
- Agent Name: name of the agent, e.g. JUnit for Java Universal 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: Universal Agent
Enter below script in Pre-Execute Script editor which is specific to the Operating System that the host is running.
#!/bin/bash if [ ! -d "/usr/local/var/junit-sample" ] then cd "/usr/local/var" git clone https://github.com/QASymphony/junit-sample else cd /usr/local/var/junit-sample git pull --all fi
if not exist "D:\junit-sample" ( cd /d D:\ git clone https://github.com/QASymphony/junit-sample ) else ( cd /d "D:\junit-sample" git pull --all )
- If your host machine is running on Linux or Mac, select shell as the executor.
- If your host machine is running on Windows, select batch as the executor.
- If your host machine is running on Linux or Mac: enter /usr/local/var/junit-sample
- If your host machine is running on Windows, enter D:\junit-sample
You will configure the Execute Command to execute our sample JUnit project with maven.
Note: make sure you install maven to your host machine for the command to be executed successfully by Universal Agent.
Enter the command below to the Execute Command editor.
mvn clean compile package test
Path to Results
Optional field. Enter the value below to specify the path to the test result generated by JUnit.
- If your host machine is running on Linux or Mac: /usr/local/var/junit-sample/target/surefire-reports
- If your host machine is running on Windows: D:\junit-sample\target\surefire-reports
Optional field. Select JUnit for Java as the Result Parser.
- If you want the Universal Agent to submit test results to qTest Manager, you must specify values for both Path to Results and Result Parser. Otherwise, you must do that yourself via Execute Command.
The screenshot below shows how the new JUnit for Java Universal Agent is configured, on Mac.
Select SAVE to finish creating the agent. The agent will be available to next time host machine polls to qTest Launch.
Execute JUnit for Java Universal Agent
- Access the host machine where the JUnit for Java Universal Agent was created.
- Locate the agent in the Agents list and select the Run now button.
- The Universal Agent execution dialog will display.
- Select the Execute button to kick off the agent execution and you will see the logs shown in the Console Log section. If the execution is successful, you'll see the test run logs being submitted to qTest Manager.
Now you can access qTest Manager and schedule test execution for the newly created test runs with JUnit for Java Universal Agent.