From 274c3fbd1b07a01a29685d7e155b8bd47480bb36 Mon Sep 17 00:00:00 2001 From: zhouxin Date: Mon, 17 Jul 2023 16:38:45 +0800 Subject: [PATCH] * Fix metric and add unit test. --- .../testcase_coverage_of_story_in_product.php | 8 +++--- .../testcase_coverage_of_story_in_product.php | 25 +++++++++++++++++++ .../case.yaml | 11 ++++++++ .../story.yaml | 14 +++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 module/metric/test/calc/product/scale/testcase_coverage_of_story_in_product.php create mode 100644 module/metric/test/calc/product/scale/yaml/testcase_coverage_of_story_in_product/case.yaml create mode 100644 module/metric/test/calc/product/scale/yaml/testcase_coverage_of_story_in_product/story.yaml diff --git a/module/metric/calc/product/scale/testcase_coverage_of_story_in_product.php b/module/metric/calc/product/scale/testcase_coverage_of_story_in_product.php index 81e24d2b4d..9ecaf8e809 100644 --- a/module/metric/calc/product/scale/testcase_coverage_of_story_in_product.php +++ b/module/metric/calc/product/scale/testcase_coverage_of_story_in_product.php @@ -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); } } diff --git a/module/metric/test/calc/product/scale/testcase_coverage_of_story_in_product.php b/module/metric/test/calc/product/scale/testcase_coverage_of_story_in_product.php new file mode 100644 index 0000000000..7c1fef2247 --- /dev/null +++ b/module/metric/test/calc/product/scale/testcase_coverage_of_story_in_product.php @@ -0,0 +1,25 @@ +#!/usr/bin/env php +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的已立项研发需求用例覆盖率数。 diff --git a/module/metric/test/calc/product/scale/yaml/testcase_coverage_of_story_in_product/case.yaml b/module/metric/test/calc/product/scale/yaml/testcase_coverage_of_story_in_product/case.yaml new file mode 100644 index 0000000000..7aefd0cdbf --- /dev/null +++ b/module/metric/test/calc/product/scale/yaml/testcase_coverage_of_story_in_product/case.yaml @@ -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} +... + diff --git a/module/metric/test/calc/product/scale/yaml/testcase_coverage_of_story_in_product/story.yaml b/module/metric/test/calc/product/scale/yaml/testcase_coverage_of_story_in_product/story.yaml new file mode 100644 index 0000000000..e3e4d80d29 --- /dev/null +++ b/module/metric/test/calc/product/scale/yaml/testcase_coverage_of_story_in_product/story.yaml @@ -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 +... + +