承接 testmonitor/junit-xml-parser 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

testmonitor/junit-xml-parser

最新稳定版本:v1.1.0

Composer 安装命令:

composer require testmonitor/junit-xml-parser

包简介

This package provides a very basic, convenient parser for JUnit XML reports.

README 文档

README

Latest Stable Version CircleCI StyleCI codecov License

This package provides a very basic, convenient parser for JUnit XML reports.

Table of Contents

Installation

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!

Usage

Include the parser in your project:

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.

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.

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";
        }
    }
}

Handling Properties

This example demonstrates how to retrieve the property keys and values:

use TestMonitor\JUnitXmlParser\JUnitXmlParser;

$parser = new JUnitXmlParser();
$result = $parser->parse('tests/results.xml');

foreach ($result->getTestSuites() as $suite) {
    echo "Suite: {$suite->getName()}\n";

    foreach ($suite->getProperties() as $key => $value) {
        echo "$key: $value\n";
    }
}

Processing System Out and System Err

This example demonstrates how to retrieve the information for the system-out and system-err tags:

use TestMonitor\JUnitXmlParser\JUnitXmlParser;
use TestMonitor\JUnitXmlParser\Enums\TestStatus;

$parser = new JUnitXmlParser();
$result = $parser->parse('tests/results.xml');

foreach ($result->getTestSuites() as $suite) {
    foreach ($suite->getTestCases() as $testCase) {
        if ($testCase->getStatus() === TestStatus::PASSED) {
            echo "Test '{$testCase->getName()}' passed:\n";
            echo $testCase->getSystemOut() . "\n\n";
        } else {
            echo "Test '{$testCase->getName()}' didn't pass:\n";
            echo $testCase->getSystemErr() . "\n\n";
        }
    }
}

Extracting Execution Time and Timestamp

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";
}

Tests

The package contains integration tests. You can run them using PHPUnit.

$ vendor/bin/phpunit

Changelog

Refer to CHANGELOG for more information.

Contributing

Refer to CONTRIBUTING for contributing details.

Credits

License

The MIT License (MIT). Refer to the License for more information.

统计信息

  • 总下载量: 226
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-17