This package provides a very basic, convenient parser for JUnit XML reports.
To install the client you need to require the package using composer:
$ composer require testmonitor/junit-xml-parser
Use composer's autoload:
require __DIR__.'/../vendor/autoload.php';
You're all set up now!
Include the parser in your project:
use TestMonitor\JUnitXmlParser\JUnitXmlParser;
$parser = new JUnitXmlParser();
$testSuites = $parser->parse('path/to/junit.xml');
Below are some examples demonstrating how to use the JUnit XML Parser to extract and process test results.
This example shows how to parse a JUnit XML report and retrieve test suite and test case information.
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";
}
}
This example demonstrates how to identify and handle failed and skipped test cases.
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";
}
}
}
JUnit XML reports include execution times and timestamps, which can be accessed as shown below.
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";
}
The package contains integration tests. You can run them using PHPUnit.
$ vendor/bin/phpunit
Refer to CHANGELOG for more information.
Refer to CONTRIBUTING for contributing details.
- Thijs Kok - Lead developer - ThijsKok
- Stephan Grootveld - Developer - Stefanius
- Frank Keulen - Developer - FrankIsGek
The MIT License (MIT). Refer to the License for more information.