如何为codeception测试用例提供唯一的ID


How to provide unique IDs to codeception testcases?

我有一些正在自动化的测试用例,它们有唯一的ID。

//Plain English testcase
ID: 1234
1. Go to url: "example.com"
2. Click on button named: "Don't click me"
3. See if the button got angry 

我在哪里可以将上述测试用例的ID包含到该测试用例的自动化版本中(位于下面)?

//Automated version of the above testcase
$I = new AcceptanceTester($scenario);
$I->amOnUrl("example.com");
$I->see("Don't click me");
$I->click("#angry_button");
$I->see('......') // some result

请记住,无论何时生成前者,该ID都必须存在于xml报告中:

codecept run acceptance --xml

您可以使用

$I->wantTo("Test ID: 1234");

但是,如果您在每个测试用例执行中引用一个唯一的ID,则可以使用日期作为一种变通方法。

例如:

$time = date("m-j-Y-G:i:s");
$I->wantTo("Test ID ".$time);

开始在codeception中使用Cest测试用例。这会让你的生活轻松很多。相信我,我是从Cept开始的。

所以,当你使用塞斯特时,你可以做以下事情:

使用您的函数名称作为唯一id。在我的测试中,我有:

public function testPageElementsAvailability(AcceptanceTester $I)
{ 
  test some thing
}

这将生成以下xml

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite name="acceptance" tests="1" assertions="1" failures="0" errors="0" time="3.954338">
    <testcase file="..../createCest.php" name="testPageElementsAvailability" class="post'createCest" feature="test page elements availability" assertions="1" time="3.954338"/>
 </testsuite>
</testsuites>