backendtea / failuretest
此包已被废弃,不再维护。未建议替代包。
允许 PHPUnit 测试失败,并在问题解决前密切关注。
v1.0.0
2018-01-25 20:09 UTC
Requires
- php: ^5.6 || ^7.0
- phpunit/phpunit: ^5.0 || ^6.0
This package is not auto-updated.
Last update: 2020-01-24 17:32:07 UTC
README
允许 PHPUnit 测试失败,并在问题解决前密切关注。
安装
- 使用 Composer:
composer require backendtea/failuretest
或者简单地将 AllowFailure.php 复制到您的项目中并自行包含。
要求
- PHP 版本 5.6 或更高
- PHPUnit 版本 5.0 或更高。
使用
这些特性使用了 PHPUnit 的 tearDown()
函数。如果您重写了它,不要忘记调用 parent::tearDown();
任何失败的测试将显示为未完成,并附上原始的失败信息。一旦测试实际上通过了所有标准,它将被标记为失败,并显示错误信息,解释您可以将其移动到常规测试。
AllowFailure
<?php use FailureTest\AllowFailure; class AllowFailureTest extends \PHPUnit\Framework\TestCase { use AllowFailure; /** * @allowedFailure */ public function test_it_handles_a_failure() { //This doesn't cause errors $this->assertTrue(false); } /** * @allowedFailure */ public function test_a_success_is_allowed() { //This doesn't cause errors $this->assertTrue(true); } /** * @mustFail */ public function test_it_checks_out() { //This doesn't cause errors $this->assertTrue(false); } /** * @mustFail */ public function test_it_goes_wrong() { //This will give a failed test $this->assertTrue(true); } }
AllowFailure
特性为您提供了两个注解:@allowedFailure
和 @mustFail
。两者都作用于方法或类级别。
@allowedFailure
如果测试失败,则简单地将其标记为未完成,如果测试通过则不执行任何操作。@mustFail
与FailureTestCase
的工作方式相同。除了您可以在函数级别进行配置。
@allowedFailure
覆盖 @mustfail
。因此,如果两者都存在,无论是在类还是方法中,测试如果成功则不会报错。
原因
找到错误时,除了创建一个问题,还可以贡献一个失败的测试用例。这确保了问题不会被忘记,并且还允许其他开发人员更好地确保问题已被修复。
它还可以作为一个很好的“待办事项”列表,如果您愿意,可以将其移动到另一个 VCS。
贡献
如果您发现了一个错误或想要一个功能,请打开一个问题或创建一个 PR。
Failure
子文件夹中的所有测试都应失败,而 Success
文件夹中的测试则不应失败。