为了完成我的想法,通过套用bjui的框架来进行开发,编程语言为php+mysql+jquery。
下图是我暂时定义的数据库表:
testcase:保存测试用例
testcase_info:测试用例表单的一些选项
testimplement:测试执行
testplan:测试计划
testplan_list:测试计划中的测试用例的排序
testresult:测试结果
最初我做测试执行这个模块的流程是:
一.测试执行者进入这个模块后,加载指定给你的测试计划列表
<?php
$name = getusername();
$res=mysql_query("SELECT tpid,tpname FROM tb_testplan WHERE tpcreater LIKE '%$name%' AND isdel=0 ORDER BY tpid");
while ($tprow=mysql_fetch_array($res)){
echo '<li data-id="10" data-pid="1" data-url="item_testcase/testimplement_manual_new_imp_new.php?tpid='.$tprow['tpid'].'"
data-divid="#implement_new_caselist">'.$tprow['tpname'].'</li>';
}
?>
二.选择相应测试计划后,局部刷新页面,显示测试计划详细,并且要求填写相应的执行名称。
// 测试计划id
$tpid = $_GET['tpid'];
$res=mysql_query("select * from tb_testplan where tpid=$tpid");
$tprow=mysql_fetch_array($res);
三.开始执行后,页面刷新。在正在执行的列表中显示我正在执行的列表
通过js提交数据到数据库<button type="button" class="btn-default" data-icon="save" οnclick="do_ti_commit('#tiimplementer','#tiname','#tpid')">开始执行</button>
function do_ti_commit(tiimplementer,tiname,tpid){
var to_url="item_testcase/testimplement_manual_new_imp_new_commit.php?tiimplementer=" + $(tiimplementer).val() +"&tiname="+$(tiname).val()+"&tpid="+$(tpid).val();
$.ajax({
type: "GET",
url: to_url,
success: function(msg){
//刷新指定tab页
$(document).navtab("refresh","testimplement_manual_new");
}
})
}
四.点击相应执行列表后,获取对应测试计划的测试用例的排列,并且在第一次打开后在测试结果中预先生成相应测试执行的每条测试用例的测试结果。
<pre name="code" class="php">// 通过id获得指定测试计划的内容
$tpid = Getpara('tpid');
$tiid = Getpara('tiid');
$result = mysql_query("SELECT * FROM tb_testplan WHERE tpid='$tpid'");
$tprow = mysql_fetch_array($result);
//$caselist=$tprow['tptestcaselist'];
//如果是新建执行,则向testresult中预先建立测试结果数据
$res = mysql_query("SELECT * FROM tb_testimplement WHERE tiid='$tiid'");
$tirow = mysql_fetch_array($res);
if($tirow['tistatus']=="新建"){
$tplres=mysql_query("select tcid from tb_testplan_list where tpid='$tpid'");
while($tclrow=mysql_fetch_array($tplres)){
mysql_query("insert into tb_testresult (tpid,tiid,tcid) values('$tpid','$tiid','".$tclrow['tcid']."')");
}
}else{
}
五.选中每条测试用例后,局部刷新页面,显示测试用例详细步骤(所有界面尽量不弹窗,用ajax完成)
<tr οnclick="show_detail('. $tclrow['tcid'].')">
function show_detail(tid){
$.ajax({
type: "POST",
url: "item_testcase/testimplement_manual_new_layout_casedetail.php",
data: "tcid="+tid,
success: function(msg){
$("#implement_new_casedetail").html(msg);
}
})
}
六.在每条测试用例可以勾选测试结果,选择后更新测试结果相应的状态,以达到实时更新和退出后重新打开不会丢失测试进度的功能。
在控制测试结果的状态下有点繁琐,主要功能如下:
1.显示测试用例列表后,未经测试的用例NT,需要隐藏结果按钮,点击相应用例后异步在其他布局显示用例详细信息,并显示结果按钮。
2.点击相应结果后(pass,fail)更新界面状态为测试结果和重新测试按钮,同时存入tb_testresult
3.点击重新测试按钮后,再次显示结果按钮,并更新数据库状态为NT。
为完成以上功能,需使用js控制页面信息,通过js调用ajax来控制数据库更新信息
//点击相应用例,显示具体用例的前提条件和期望结果
function show_detail(tid,result){
//只有在没有测试结果和没有显示结果的情况显示按钮
var is_hidden=$('#result_'+tid).is(":hidden");
if(result==0&&is_hidden){
$('#pass_'+tid).show();
$('#fail_'+tid).show();
}
$.ajax({
type: "POST",
url: "item_testcase/testimplement_manual_new_layout_casedetail.php",
data: "tcid="+tid,
success: function(msg){
$("#implement_new_casedetail").html(msg);
}
})
}
//设置此用例的判断结果
function set_result(tcid,tiid,result){
$.ajax({
type: "POST",
url: "item_testcase/testimplement_manual_new_imp_result_commit.php",
data: "trtestresult="+result+"&tiid="+tiid+"&tcid="+tcid,
success: function(msg){
if(result==1){
show_pass(tcid,tiid);
}else if(result==2){
show_fail(tcid,tiid);
}
}
})
}
//重新测试此用例
function repeat_test(tcid,tiid){
//隐藏结果,显示按钮
$('#pass_'+tcid).show();
$('#fail_'+tcid).show();
$('#result_'+tcid).hide();
$('#repeat_'+tcid).hide();
//更新数据库状态为NT
$.ajax({
type: "POST",
url: "item_testcase/testimplement_manual_new_imp_result_commit.php",
data: 'trtestresult=0&tiid='+tiid+"&tcid="+tcid,
success: function(msg){
}
})
}
function show_pass(tcid,tiid){
$('#pass_'+tcid).hide();
$('#fail_'+tcid).hide();
$('#result_'+tcid).show();
$('#result_'+tcid).html('<span style="font-size:15px">PASS</span>').css("background-color","#339900");
$('#repeat_'+tcid).show();
}
function show_fail(tcid,tiid){
$('#pass_'+tcid).hide();
$('#fail_'+tcid).hide();
$('#result_'+tcid).show();
$('#result_'+tcid).html('<span style="font-size:15px">FAIL</span>').css("background-color","#993333");
$('#repeat_'+tcid).show();
}