Php 如何在codeception中编写正确的Cest格式测试?
我注意到,每当运行Cest类型的测试用例时,它们都会在完成后保留会话。换言之,其他测试有可能从测试之前停止的地方继续进行。例如:Php 如何在codeception中编写正确的Cest格式测试?,php,automated-tests,codeception,acceptance-testing,Php,Automated Tests,Codeception,Acceptance Testing,我注意到,每当运行Cest类型的测试用例时,它们都会在完成后保留会话。换言之,其他测试有可能从测试之前停止的地方继续进行。例如: class CheckGoogleSearch{ public function checkIfPageIsAccessible(AcceptanceTester $I){ $I->amOnPage('/'); $I->see('something..'); } public function checkIfSearchFie
class CheckGoogleSearch{
public function checkIfPageIsAccessible(AcceptanceTester $I){
$I->amOnPage('/');
$I->see('something..');
}
public function checkIfSearchFieldIsAccessible(AcceptanceTester $I){
// Notice, that it is assumed that we are on the google's home page,
//because the above test had it already opened in the past
$I->see('Google Search');
}
}
此代码是否可以被视为最佳实践?或者将来它会很容易出错,在每次测试之前重置到Google的主页(并做一些额外的准备)会更好吗?您可以使用
@取决于
注释。这样,如果您的第一个测试失败,那么依赖于上一个测试的下一个测试将被跳过,并且不会报告失败
class CheckGoogleSearch{
public function checkIfPageIsAccessible(AcceptanceTester $I){
$I->amOnPage('/');
$I->see('something..');
}
/**
* @param AcceptanceTester $I
* @depends login
*/
public function checkIfSearchFieldIsAccessible(AcceptanceTester $I){
// Notice, that it is assumed that we are on the google's home page,
//because the above test had it already opened in the past
$I->see('Google Search');
}
}
我个人认为这不是一个好的或坏的做法。这取决于您的测试堆栈。
在您的示例中,如果您只有codeception,而没有其他需要更详细信息的集成,那么在测试id上执行所有操作都很好,但在我的示例中,我有一个Testlink集成,其中包含一个测试用例