2017-04-08 41 views
0

我想將我的功能測試結果與TestRail集成。由於測試軌接受狀態更新意味着測試是成功還是未能與其集成。但PHPunit函數像assertEqual,assertTrue等不返回任何值。 我們該怎麼做?如何將PHPunit與testrail集成

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條件。

回答

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