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 report files.
Installation
To install the latest version, run:
npm install junit-report-builder --save
Usage
var builder = require('junit-report-builder').createBuilder();
var suite = builder.testSuite().name('My suite');
var testCase = suite.testCase()
.className('my.test.Class')
.name('My first test');
var testCase = 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>
<testsuite name="My suite">
<testcase classname="my.test.Class" name="My first test"/>
<testcase classname="my.test.Class" name="My second test">
<failure/>
</testcase>
</testsuite>
</testsuites>
License
MIT. See LICENSE.
Changelog
0.0.2
- Corrected example in readme
0.0.1