Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPunit result output on the CLI not showing test names

I'm running a brand new test suite in PHPUnit, I'd like to see the result of each test with the test name next to it. It would make fixing broken tests and TDD easier.

PHPunit does output the broken messages afterwards but your eyes go wonky after a while going through all the errors and stacktraces.

The current .......F................... type output is great once your test suite is up and stable, but while you're creating a suite...

I've tried the --verbose param and it doesn't help.

like image 242
Jujhar Singh Avatar asked Aug 07 '14 10:08

Jujhar Singh


People also ask

How do I run a PHPUnit test?

How to Run Tests in PHPUnit. You can run all the tests in a directory using the PHPUnit binary installed in your vendor folder. You can also run a single test by providing the path to the test file. You use the --verbose flag to get more information on the test status.

What is a PHPUnit test?

PHPUnit is a unit testing framework for the PHP programming language. It is an instance of the xUnit design for unit testing systems that began with SUnit and became popular with JUnit. Even a small software development project usually takes hours of hard work.

What is the use of PHPUnit?

PHPUnit is a framework independent library for unit testing PHP. Unit testing is a method by which small units of code are tested against expected results. Traditional testing tests an app as a whole meaning that individual components rarely get tested alone.


2 Answers

Also, if you would like output of what specific test is being run by line, try the --debug flag, this way when errors are being thrown, you will know what test throwing the error by name.

like image 37
Jason Horvath Avatar answered Sep 23 '22 06:09

Jason Horvath


Use phpunit --testdox
On the cli this will give you a very readable testdox format and allow you to see and fix your multiple test suites easily e.g.

PHPUnit 3.7.37 by Sebastian Bergmann.  Configuration read from /home/badass-project/tests/phpunit.xml  AnalyticsViewers  [x] test getViewersForMonth throws for no valid date  [x] test getViewersForMonth limits correctly  [x] test getViewersForMonth only returns unprocessed records  [ ] test getViewersForMonth marks retrieved records as processed  [ ] test getViewersForMonth returns zero for no view data  [x] test getViewersForMonth returns valid data  Organisation  [x] test getOrganisation returns orgs 

I use it in combination with the stack traces from a vanilla PHPUnit run to quickly setup.

It also has the added benefit of replacing underscores in your test function names with spaces. eg test_getViewersForMonth_returns_valid_data becomes test getViewersForMonth returns zero for no view data which is more human readable.
N.B. Generally speaking if you're following the PSR coding standards you should be using camelCase for method names but for unit tests methods I break this rule to reduce cognitive load during TDD development.

like image 105
Jujhar Singh Avatar answered Sep 24 '22 06:09

Jujhar Singh