2015-12-30 109 views
2

我注意到,每当运行CEST类型的测试用例时,它们会在完成之后保留它们的会话。换句话说,其他测试可能从继续进行,在此之前的测试将从开始。例如:如何在代码中编写正确的Cest格式测试?

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的主页并做一些额外的准备工作会更好吗?

+1

这是一个错误:https://github.com/Codeception/Codeception/issues/2586 – Naktibalda

回答

0

可以使用

@depends

注解。这样,如果您的第一次测试失败,则依赖于前一次测试的下一次测试将被跳过,而不会报告失败。

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'); 
    } 
} 

Personnaly我不认为这是好的或不好的做法。这取决于你的测试堆栈。 在您的例子,如果你只有codeception,而且需要更精细的细节没有其他的整合,做所有作为测试ID很好,但我的情况我有一个测试情况下,我可以开TESTLINK集成

  1. /访问页面
  2. 是否可用
  3. 某些元素我可以做一个搜索,并得到预期的结果

希望这有助于。

快乐测试!

相关问题