Ejemplo n.º 1
0
 /**
  * @param TestMethodReport $testMethodReport
  */
 public function addTestMethodReport($testMethodReport)
 {
     $testMethodReport->setTestCaseReport($this);
     $this->testMethodReports[] = $testMethodReport;
 }
Ejemplo n.º 2
0
 /**
  * 执行测试用例
  * @param TestCase $testCase
  */
 protected function runTestCase(TestCase $testCase)
 {
     //给测试用例传递Mechanic
     $testCase->setMechanic($this);
     $testMethods = $this->getTestCaseTestMethods($testCase);
     $this->dispatcher->dispatch(EventStore::TEST_CASE_EXECUTE, new Event(EventStore::TEST_CASE_EXECUTE, $this, ['testCase' => $testCase, 'testMethods' => $testMethods]));
     foreach ($testMethods as $testMethod) {
         try {
             //执行用例方法,如果方法没有明确返回false,则用例方法算执行成功
             $result = $testMethod->invoke($testCase);
             $result = $result !== false;
             $message = '';
         } catch (\Exception $e) {
             $result = false;
             $message = $e->getMessage();
         }
         //记录用例方法的测试报告到用例报告
         $testCase->getTestCaseReport()->addTestMethodReport(TestMethodReport::create($testMethod, $result, [$message]));
     }
     $this->dispatcher->dispatch(EventStore::TEST_CASE_EXECUTED, new Event(EventStore::TEST_CASE_EXECUTED, $this, ['testCase' => $testCase]));
 }