tags:

views:

20

answers:

1

So I've got a lot of PHPUnit tests (they are actually Selenium tests running as PHPUnit tests). When I run them from the command line, I get this sort of reporting as the tests complete:

..E..F..E.FF...

Then I have to wait until all the tests finish running before it will tell me the errors and what failed. I would like to be able to control this so I can do some more useful reporting. For example:

testLogin ....... passed
testFoobar ...... failed
    - Failed asserting that foo = true on line 123
testBazbat ...... passed

How can I get control over how PHPUnit displays the results?

+1  A: 

PHPUnit has a few command line parameters to control the output format. The most useful ones for your are --testdox and --tap

They work like this:

]> phpunit --tap FooTest.php 
TAP version 13
not ok 1 - Failure: FooTest::test_add
  ---
  message: fark
  severity: fail
  ...
ok 2 - FooTest::test_exists
ok 3 - FooTest::test_show_html
ok 4 - FooTest::test_show_array
ok 5 - FooTest::test_show_empty
ok 6 - FooTest::test_find
1..6


]> phpunit --testdox FooTest.php 
PHPUnit 3.5.0 by Sebastian Bergmann.

Foo
 [ ] test add
 [x] test exists
 [x] test show html
 [x] test show array
 [x] test show empty
 [x] test find

As you can see --testdox does not show the failure reason, its ment to be used like a kind of specification generator. But --tap comes pretty close.

And you can always write your own test listener - a custom class that implements PHPUnit_Framework_Testlistener interface (has methods like startTest, endTest, addFailure, addError etc; the names are pretty self-explanatory, respective code will be called for events that happen when your testsuite runs).

Such code is hooked up into phpunit using the xml configuration file.

One good example of such custom listener can be viewed here: http://raphaelstolt.blogspot.com/2010/06/growling-phpunits-test-status.html

Anti Veeranna
Thanks. That's really helpful. Could you elaborate a bit more on what you mean by "test listener" and "loader"? That might be where I want to go with it, but I wouldn't know where to start.
Andrew
I edited the answer with more details about test listeners. Custom test loader is actually not relevant at all for your issue, so I removed that part.
Anti Veeranna
Thanks for the update, that blog post will really help!
Andrew