Test report files to JUnit XML converter
npm install junit-convertertest-case <reason> elements to JUnit <skipped> with message.
test-case <failure> elements to JUnit <failure> with message and stack trace.
test <reason> elements to JUnit <skipped> with message.
test <failure> elements to JUnit <failure> with message and stack trace.
dotnet test generates TRX style files unless different logger is used.
- Converts Output/ErrorInfo/ErrorInfo to JUnit <failure> with message.
- Converts Output/ErrorInfo/Message to JUnit <failure> message.
- Converts Output/ErrorInfo/StackTrace to JUnit <failure> stack trace.
- Converts Output/StdErr to JUnit <system-err>.
- Converts Output/StdOut to JUnit <system-out>.
- Converts Inconclusive and NotExecuted tests to <skipped> with message.
- Tests are split into multiple <testsuite> elements by test classname.
- Tests are ordered by name.
- Test suit times are not 100% accurate - displayed as a sum() of all test times.
$3
`bash
npm i --save-dev junit-converter
`
`js
const converter = require('junit-converter');
let options = {
testFile: 'mytesfiles/nunit.xml',
testType: 'nunit'
}
// Convert test report to JUnit format and save to file
// Set minify:true to save minified XML
converter.toFile(options).then(() => console.log(JUnit report created));
// Convert test report to JUnit format and return as 'pretty' XML string
// Set minify:true to returm minified XML string
converter.toString(options).then((result) =>{/do something with result/});
// Convert test report to JUnit format and return as JSON object for processing
converter.toJson(options).then((result) =>{/do something with result/});
`
$3
`bash
npm i -g junit-converter
`
#### Convert test report to JUnit format and save to file
`bash
junit-converter --testFile mytests/nunit.xml --testType nunit
`
$3
| Option | Type | Default | Description |
|:--------------------------|:--------|:--------------------------|:--------------------------------------------------|
| testFile (required) | string | | Path to test file for conversion |
| testType (required) | string | | Test report type |
| reportDir | string | ./report | Converted report output path when saving file |
| reportFile | string | testFile.name-junit.xml | JUnit report file name |
| splitByClassname | boolean | false | Split into multiple test suites by test classname |
| minify | boolean | false | Minify XML result |
- testFile - relative or absolute path to input test file.
- testType - type of test report, not case-sensitive.
- reportDir - will be created if path does not exist. Only used when saving to file.
- reportFile - JUnit file name. Only used when saving to file.
- splitByClassname - If true, splits test cases into multiple test suites by classname.
This is useful for test runners that generate tests under a single test suite such as dotnet test when using JUnit loggers.
Should only be set to true if test report file contains single test suite.
TRX report files are always split by classname, so this option is ignored for TRX files.
#### Supported testType options.
| testType` | File Type |