+ [misc] Add unit tests for testtaskZen::buildTaskForImportUnitResult() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -340,4 +340,114 @@ class testtaskZenTest
|
||||
return array('error' => $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test buildTaskForImportUnitResult method.
|
||||
*
|
||||
* @param int $productID
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function buildTaskForImportUnitResultTest($productID = 1)
|
||||
{
|
||||
// 根据不同的productID使用不同的测试数据
|
||||
$testData = array(
|
||||
1 => array(
|
||||
'execution' => 1,
|
||||
'build' => 1,
|
||||
'frame' => 'phpunit',
|
||||
'owner' => 'admin',
|
||||
'begin' => '2024-01-01',
|
||||
'end' => '2024-01-31',
|
||||
'name' => '单元测试导入任务',
|
||||
'pri' => 3,
|
||||
'desc' => '<p>从单元测试结果导入的测试任务</p>',
|
||||
'mailto' => 'admin,qa',
|
||||
'uid' => 'uid123'
|
||||
),
|
||||
2 => array(
|
||||
'execution' => 0,
|
||||
'build' => 2,
|
||||
'frame' => 'jest',
|
||||
'owner' => 'user1',
|
||||
'begin' => '2024-02-01',
|
||||
'end' => '2024-02-28',
|
||||
'name' => 'Jest单元测试',
|
||||
'pri' => 2,
|
||||
'desc' => '',
|
||||
'mailto' => '',
|
||||
'uid' => 'uid456'
|
||||
),
|
||||
5 => array(
|
||||
'execution' => 5,
|
||||
'build' => 3,
|
||||
'frame' => 'junit',
|
||||
'owner' => 'tester',
|
||||
'begin' => '2024-03-01',
|
||||
'end' => '2024-03-31',
|
||||
'name' => 'JUnit测试导入',
|
||||
'pri' => 1,
|
||||
'desc' => '<script>alert("xss")</script>Java单元测试结果导入',
|
||||
'mailto' => 'qa,dev',
|
||||
'uid' => ''
|
||||
),
|
||||
0 => array(
|
||||
'execution' => 0,
|
||||
'build' => 1,
|
||||
'frame' => '',
|
||||
'owner' => '',
|
||||
'begin' => '2024-12-01',
|
||||
'end' => '2024-12-31',
|
||||
'name' => '无效产品ID测试',
|
||||
'pri' => 3,
|
||||
'desc' => '测试无效产品ID的情况',
|
||||
'mailto' => '',
|
||||
'uid' => 'invalid'
|
||||
),
|
||||
999 => array(
|
||||
'execution' => 999,
|
||||
'build' => 999,
|
||||
'frame' => 'unknown',
|
||||
'owner' => 'unknown',
|
||||
'begin' => '2025-01-01',
|
||||
'end' => '2025-01-31',
|
||||
'name' => '不存在的产品测试',
|
||||
'pri' => 4,
|
||||
'desc' => '测试不存在的产品ID',
|
||||
'mailto' => 'admin',
|
||||
'uid' => 'test999'
|
||||
)
|
||||
);
|
||||
|
||||
$data = isset($testData[$productID]) ? $testData[$productID] : $testData[1];
|
||||
|
||||
// 保存原始$_POST和$_GET数据
|
||||
$originalPost = $_POST;
|
||||
$originalGet = $_GET;
|
||||
|
||||
// 模拟表单数据
|
||||
$_POST = $data;
|
||||
$_GET = array();
|
||||
|
||||
try {
|
||||
$testtaskZen = $this->testtaskZenTest->newInstance();
|
||||
$method = $this->testtaskZenTest->getMethod('buildTaskForImportUnitResult');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invoke($testtaskZen, (int)$productID);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
// 恢复原始数据
|
||||
$_POST = $originalPost;
|
||||
$_GET = $originalGet;
|
||||
|
||||
return $result;
|
||||
} catch(Exception $e) {
|
||||
// 恢复原始数据
|
||||
$_POST = $originalPost;
|
||||
$_GET = $originalGet;
|
||||
|
||||
return array('error' => $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 testtaskZen::buildTaskForImportUnitResult();
|
||||
cid=0
|
||||
|
||||
- 测试步骤1:正常产品ID测试 >> 期望返回构建的任务对象
|
||||
- 测试步骤2:空产品ID测试 >> 期望返回构建的任务对象
|
||||
- 测试步骤3:不存在的产品ID测试 >> 期望返回构建的任务对象
|
||||
- 测试步骤4:大产品ID测试 >> 期望返回构建的任务对象
|
||||
- 测试步骤5:验证必须字段设置 >> 期望product、auto字段正确设置
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/testtaskzen.unittest.class.php';
|
||||
|
||||
zenData('product')->loadYaml('product', false, 2)->gen(10);
|
||||
|
||||
su('admin');
|
||||
|
||||
$testtaskZenTest = new testtaskZenTest();
|
||||
|
||||
r($testtaskZenTest->buildTaskForImportUnitResultTest(1)) && p('product,auto') && e('1,unit');
|
||||
r($testtaskZenTest->buildTaskForImportUnitResultTest(0)) && p('product,auto') && e('0,unit');
|
||||
r($testtaskZenTest->buildTaskForImportUnitResultTest(999)) && p('product,auto') && e('999,unit');
|
||||
r($testtaskZenTest->buildTaskForImportUnitResultTest(5)) && p('product,auto,name') && e('5,unit,JUnit测试导入');
|
||||
r($testtaskZenTest->buildTaskForImportUnitResultTest(1)) && p('product,auto') && e('1,unit');
|
||||
Reference in New Issue
Block a user