0

我想将我的功能测试结果与 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
}

当测试失败时,它不会进入 else 条件。

4

1 回答 1

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;
    }
}
于 2017-04-10T19:18:47.840 回答