From 7b48a76d41ba61754d067aaa8fa4ccd882a35960 Mon Sep 17 00:00:00 2001 From: liugang Date: Wed, 10 Sep 2025 10:19:30 +0800 Subject: [PATCH] + [misc] Add unit tests for testtaskModel::processStepResults() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../test/lib/testtask.unittest.class.php | 23 +++++++++ .../test/model/processstepresults.php | 47 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100755 module/testtask/test/model/processstepresults.php diff --git a/module/testtask/test/lib/testtask.unittest.class.php b/module/testtask/test/lib/testtask.unittest.class.php index 2210687468..b9e3710c3a 100644 --- a/module/testtask/test/lib/testtask.unittest.class.php +++ b/module/testtask/test/lib/testtask.unittest.class.php @@ -692,4 +692,27 @@ class testtaskTest return $result; } + + /** + * Test processStepResults method. + * + * @param array $caseIdList + * @param int $caseID + * @param string $caseResult + * @param array $postSteps + * @param array $postReals + * @access public + * @return array + */ + public function processStepResultsTest(array $caseIdList, int $caseID, string $caseResult, array $postSteps, array $postReals): array + { + $reflection = new ReflectionClass($this->objectModel); + $method = $reflection->getMethod('processStepResults'); + $method->setAccessible(true); + + $result = $method->invokeArgs($this->objectModel, [$caseIdList, $caseID, $caseResult, $postSteps, $postReals]); + if(dao::isError()) return dao::getError(); + + return $result; + } } diff --git a/module/testtask/test/model/processstepresults.php b/module/testtask/test/model/processstepresults.php new file mode 100755 index 0000000000..6f63984cd2 --- /dev/null +++ b/module/testtask/test/model/processstepresults.php @@ -0,0 +1,47 @@ +#!/usr/bin/env php +id->range('1-6'); +$casestepTable->case->range('1{3},2{2},3{1}'); +$casestepTable->version->range('1{6}'); +$casestepTable->type->range('step{6}'); +$casestepTable->gen(6); + +$caseTable = zenData('case'); +$caseTable->id->range('1-5'); +$caseTable->status->range('normal{5}'); +$caseTable->version->range('1{5}'); +$caseTable->gen(5); + +// 3. 用户登录 +su('admin'); + +// 4. 创建测试实例 +$testtaskTest = new testtaskTest(); + +// 5. 执行测试步骤 +r($testtaskTest->processStepResultsTest([1, 2], 1, 'pass', [], [])) && p('1:result') && e('pass'); // 步骤1:用例有步骤,结果为pass +r($testtaskTest->processStepResultsTest([1, 2], 1, 'fail', [1 => 'fail', 2 => 'pass', 3 => 'fail'], [1 => '实际结果1'])) && p('1:result') && e('fail'); // 步骤2:用例有步骤,结果为fail +r($testtaskTest->processStepResultsTest([1, 2], 4, 'pass', [], [])) && p('0:result') && e('pass'); // 步骤3:用例无步骤,结果为pass +r($testtaskTest->processStepResultsTest([1, 2], 4, 'fail', [], ['测试失败原因'])) && p('0:result') && e('fail'); // 步骤4:用例无步骤,结果为fail +r($testtaskTest->processStepResultsTest([], 1, 'pass', [], [])) && p() && e('Array'); // 步骤5:空步骤数组测试 \ No newline at end of file