我想将我的功能测试结果与TestRail集成。由于测试轨接受状态更新意味着测试是成功还是失败与其集成。但是像assertEqual,assertTrue等PHPunit函数不会返回任何值。 我们怎么做到这一点?
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
}
当测试失败时,它不会进入其他状态。
答案 0 :(得分:1)
一个简单的答案是捕获异常,发布结果并重新抛出异常。
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;
}
}