What is best practice for printing log statements from a PHPUnit test case?
I am running selenium test cases and want to print out something like “Log in acccomplished”, “Page XY opened”.
I want to see those in any log file I want. Would be good, if you can define a log level.
I would suggest that You use the Selenium Server Logging. It will provide You with all debugging information You might need.
If it’s not an option for You and You still want to log from the
PHPUnittest cases, You have 3 options:phpunit.xmlfile or the command line arguments (documentation);PHPUnit_Framework_TestListenerinterface, which is kind of limited because it supports only a limited amount of events You can log, such asstartTest,endTest,addError,addFailure, etc. See the (documentation) for the complete list of the supported events. You could possibly add some more events to your implementation but that would also require that You override thePHPUnit_Framework_TestSuite::run()method by subclassing thePHPUnit_Extensions_TestDecoratorclass (documentation) or by implementing thePHPUnit_Framework_Testinterface (documentation).PHPUnit_Framework_TestCaseclass and implement the logging functionality there. This will allow You to log from within Your test methods.(documentation)