What is junit-report-builder?
The junit-report-builder npm package is a tool for creating JUnit XML reports. These reports are commonly used in continuous integration (CI) systems to display test results. The package allows you to programmatically build and structure these reports, making it easier to integrate with various CI tools.
What are junit-report-builder's main functionalities?
Creating a Test Suite
This feature allows you to create a new test suite. A test suite is a collection of test cases that can be reported together.
const builder = require('junit-report-builder');
const suite = builder.testSuite().name('My Test Suite');
Adding Test Cases
This feature allows you to add test cases to a test suite. You can specify the class name, test name, execution time, and the result of the test (e.g., failure message).
const builder = require('junit-report-builder');
const suite = builder.testSuite().name('My Test Suite');
suite.testCase().className('MyClass').name('should do something').time(123).failure('Failure message');
Writing the Report to a File
This feature allows you to write the constructed JUnit report to an XML file. This file can then be used by CI tools to display test results.
const builder = require('junit-report-builder');
const suite = builder.testSuite().name('My Test Suite');
suite.testCase().className('MyClass').name('should do something').time(123).failure('Failure message');
builder.writeTo('test-report.xml');
Other packages similar to junit-report-builder
mocha-junit-reporter
The mocha-junit-reporter package is a reporter for the Mocha testing framework that generates JUnit XML reports. It is specifically designed to work with Mocha, making it a good choice if you are already using Mocha for your tests. Unlike junit-report-builder, which is a general-purpose JUnit report builder, mocha-junit-reporter is tightly integrated with Mocha.
jest-junit
The jest-junit package is a Jest reporter that generates JUnit XML reports. It is designed to work seamlessly with the Jest testing framework. If you are using Jest for your tests, jest-junit provides a straightforward way to generate JUnit reports without needing to manually build them, as you would with junit-report-builder.
junit-xml
The junit-xml package is a Python library for creating JUnit XML reports. While it is not a direct npm package, it serves a similar purpose in the Python ecosystem. It allows you to programmatically create JUnit reports, similar to junit-report-builder, but is used in Python projects.
junit-report-builder
A project aimed at making it easier to build Jenkins compatible XML based JUnit reports.
Installation
To install the latest version, run:
npm install junit-report-builder --save
Usage
import builder from 'junit-report-builder';
let suite = builder.testSuite().name('My suite');
let firstTestCase = suite.testCase()
.className('my.test.Class')
.name('My first test');
let secondTestCase = suite.testCase()
.className('my.test.Class')
.name('My second test')
.failure();
builder.writeTo('test-report.xml');
This will create test-report.xml
containing the following:
<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="2" failures="1" errors="0" skipped="0">
<testsuite name="My suite" tests="2" failures="1" errors="0" skipped="0">
<testcase classname="my.test.Class" name="My first test"/>
<testcase classname="my.test.Class" name="My second test">
<failure/>
</testcase>
</testsuite>
</testsuites>
If you want to create another report file, start by getting a new
builder instance like this:
let anotherBuilder = builder.newBuilder();
CommonJS is also supported:
let builder = require('junit-report-builder');
Please refer to the e2e.spec.ts for more details on the usage.
License
MIT
Changelog
4.0.1
4.0.0
- Accidentally dropped CommonJS support. This is fixed again in 4.0.1.
- Dropped support for node.js 14, 12, 10 and 8.
- Full typing support for TypeScript. Thanks to Harel M.
3.2.1
3.2.0
- Support name and test count attributes for the root test suites element. Thanks to Simeon Cheeseman.
- Describe parameter types and return types with JSDoc. Thanks to Simeon Cheeseman.
3.1.0
- Add support for generic properties for test cases. Thanks to Pietro Ferrulli.
- Bump dependencies
3.0.1
- Bump dependencies: lodash, make-dir, date-format, minimist
3.0.0
- Properly prevent invalid characters from being included in the XML files.
- Dropped support for node.js 4 and 6
2.1.0
- Added support for adding a
file
attribute to a test case. Thanks to Ben Holland.
2.0.0
- Replace mkdirp by make-dir to resolve npm advisory 1179.
- Dropped support for node.js 0.10.x and 0.12.x
1.3.3
- Updated lodash to a version without known vulnerabilities.
1.3.2
- Added support for emitting the type attribute for error and failure elements of test cases
- Added support for emitting cdata/content for the error element of a test case
Thanks to Robert Turner.
1.3.1
- Update dependencies to versions without known vulnerabilities.
1.3.0
1.2.0
- Support creating XML with emojis. Thanks to ischwarz.
1.1.1
- Changed
date-format
to be a dependency. Previously it was incorrectly set to be a devDependency. Thanks to georgecrawford.
1.1.0
- Added attributes for test count, failure count, error count and skipped test count to testsuite elements
- Added ability to attach standard output and standard error logs to test cases
- Added ability set execution time for test suites
- Added ability set timestamp for test suites
1.0.0
- Simplified API by making the index module export a builder instance
0.0.2
- Corrected example in readme
0.0.1