* Add auto test of testcase.
This commit is contained in:
@@ -7,6 +7,90 @@ class testcaseTest
|
||||
$this->objectModel = $tester->loadModel('testcase');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test create a case.
|
||||
*
|
||||
* @param array $param
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function createTest($param)
|
||||
{
|
||||
$bugID = 0;
|
||||
|
||||
$_POST['product'] = '1';
|
||||
$_POST['module'] = '1821';
|
||||
$_POST['type'] = 'feature';
|
||||
$_POST['stage'] = array('', 'unittest');
|
||||
$_POST['story'] = '4';
|
||||
$_POST['color'] = '';
|
||||
$_POST['pri'] = '3';
|
||||
$_POST['precondition'] = '前置条件';
|
||||
$_POST['steps'] = array('1' => '1','1.1' => '1.1', '1.2' => '1.2', '2' => '2', '3' => '3', '4' => '');
|
||||
$_POST['stepType'] = array('1' => 'group','1.1' => 'item', '1.2' => 'item', '2' => 'step', '3' => 'item', '4' => 'step');
|
||||
$_POST['expects'] = array('1' => '','1.1' => '', '1.2' => '', '2' => '', '3' => '', '4' => '');
|
||||
$_POST['keywords'] = '关键词1,关键词2';
|
||||
$_POST['status'] = 'normal';
|
||||
$_POST['labels'] = array('');
|
||||
$_POST['files'] = array('');
|
||||
|
||||
foreach($param as $field => $value) $_POST[$field] = $value;
|
||||
|
||||
$objects = $this->objectModel->create($bugID);
|
||||
|
||||
unset($_POST);
|
||||
|
||||
if(dao::isError()) return isset($param['type']) ? dao::getError()['type'][0] : dao::getError()['title'][0];
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test batch create cases.
|
||||
*
|
||||
* @param array $param
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
function batchCreateTest($param)
|
||||
{
|
||||
$productID = 1;
|
||||
$branch = 0;
|
||||
$storyID = 0;
|
||||
|
||||
$module = array(0, 0, 0);
|
||||
$story = array(0, 0, 0);
|
||||
$title = array('测试批量创建1', '测试批量创建2', '测试批量创建3');
|
||||
$color = array('#3da7f5', '', '#ffaf38');
|
||||
$type = array('performance', 'config', 'install');
|
||||
$pri = array('1', '2', '3');
|
||||
$precondition = array('测试批量创建前置1', '测试批量创建前置2', '测试批量创建前置3');
|
||||
$keywords = array('测试批量创建关键词1', '测试批量创建关键词2', '测试批量创建关键词3');
|
||||
$stage = array(array('smoke'), array('bvt'), array('intergrate'));
|
||||
$needReview = array(0, 0, 0);
|
||||
|
||||
$_POST['module'] = $module;
|
||||
$_POST['story'] = $story;
|
||||
$_POST['title'] = $title;
|
||||
$_POST['color'] = $color;
|
||||
$_POST['type'] = $type;
|
||||
$_POST['pri'] = $pri;
|
||||
$_POST['precondition'] = $precondition;
|
||||
$_POST['keywords'] = $keywords;
|
||||
$_POST['stage'] = $stage;
|
||||
$_POST['needReview'] = $needReview;
|
||||
|
||||
foreach($param as $field => $value) $_POST[$field] = $value;
|
||||
|
||||
$objects = $this->objectModel->batchCreate($productID, $branch, $storyID);
|
||||
|
||||
unset($_POST);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return count($objects);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get cases of a module.
|
||||
*
|
||||
@@ -325,14 +409,14 @@ class testcaseTest
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function batchUpdateTest($param = array())
|
||||
public function batchUpdateTest($index, $param = array())
|
||||
{
|
||||
$batchUpdateField['caseIDList'] = array('1' => 1, '2' => 2, '3' => 3, '4' => 4);
|
||||
$batchUpdateField['pris'] = array('1' => 1, '2' => 2, '3' => 3, '4' => 4);
|
||||
$batchUpdateField['statuses'] = array('1' => 'wait', '2' => 'normal', '3' => 'blocked', '4' => 'investigate');
|
||||
$batchUpdateField['modules'] = array('1' => 0, '2' => 0, '3' => 0, '4' => 0);
|
||||
$batchUpdateField['branches'] = array('1' => 0, '2' => 0, '3' => 0, '4' => 0);
|
||||
$batchUpdateField['story'] = array('1' => 0, '2' => 0, '3' => 0, '4' => 0);
|
||||
$batchUpdateField['story'] = array('1' => 2, '2' => 2, '3' => 2, '4' => 2);
|
||||
$batchUpdateField['product'] = array('1' => 1, '2' => 1, '3' => 1, '4' => 1);
|
||||
$batchUpdateField['title'] = array('1' => '这个是测试用例1', '2' => '这个是测试用例2', '3' => '这个是测试用例3', '4' => '这个是测试用例4');
|
||||
$batchUpdateField['color'] = array('1' => '#3da7f5', '2' => '#75c941', '3' => '#2dbdb2', '4' => '#797ec9');
|
||||
@@ -351,7 +435,7 @@ class testcaseTest
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
return $objects[$index][0];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/testcase.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 testcaseModel->batchCreate();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$title1 = array('测试批量创建4', '', '测试批量创建6');
|
||||
$title2 = array('测试批量创建7', '测试批量创建8', '测试批量创建9');
|
||||
$title3 = array('测试批量创建10', '测试批量创建11', '测试批量创建12');
|
||||
$title4 = array('测试批量创建13', '测试批量创建14', '测试批量创建15');
|
||||
$title5 = array('测试批量创建16', '测试批量创建17', '测试批量创建18');
|
||||
$type = array('feature', 'ditto', 'config');
|
||||
$pri = array('2', 'ditto', '1');
|
||||
$stage = array(array('system', 'smoke'), array('bvt'), array('unittest'));
|
||||
$needReview = array(0, 1, 0);
|
||||
|
||||
|
||||
$testcase = new testcaseTest();
|
||||
|
||||
r($testcase->batchCreateTest(array('title' => $title1))) && p() && e('2'); // 测试批量创建用例1
|
||||
r($testcase->batchCreateTest(array('type' => $type, 'title' => $title2))) && p() && e('3'); // 测试批量创建用例2
|
||||
r($testcase->batchCreateTest(array('pri' => $pri, 'title' => $title3))) && p() && e('3'); // 测试批量创建用例3
|
||||
r($testcase->batchCreateTest(array('stage' => $stage, 'title' => $title4))) && p() && e('3'); // 测试批量创建用例4
|
||||
r($testcase->batchCreateTest(array('needReview' => $needReview, 'title' => $title5))) && p() && e('3'); // 测试批量创建用例5
|
||||
r($testcase->batchCreateTest(array('title' => $title1))) && p() && e('0'); // 测试重复批量创建用例1
|
||||
system("./ztest init");
|
||||
Executable
+47
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/testcase.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 testcaseModel->batchUpdate();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$changeTitle = array('1' => '修改后的测试用例1', '2' => '这个是测试用例2', '3' => '这个是测试用例3', '4' => '这个是测试用例4');;
|
||||
$changePris = array('1' => 1, '2' => 1, '3' => 3, '4' => 4);
|
||||
$changeStatuses = array('1' => 'wait', '2' => 'normal', '3' => 'nomal', '4' => 'investigate');
|
||||
$changeModules = array('1' => 0, '2' => 0, '3' => 0, '4' => 1822);
|
||||
$changeColor = array('1' => '#2dbdb2', '2' => '#75c941', '3' => '#2dbdb2', '4' => '#797ec9');
|
||||
$changeTypes = array('1' => 'feature', '2' => 'other', '3' => 'config', '4' => 'install');
|
||||
$changePrecondition = array('1' => '这是前置条件1', '2' => '这是前置条件2', '3' => '修改后的前置条件3', '4' => '这是前置条件4');
|
||||
$changeKeywords = array('1' => '这是关键词1', '2' => '这是关键词2', '3' => '这是关键词3', '4' => '修改后的关键词4');
|
||||
$changeStages = array('1' => array('unittest', 'feature'), '2' => array('feature'), '3' => array('intergrate'), '4' => array('system'));
|
||||
|
||||
$changeTitle = array('title' => $changeTitle);
|
||||
$changePris = array('pris' => $changePris);
|
||||
$changeStatuses = array('statuses' => $changeStatuses);
|
||||
$changeModules = array('modules' => $changeModules);
|
||||
$changeColor = array('color' => $changeColor);
|
||||
$changeTypes = array('types' => $changeTypes);
|
||||
$changePrecondition = array('precondition' => $changePrecondition);
|
||||
$changeKeywords = array('keywords' => $changeKeywords);
|
||||
$changeStages = array('stages' => $changeStages);
|
||||
|
||||
|
||||
$testcase = new testcaseTest();
|
||||
|
||||
r($testcase->batchUpdateTest(1, $changeTitle)) && p('field,old,new') && e('title,这个是测试用例1,修改后的测试用例1'); // 测试批量修改用例标题
|
||||
r($testcase->batchUpdateTest(2, $changePris)) && p('field,old,new') && e('pri,2,1'); // 测试批量修改用例优先级
|
||||
r($testcase->batchUpdateTest(3, $changeStatuses)) && p('field,old,new') && e('status,blocked,nomal'); // 测试批量修改用例状态
|
||||
r($testcase->batchUpdateTest(4, $changeModules)) && p('field,old,new') && e('module,0,1822'); // 测试批量修改用例模块
|
||||
r($testcase->batchUpdateTest(1, $changeColor)) && p('field,old,new') && e('color,#3da7f5,#2dbdb2'); // 测试批量修改用例颜色
|
||||
r($testcase->batchUpdateTest(2, $changeTypes)) && p('field,old,new') && e('type,performance,other'); // 测试批量修改用例类型
|
||||
r($testcase->batchUpdateTest(3, $changePrecondition)) && p('field,old,new') && e('precondition,这是前置条件3,修改后的前置条件3'); // 测试批量修改用例前置条件
|
||||
r($testcase->batchUpdateTest(4, $changeKeywords)) && p('field,old,new') && e('keywords,这是关键词4,修改后的关键词4'); // 测试批量修改用例关键词
|
||||
r($testcase->batchUpdateTest(1, $changeStages)) && p('field,old,new') && e('stage,unittest,unittest,feature'); // 测试批量修改用例阶段
|
||||
system("./ztest init");
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/testcase.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 testcaseModel->create();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$testcase1 = array('title' => '测试创建测试用例1');
|
||||
$testcase2 = array('title' => '测试创建测试用例2', 'pri' => '1', 'type' => 'performance');
|
||||
$testcase3 = array('title' => '测试创建测试用例3', 'keywords' => '测试关键词3', 'stage' => array('unittest', 'smoke'));
|
||||
|
||||
$no_title = array('title' => '');
|
||||
$no_type = array('type' => '', 'title' => '测试创建没有填写类型的用例');
|
||||
|
||||
|
||||
|
||||
$testcase = new testcaseTest();
|
||||
|
||||
r($testcase->createTest($testcase1)) && p('status') && e('created'); // 测试创建用例1
|
||||
r($testcase->createTest($testcase2)) && p('status') && e('created'); // 测试创建用例2
|
||||
r($testcase->createTest($testcase3)) && p('status') && e('created'); // 测试创建用例3
|
||||
r($testcase->createTest($testcase1)) && p('status') && e('exists'); // 测试创建重名用例1
|
||||
r($testcase->createTest($no_title)) && p() && e('『用例标题』不能为空。'); // 测试创建没有填写名字的用例
|
||||
r($testcase->createTest($no_type)) && p() && e('『用例类型』不能为空。'); // 测试创建没有填写类型的用例
|
||||
system("./ztest init");
|
||||
Reference in New Issue
Block a user