diff --git a/module/testcase/test/lib/testcasezen.unittest.class.php b/module/testcase/test/lib/testcasezen.unittest.class.php index ebd982e153..96916fcc50 100755 --- a/module/testcase/test/lib/testcasezen.unittest.class.php +++ b/module/testcase/test/lib/testcasezen.unittest.class.php @@ -983,7 +983,17 @@ class testcaseZenTest try { $result = callZenMethod('testcase', 'checkCasesForShowImport', [$cases]); - if(dao::isError()) return dao::getError(); + if(dao::isError()) + { + $errors = dao::getError(); + /* Flatten error array for test framework compatibility. */ + $flatErrors = array(); + foreach($errors as $key => $value) + { + $flatErrors[$key] = is_array($value) ? implode(',', $value) : $value; + } + return $flatErrors; + } return $result; } catch (Exception $e) { diff --git a/module/testcase/test/zen/checkcasesforshowimport.php b/module/testcase/test/zen/checkcasesforshowimport.php new file mode 100755 index 0000000000..90058e4070 --- /dev/null +++ b/module/testcase/test/zen/checkcasesforshowimport.php @@ -0,0 +1,65 @@ +#!/usr/bin/env php + 1, 'title' => '测试用例1', 'type' => 'feature', 'steps' => array(1 => '步骤1', 2 => '步骤2'), 'expects' => array(1 => '期望1', 2 => '期望2')), + (object)array('id' => 2, 'title' => '测试用例2', 'type' => 'interface', 'steps' => array(1 => '步骤1'), 'expects' => array(1 => '期望1')) +); +r($testcaseTest->checkCasesForShowImportTest($validCases)) && p('0:title') && e('测试用例1'); + +// 步骤2:边界值 - title字段为空 +$casesWithEmptyTitle = array( + (object)array('id' => 1, 'title' => '', 'type' => 'feature', 'steps' => array(1 => '步骤1'), 'expects' => array(1 => '期望1')), + (object)array('id' => 2, 'title' => '测试用例2', 'type' => 'interface', 'steps' => array(1 => '步骤1'), 'expects' => array(1 => '期望1')) +); +r($testcaseTest->checkCasesForShowImportTest($casesWithEmptyTitle)) && p('title[0]') && e('『用例名称』不能为空。'); + +// 步骤3:异常输入 - type字段为空 +$casesWithEmptyType = array( + (object)array('id' => 1, 'title' => '测试用例1', 'type' => '', 'steps' => array(1 => '步骤1'), 'expects' => array(1 => '期望1')), + (object)array('id' => 2, 'title' => '测试用例2', 'type' => 'interface', 'steps' => array(1 => '步骤1'), 'expects' => array(1 => '期望1')) +); +r($testcaseTest->checkCasesForShowImportTest($casesWithEmptyType)) && p('type[0]') && e('『用例类型』不能为空。'); + +// 步骤4:业务规则验证 - 期望有值但步骤为空 +$casesWithExpectButNoStep = array( + (object)array('id' => 1, 'title' => '测试用例1', 'type' => 'feature', 'steps' => array(), 'expects' => array(1 => '期望1')), + (object)array('id' => 2, 'title' => '测试用例2', 'type' => 'interface', 'steps' => array(1 => '步骤1'), 'expects' => array(1 => '期望1')) +); +r($testcaseTest->checkCasesForShowImportTest($casesWithExpectButNoStep)) && p('steps[0]') && e('步骤1不能为空'); + +// 步骤5:多个错误 - title和type都为空 +$casesWithMultipleErrors = array( + (object)array('id' => 1, 'title' => '', 'type' => '', 'steps' => array(1 => '步骤1'), 'expects' => array(1 => '期望1')), + (object)array('id' => 2, 'title' => '测试用例2', 'type' => 'interface', 'steps' => array(1 => '步骤1'), 'expects' => array(1 => '期望1')) +); +r($testcaseTest->checkCasesForShowImportTest($casesWithMultipleErrors)) && p('title[0],type[0]') && e('『用例名称』不能为空。,『用例类型』不能为空。'); \ No newline at end of file