JUnit
JUnit is a testing frameworks for the JVM and is used by many popular builds tools such as Gradle, Maven, Ant or Spring Boot. Most of these tools generate JUnit XML report files when running your tests by default. Submit and collect all your tests results from JUnit-style XML reports in Testiny to track results over time, identify frequently failing tests and fix CI failures or flaky tests.
Many testing frameworks follow a standardized JUnit-style XML format to record test results. You can import JUnit-style XML reports from any testing framework into Testiny, not just from JUnit.
JUnit Reports
To submit JUnit-style XML reports to Testiny, use the Testiny CLI with the --junit
option and make sure you're specify a Testiny API key. The CLI will collect the results of all specified JUnit XML reports and create an automated test run in Testiny.
- Node.js/npm
- Linux
- Windows
- macOS
export TESTINY_API_KEY=****
npx @testiny/cli automation --project ID_OR_KEY --source "frontend-tests" --junit results/*.xml
export TESTINY_API_KEY=****
./testiny-importer-linux automation --project ID_OR_KEY --source "frontend-tests" --junit results/*.xml
set TESTINY_API_KEY=****
testiny-importer-win.exe automation --project ID_OR_KEY --source "frontend-tests" --junit results/*.xml
export TESTINY_API_KEY=****
./testiny-importer-macos automation --project ID_OR_KEY --source "frontend-tests" --junit results/*.xml
CLI Options for JUnit-style Reports
Test Case and Folder Title
Ignore classname for test case title
By default, the classname attribute is included in the title of the automatically generated test cases in Testiny. To remove or ignore the classname, specify the option:
--junit-ignore-classname
For example, if you have a test with classname="com.example.tests.LoginTest" and name="testValidLogin", the resulting test case title would be "com.example.tests.LoginTest.testValidLogin". With the --junit-ignore-classname
option, the resulting test case title is "testValidLogin".
Use classname as folder title
If you want to use the classname as the folder structure instead of putting it in the test case title, use the CLI option:
--junit-classname-as-folder single // treats the whole classname as a single folder name
--junit-classname-as-folder nested // splits the classname on "." and nests the folder accordingly
Remove prefix from classname
If your classnames all start with a common root (e.g., com.example.), and you don’t want that repeated in folder or title structure, you can strip this prefix with the CLI option:
--junit-strip-classname-prefix "com.example."
Time Duration
The duration of the run or test case is determined by the time
attribute. Due to a lack of standardization, time is sometimes supplied as either seconds or milliseconds. By convention, if the time includes a "." decimal separator it is assumed that the duration is in seconds and milliseconds otherwise.
The time unit for the duration can be set explicitly using the CLI:
--junit-duration-unit sec
--junit-duration-unit ms
More resources
Here are some further resources to help you get started with integrating jUnit with Testiny, including CI/CD integration examples, a full automation guide, and the Testiny CLI.