Codeception:canSeeRecord() 和 seeRecord() 有什么区别
Codeception: What is the difference between canSeeRecord() and seeRecord()
我在 Yii2 应用程序中使用 Codeception 进行单元测试。 Yii2 模块有一个文档化的 seeRecord() 方法。还有类似的 canSeeRecord()
没有任何在线文档,但在 PHPDoc 中有附加信息:
Conditional Assertion: Test won't be stopped on fail
但这到底是什么意思呢?在测试失败时,PhpStorm 只显示第一个错误,所以我看不出有什么区别。这两个调用之间有什么实际区别吗:
$this->tester->seeRecord(MyModel::class, ['name' => 'rob006']);
$this->tester->canSeeRecord(MyModel::class, ['name' => 'rob006']);
记录于 https://codeception.com/docs/03-AcceptanceTests#Conditional-Assertions
Usually, as soon as any assertion fails, further assertions of this
test will be skipped. Sometimes you don’t want this - maybe you have a
long-running test and you want it to run to the end. In this case, you
can use conditional assertions. Each see
method has a corresponding
canSee
method, and dontSee
has a cantSee
method:
$I->canSeeInCurrentUrl('/user/miles');
$I->canSeeCheckboxIsChecked('#agree');
$I->cantSeeInField('user[name]', 'Miles');
Each failed assertion will be shown in the test results, but it won’t stop the test.
证明 PHPDoc 是正确的 - 断言失败后测试将继续。但就我而言,我对 PhpStorm 集成感到困惑,它只报告第一个错误。
我创建了简单测试:
public function testTest() {
// products table is empty - these tests always fail
$this->tester->canSeeRecord(Product::class, ['id' => 1]);
$this->tester->canSeeRecord(Product::class, ['id' => 2]);
$this->tester->canSeeRecord(Product::class, ['id' => 3]);
}
PhpStorm 在此测试中仅显示第一个错误:
但是当您 运行 从控制台进行此测试时,会报告所有三个错误:
我在 Yii2 应用程序中使用 Codeception 进行单元测试。 Yii2 模块有一个文档化的 seeRecord() 方法。还有类似的 canSeeRecord()
没有任何在线文档,但在 PHPDoc 中有附加信息:
Conditional Assertion: Test won't be stopped on fail
但这到底是什么意思呢?在测试失败时,PhpStorm 只显示第一个错误,所以我看不出有什么区别。这两个调用之间有什么实际区别吗:
$this->tester->seeRecord(MyModel::class, ['name' => 'rob006']);
$this->tester->canSeeRecord(MyModel::class, ['name' => 'rob006']);
记录于 https://codeception.com/docs/03-AcceptanceTests#Conditional-Assertions
Usually, as soon as any assertion fails, further assertions of this test will be skipped. Sometimes you don’t want this - maybe you have a long-running test and you want it to run to the end. In this case, you can use conditional assertions. Each
see
method has a correspondingcanSee
method, anddontSee
has acantSee
method:$I->canSeeInCurrentUrl('/user/miles'); $I->canSeeCheckboxIsChecked('#agree'); $I->cantSeeInField('user[name]', 'Miles');
Each failed assertion will be shown in the test results, but it won’t stop the test.
证明 PHPDoc 是正确的 - 断言失败后测试将继续。但就我而言,我对 PhpStorm 集成感到困惑,它只报告第一个错误。
我创建了简单测试:
public function testTest() {
// products table is empty - these tests always fail
$this->tester->canSeeRecord(Product::class, ['id' => 1]);
$this->tester->canSeeRecord(Product::class, ['id' => 2]);
$this->tester->canSeeRecord(Product::class, ['id' => 3]);
}
PhpStorm 在此测试中仅显示第一个错误:
但是当您 运行 从控制台进行此测试时,会报告所有三个错误: