我想将我的功能测试结果与TestRail集成。由于测试轨接受状态更新意味着测试是成功还是失败,无法与之集成。但是 PHPunit 函数如 assertEqual、assertTrue 等不返回任何值。我们该怎么做呢?
public function testGetItem()
{
$this->specify("Verify the functionality of the method ", function ($itemId, $orgId, $expectedResult) {
$result = $this->itemRepository->getItemInfo($ItemId , $orgId);
//$this->assertEquals($expectedResult , $result)
$testRail=new TestRailIntegration();
if($this->assertEquals($expectedResult , $result)){
$testRail->postResultsToTestRail("34530","1");
} else{
$testRail->postResultsToTestRail("34530","");
}
//34530 is testrail id
}
当测试失败时,它不会转到 ELSE 条件。
一个简单的答案是捕获异常,发布结果并重新抛出异常。
public function testGetItem()
{
$this->specify("Verify the functionality of the method ", function ($itemId, $orgId, $expectedResult) {
$testRail = new TestRailIntegration();
try {
$result = $this->itemRepository->getItemInfo($ItemId , $orgId);
$this->assertEquals($expectedResult, $result);
$testRail->postResultsToTestRail("34530", "1");
} catch (Exception $e) {
$testRail->postResultsToTestRail("34530", "");
throw $e;
}
}