0

I want to integrate my functional test result with TestRail . Since test rail accept status update means whether the test is success or fail for integrating with it . But PHPunit functions like assertEqual, assertTrue, etc do not return any values. How can we do this?

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
}

when a test fails it does not go to the else condition.

Naktibalda
  • 13,705
  • 5
  • 35
  • 51
G San
  • 81
  • 6

1 Answers1

1

A straightforward answer is to catch exception, post result and rethrow exception.

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;
    }
}
Naktibalda
  • 13,705
  • 5
  • 35
  • 51