我正在 PHPUnit 中运行一个全新的测试套件,我想查看每个测试的结果及其旁边的测试名称。这将使修复损坏的测试和 TDD 变得更容易。
PHPunit 之后确实会输出损坏的消息,但是在查看所有错误和堆栈跟踪一段时间后,您的眼睛会变得不稳定。
一旦您的测试套件启动,当前的 .......F.......
类型输出就很棒稳定,但是当您创建套件时...
我已经尝试了 --verbose
参数,但没有帮助。
最佳答案
使用phpunit --testdox
在 cli 上,这将为您提供一个非常可读的 testdox格式化并允许您轻松查看和修复多个测试套件,例如
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
我将它与普通 PHPUnit 运行的堆栈跟踪结合使用以快速设置。
它还有一个额外的好处,即用空格替换测试函数名称中的下划线。例如 test_getViewersForMonth_returns_valid_data
变为 test getViewersForMonth 对于没有 View 数据返回零
,这更易于理解。
注意 一般来说,如果您遵循 PSR coding standards你应该使用驼峰命名法作为方法名称,但对于单元测试方法,我打破了这条规则来减少 cognitive load TDD 开发期间。
关于CLI 上的 PHPunit 结果输出不显示测试名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25180148/