* Fix metric and add unit test.

This commit is contained in:
zhouxin
2023-07-17 16:39:06 +08:00
parent 08237e4d47
commit 274c3fbd1b
4 changed files with 55 additions and 3 deletions
@@ -26,7 +26,7 @@ class testcase_coverage_of_story_in_product extends baseCalc
public function getStatement()
{
return $this->dao->select('t1.id,t1.product,t3.id as case')->from(TABLE_STORY)->alias('t1')
return $this->dao->select('t1.id,t1.product,t3.id as caseID')->from(TABLE_STORY)->alias('t1')
->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
->leftJoin(TABLE_CASE)->alias('t3')->on('t1.id=t3.story')
->where('t1.stage')->eq('projected')
@@ -42,7 +42,7 @@ class testcase_coverage_of_story_in_product extends baseCalc
if(!isset($this->result[$row->product])) $this->result[$row->product] = array('total' => 0, 'haveCase' => 0);
$this->result[$row->product]['total'] ++;
if($row->case !== null) $this->result[$row->product]['haveCase'] ++;
if($row->caseID !== null) $this->result[$row->product]['haveCase'] ++;
$this->idList[] = $row->id;
}
@@ -54,8 +54,10 @@ class testcase_coverage_of_story_in_product extends baseCalc
{
$records[] = array(
'product' => $productID,
'rate' => $result['total'] ? $result['haveCase'] / $result['total'] : 0,
'value' => $result['total'] ? round($result['haveCase'] / $result['total'], 2) : 0,
);
}
return $this->filterByOptions($records, $options);
}
}
@@ -0,0 +1,25 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 7) . '/test/lib/init.php';
include dirname(__FILE__, 4) . '/calc.class.php';
zdTable('product')->gen(50);
zdTable('story')->config('story')->gen(50);
zdTable('case')->config('case')->gen(100);
$metric = new metricTest();
$calc = $metric->calcMetric(__FILE__);
/**
title=testcase_coverage_of_story_in_product.php
timeout=0
cid=1
*/
r($calc->getResult(array('product' => '1'))) && p('0:value') && e('0.4'); // 测试产品1的已立项研发需求用例覆盖率数。
r($calc->getResult(array('product' => '2'))) && p('0:value') && e('0.6'); // 测试产品2的已立项研发需求用例覆盖率数。
r($calc->getResult(array('product' => '3'))) && p('0:value') && e('1'); // 测试产品3的已立项研发需求用例覆盖率数。
r($calc->getResult(array('product' => '4'))) && p('0:value') && e('0'); // 测试产品4的已立项研发需求用例覆盖率数。
r($calc->getResult(array('product' => '5'))) && p('0:value') && e('0'); // 测试产品5的已立项研发需求用例覆盖率数。
@@ -0,0 +1,11 @@
---
title: zt_case
author: zhouxin
version: "1.0"
fields:
- field: id
range: 1-100
- field: story
range: 1{10},2{10},5{10},6{10},7{10},11{10},12{10},13{10},14{10},15{10}
...
@@ -0,0 +1,14 @@
---
title: zt_story
author: zhouxin
version: "1.0"
fields:
- field: id
range: 1-50
- field: product
range: 1-10{5}
- field: stage
range: projected
...