Get "PHP 8 in a Nuthshell" (Now comes with PHP 8.3)
Amit Merchant

Amit Merchant

A blog on PHP, JavaScript, and more

Make PHPUnit test reports more detailed using TestDox

If you’ve ever worked with PHPUnit for TDD, you might be aware of the fact that PHPUnit’s default test reports are pretty minimal and ambiguous.

For instance, a normal test run would look something like this.

PHPUnit Default

As you can tell, this test report doesn’t show a lot of details. i.e. you can not guess what all tests passed and which ones failed just by looking at the end result.

On the contrary, if you’re using Laravel 7.x, you can use the artisan test command to get results more verbose and detailed like so.

php artisan test

But what if you want similar kind of test results from PHPUnit itself? Well, Meet TestDox.

Make test results verbose using TestDox

TestDox is essentially a functionality that comes bundled with PHPUnit which looks at a test class and all the test method names and converts them from camel case (or snake_case) PHP names to sentences.

Essentially, this makes the test results almost similar like we get using the php artisan test.

To use TestDox, all you’ll need to do is use the --testdox option with PHPUnit like so.

$ vendor/bin/phpunit --testdox

Running this would give a test report like so.

PHPUnit with TestDox

Looks more detailed as opposed to using PHPUnit in its default state, right?

Here’s how a failing test would look like when using TestDox.

What TestDox does under the hood is converts test method names to sentences. So, for instance, if there is a method called testBalanceIsInitiallyZero() (or test_balance_is_initially_zero()), it will convert it to “Balance is initially zero”.

Like this article? Consider leaving a

Tip

👋 Hi there! I'm Amit. I write articles about all things web development. You can become a sponsor on my blog to help me continue my writing journey and get your brand in front of thousands of eyes.

Comments?