57

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.

3 Answers 3

133

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.

4
  • 11
    Warning: the textdox format doesn't actually include any errors that are thrown! Feb 27, 2017 at 11:12
  • I'm using PHPUnit 7.x, and testShouldRedirectNonLoggedInUser() becomes Should redirect non logged in user.
    – CJ Dennis
    Sep 17, 2018 at 4:36
  • 1
    @starbeamrainbowlabs You probably mean testdox. A typo here is very ambiguous because both words (test and text) are valid.
    – cezar
    Mar 8, 2019 at 8:35
  • @cezar Ah, oops! Didn't notice that typo there :P Mar 8, 2019 at 10:45
17

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.

1
  • the --debug flag has been removed from phpunit 10
    – boksiora
    Jul 28 at 7:27
1

try to use phpunit with the --teamcity Reporting command.

phpunit --help :

--teamcity                       Replace default progress and result output with TeamCity format

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.