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.
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.
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.
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
test_balance_is_initially_zero()), it will convert it to “Balance is initially zero”.
👋 Hi there! I'm Amit. I write articles about all things web development. If you like what I write and want me to continue doing the same, I would like you buy me some coffees. I'd highly appreciate that. Cheers!