https://github.com/testmonitor/junit-xml-parser
This package provides a very basic, convenient parser for JUnit XML reports.
https://github.com/testmonitor/junit-xml-parser
Last synced: about 2 months ago
JSON representation
This package provides a very basic, convenient parser for JUnit XML reports.
- Host: GitHub
- URL: https://github.com/testmonitor/junit-xml-parser
- Owner: testmonitor
- License: mit
- Created: 2025-02-17T15:46:01.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-10-24T13:29:57.000Z (6 months ago)
- Last Synced: 2025-10-28T02:32:52.271Z (6 months ago)
- Language: PHP
- Homepage:
- Size: 92.8 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# TestMonitor JUnit Parser
[](https://packagist.org/packages/testmonitor/junit-xml-parser)
[](https://circleci.com/gh/testmonitor/junit-xml-parser)
[](https://styleci.io/repos/934299329)
[](https://codecov.io/gh/testmonitor/junit-xml-parser)
[](https://packagist.org/packages/testmonitor/junit-xml-parser)
This package provides a very basic, convenient parser for JUnit XML reports.
## Table of Contents
- [Installation](#installation)
- [Usage](#usage)
- [Examples](#examples)
- [Tests](#tests)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)
## Installation
To install the client you need to require the package using composer:
$ composer require testmonitor/junit-xml-parser
Use composer's autoload:
```php
require __DIR__.'/../vendor/autoload.php';
```
You're all set up now!
## Usage
Include the parser in your project:
```php
use TestMonitor\JUnitXmlParser\JUnitXmlParser;
$parser = new JUnitXmlParser();
$testSuites = $parser->parse('path/to/junit.xml');
```
## Examples
Below are some examples demonstrating how to use the JUnit XML Parser to extract and process test results.
### Parsing a JUnit XML file
This example shows how to parse a JUnit XML report and retrieve test suite and test case information.
```php
use TestMonitor\JUnitXmlParser\JUnitXmlParser;
$parser = new JUnitXmlParser();
$testSuites = $parser->parse('tests/results.xml');
foreach ($testSuites as $suite) {
echo "Suite: " . $suite->getName() . "\n";
foreach ($suite->getTestCases() as $testCase) {
echo " Test: " . $testCase->getName() . " - Status: " . $testCase->getStatus()->name . "\n";
}
}
```
### Processing Failures and Skipped Tests
This example demonstrates how to identify and handle failed and skipped test cases.
```php
use TestMonitor\JUnitXmlParser\JUnitXmlParser;
$parser = new JUnitXmlParser();
$testSuites = $parser->parse('tests/results.xml');
foreach ($testSuites as $suite) {
foreach ($suite->getTestCases() as $testCase) {
if ($testCase->getStatus() === TestStatus::FAILED) {
echo "Test " . $testCase->getName() . " failed: " . $testCase->getFailureMessage() . "\n";
} elseif ($testCase->getStatus() === TestStatus::SKIPPED) {
echo "Test " . $testCase->getName() . " was skipped.\n";
}
}
}
```
### Extracting Execution Time and Timestamp
JUnit XML reports include execution times and timestamps, which can be accessed as shown below.
```php
use TestMonitor\JUnitXmlParser\JUnitXmlParser;
$parser = new JUnitXmlParser();
$testSuites = $parser->parse('tests/results.xml');
foreach ($testSuites as $suite) {
echo "Suite: " . $suite->getName() . " executed in " . $suite->getDuration() . " seconds on " . $suite->getTimestamp() . "\n";
}
```
## Tests
The package contains integration tests. You can run them using PHPUnit.
$ vendor/bin/phpunit
## Changelog
Refer to [CHANGELOG](CHANGELOG.md) for more information.
## Contributing
Refer to [CONTRIBUTING](CONTRIBUTING.md) for contributing details.
## Credits
* **Thijs Kok** - *Lead developer* - [ThijsKok](https://github.com/thijskok)
* **Stephan Grootveld** - *Developer* - [Stefanius](https://github.com/stefanius)
* **Frank Keulen** - *Developer* - [FrankIsGek](https://github.com/frankisgek)
## License
The MIT License (MIT). Refer to the [License](LICENSE.md) for more information.