shawnveltman/testmetrics

A few helpers to profile your test suite

dev-main 2023-07-27 21:37 UTC

This package is auto-updated.

Last update: 2024-10-28 00:13:26 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

An easy way to find slow tests within your application. Since Laravel Parallel Testing allows for JUnit logging, this is simply a JUnit xml parser that grabs simple stats (setup time, average test time after setup) for each test suite, to hilight those that are the slowest.

Installation

You can install the package via composer:

composer require shawnveltman/testmetrics

After installation, be sure to add the following lines to your phpunit.xml file:

<logging>
    <junit outputFile="junit.xml"/>
</logging>

Finally, be sure to add the junit.xml to your gitignore.

Usage

Now, after you run your parallel tests, you will have the junit.xml file. Grab the contents of that file as a string, and pass it to the test_results_parser method, then print your results. That's it!

$testmetrics = new Shawnveltman\Testmetrics();
echo $testmetrics->test_results_parser(contents: $file_contents)->print_results();

Alternately, you can pass a filepath instead of string contents.

$testmetrics = new \Shawnveltman\Testmetrics\Testmetrics();
$path = base_path('junit.xml');
echo $testmetrics->test_results_parser(path: $path)->print_results();

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.