【问题标题】:How to write right Cest format tests in codeception?如何在代码接收中编写正确的 Cest 格式测试?
【发布时间】:2016-04-04 07:35:11
【问题描述】:

我注意到,每当运行 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');
  }
}

可以将此代码视为最佳实践吗?或者以后会不会容易出错,每次测试前重置到谷歌的主页(并做一些额外的准备)会更好吗?

【问题讨论】:

标签: php automated-tests codeception acceptance-testing


【解决方案1】:

你可以使用

@依赖

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

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

我个人认为这种做法既不好也不坏。这取决于您的测试堆栈。 在您的示例中,如果您只有代码接收,并且没有其他需要更详细信息的集成,那么所有测试 id 都可以,但我的情况是,我有一个带有测试用例的 Testlink 集成

  1. 我可以打开/访问该页面吗
  2. 某些元素是否可用
  3. 我可以进行搜索并获得预期的结果

希望这会有所帮助。

测试愉快!!

【讨论】:

    猜你喜欢
    • 2023-03-13
    • 1970-01-01
    • 2012-01-22
    • 2011-03-17
    • 2017-07-13
    • 2019-12-12
    • 2013-02-24
    • 1970-01-01
    • 2023-01-14
    相关资源
    最近更新 更多