获取测试报告数据

This commit is contained in:
chenjianxing 2020-05-08 14:06:33 +08:00
parent 2a3b1a2036
commit cff0b05b32
14 changed files with 187 additions and 94 deletions

View File

@ -1,18 +1,13 @@
package io.metersphere.base.mapper.ext;
import io.metersphere.base.domain.TestCase;
import io.metersphere.controller.request.testcase.QueryTestCaseRequest;
import io.metersphere.controller.request.testplancase.QueryTestPlanCaseRequest;
import io.metersphere.dto.TestCaseReportMetricDTO;
import io.metersphere.dto.TestCaseReportResultDTO;
import io.metersphere.dto.TestPlanCaseDTO;
import io.metersphere.dto.TestCaseReportStatusResultDTO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ExtTestPlanTestCaseMapper {
List<TestCaseReportResultDTO> getReportMetric(@Param("planId") String planId);
List<TestCaseReportStatusResultDTO> getReportMetric(@Param("planId") String planId);
List<String> getExecutors(@Param("planId") String planId);
}

View File

@ -2,7 +2,7 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="io.metersphere.base.mapper.ext.ExtTestPlanTestCaseMapper">
<select id="getReportMetric" parameterType="java.lang.String" resultType="io.metersphere.dto.TestCaseReportResultDTO">
<select id="getReportMetric" parameterType="java.lang.String" resultType="io.metersphere.dto.TestCaseReportStatusResultDTO">
select count(t1.id) as `count`, t1.status
from test_plan_test_case t1
inner join test_case t2

View File

@ -2,6 +2,7 @@ package io.metersphere.controller;
import io.metersphere.base.domain.TestCaseReport;
import io.metersphere.controller.request.testCaseReport.CreateReportRequest;
import io.metersphere.dto.TestCaseReportMetricDTO;
import io.metersphere.service.TestCaseReportService;
import org.springframework.web.bind.annotation.*;
@ -41,7 +42,7 @@ public class TestCaseReportController {
}
@GetMapping("/get/metric/{planId}")
public TestCaseReport getMetric(@PathVariable String planId){
public TestCaseReportMetricDTO getMetric(@PathVariable String planId){
return testCaseReportService.getMetric(planId);
}
}

View File

@ -7,7 +7,7 @@ import java.util.List;
@Data
public class TestCaseReportMetricDTO {
private List<TestCaseReportResultDTO> executeResult;
private List<TestCaseReportStatusResultDTO> executeResult;
private List<TestCaseReportModuleResultDTO> moduleExecuteResult;
private List<String> executors;
private String principal;

View File

@ -4,8 +4,10 @@ import lombok.Data;
@Data
public class TestCaseReportModuleResultDTO {
private String module;
private String moduleId;
private String moduleName;
private Integer caseCount;
private Integer passRate;
private Integer passCount;
private Double passRate;
private Integer flawCount;
}

View File

@ -1,9 +1,9 @@
package io.metersphere.dto;
import lombok.Data;
@Data
public class TestCaseReportResultDTO {
public class TestCaseReportStatusResultDTO {
private String status;
private String count;
private Integer count;
}

View File

@ -51,7 +51,7 @@ public class TestCaseNodeService {
return getNodeTrees(nodes);
}
private List<TestCaseNodeDTO> getNodeTrees(List<TestCaseNode> nodes) {
public List<TestCaseNodeDTO> getNodeTrees(List<TestCaseNode> nodes) {
List<TestCaseNodeDTO> nodeTreeList = new ArrayList<>();
@ -91,12 +91,12 @@ public class TestCaseNodeService {
return nodeTree;
}
List<TestCaseNodeDTO> childrens = Optional.ofNullable(nodeTree.getChildren()).orElse(new ArrayList<>());
List<TestCaseNodeDTO> children = Optional.ofNullable(nodeTree.getChildren()).orElse(new ArrayList<>());
lowerNodes.forEach(node -> {
if (node.getParentId() != null && node.getParentId().equals(rootNode.getId())){
childrens.add(buildNodeTree(nodeLevelMap, node));
nodeTree.setChildren(childrens);
children.add(buildNodeTree(nodeLevelMap, node));
nodeTree.setChildren(children);
}
});

View File

@ -2,20 +2,21 @@ package io.metersphere.service;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtTestCaseMapper;
import io.metersphere.base.mapper.ext.ExtTestPlanMapper;
import io.metersphere.base.mapper.ext.ExtTestPlanTestCaseMapper;
import io.metersphere.commons.constants.TestPlanTestCaseStatus;
import io.metersphere.commons.utils.BeanUtils;
import io.metersphere.controller.request.testCaseReport.CreateReportRequest;
import io.metersphere.controller.request.testcase.QueryTestPlanRequest;
import io.metersphere.dto.TestCaseNodeDTO;
import io.metersphere.dto.TestCaseReportMetricDTO;
import io.metersphere.dto.TestCaseReportResultDTO;
import io.metersphere.dto.TestPlanDTO;
import io.metersphere.controller.request.testplancase.QueryTestPlanCaseRequest;
import io.metersphere.dto.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
@Service
@ -46,6 +47,9 @@ public class TestCaseReportService {
@Resource
TestPlanTestCaseMapper testPlanTestCaseMapper;
@Resource
ExtTestCaseMapper extTestCaseMapper;
public List<TestCaseReport> listTestCaseReport(TestCaseReport request) {
TestCaseReportExample example = new TestCaseReportExample();
if ( StringUtils.isNotBlank(request.getName()) ) {
@ -84,41 +88,110 @@ public class TestCaseReportService {
return report.getId();
}
public TestCaseReport getMetric(String planId) {
TestCaseReportMetricDTO testCaseReportMetricDTO = new TestCaseReportMetricDTO();
testCaseReportMetricDTO.setExecutors(extTestPlanTestCaseMapper.getExecutors(planId));
testCaseReportMetricDTO.setExecuteResult(extTestPlanTestCaseMapper.getReportMetric(planId));
public TestCaseReportMetricDTO getMetric(String planId) {
QueryTestPlanRequest queryTestPlanRequest = new QueryTestPlanRequest();
queryTestPlanRequest.setId(planId);
TestPlanDTO testPlan = extTestPlanMapper.list(queryTestPlanRequest).get(0);
testCaseReportMetricDTO.setProjectName(testPlan.getProjectName());
testCaseReportMetricDTO.setPrincipal(testPlan.getPrincipal());
TestPlanTestCaseExample example = new TestPlanTestCaseExample();
example.createCriteria().andPlanIdEqualTo(planId);
List<TestPlanTestCase> testPlanTestCases = testPlanTestCaseMapper.selectByExample(example);
Set<String> executors = new HashSet<>();
Map<String, TestCaseReportStatusResultDTO> reportStatusResultMap = new HashMap<>();
TestCaseNodeExample testCaseNodeExample = new TestCaseNodeExample();
testCaseNodeExample.createCriteria().andProjectIdEqualTo(testPlan.getProjectId());
List<TestCaseNode> nodes = testCaseNodeMapper.selectByExample(testCaseNodeExample);
return null;
List<TestCaseNodeDTO> nodeTrees = testCaseNodeService.getNodeTrees(nodes);
Map<String, Set<String>> childIdMap = new HashMap<>();
nodeTrees.forEach(item -> {
Set<String> childIds = new HashSet<>();
getChildIds(item, childIds);
childIdMap.put(item.getId(), childIds);
});
QueryTestPlanCaseRequest request = new QueryTestPlanCaseRequest();
request.setPlanId(planId);
List<TestPlanCaseDTO> testPlanTestCases = extTestCaseMapper.getTestPlanTestCases(request);
Map<String, TestCaseReportModuleResultDTO> moduleResultMap = new HashMap<>();
for (TestPlanCaseDTO testCase: testPlanTestCases) {
executors.add(testCase.getExecutor());
getStatusResultMap(reportStatusResultMap, testCase);
getModuleResultMap(childIdMap, moduleResultMap, testCase, nodeTrees);
}
nodeTrees.forEach(rootNode -> {
TestCaseReportModuleResultDTO moduleResult = moduleResultMap.get(rootNode.getId());
if (moduleResult != null) {
moduleResult.setModuleName(rootNode.getName());
}
});
for (TestCaseReportModuleResultDTO moduleResult : moduleResultMap.values()) {
moduleResult.setPassRate(new BigDecimal(moduleResult.getPassCount()*1.0f/moduleResult.getCaseCount())
.setScale(2, BigDecimal.ROUND_HALF_UP)
.doubleValue() * 100);
if (moduleResult.getCaseCount() <= 0) {
moduleResultMap.remove(moduleResult.getModuleId());
}
}
TestCaseReportMetricDTO testCaseReportMetricDTO = new TestCaseReportMetricDTO();
testCaseReportMetricDTO.setProjectName(testPlan.getProjectName());
testCaseReportMetricDTO.setPrincipal(testPlan.getPrincipal());
testCaseReportMetricDTO.setExecutors(new ArrayList<>(executors));
testCaseReportMetricDTO.setExecuteResult(new ArrayList<>(reportStatusResultMap.values()));
testCaseReportMetricDTO.setModuleExecuteResult(new ArrayList<>(moduleResultMap.values()));
return testCaseReportMetricDTO;
}
private TestCaseReport get(List<TestCaseNode> nodes) {
// List<TestCaseNode> rootNode = new ArrayList<>();
// Map<String, List<String>> nodeMap = new HashMap<>();
// nodes.forEach(node -> {
// Integer level = node.getLevel();
// if (level == 1) {
// rootNode.add(node);
// ArrayList<Object> objects = new ArrayList<>();
// }
// });
return null;
private void getStatusResultMap(Map<String, TestCaseReportStatusResultDTO> reportStatusResultMap, TestPlanCaseDTO testCase) {
TestCaseReportStatusResultDTO statusResult = reportStatusResultMap.get(testCase.getStatus());
if (statusResult == null) {
statusResult = new TestCaseReportStatusResultDTO();
statusResult.setStatus(testCase.getStatus());
statusResult.setCount(0);
}
statusResult.setCount(statusResult.getCount() + 1);
reportStatusResultMap.put(testCase.getStatus(), statusResult);
}
private void getModuleResultMap(Map<String, Set<String>> childIdMap, Map<String, TestCaseReportModuleResultDTO> moduleResultMap, TestPlanCaseDTO testCase, List<TestCaseNodeDTO> nodeTrees) {
childIdMap.forEach((rootNodeId, childIds) -> {
if (childIds.contains(testCase.getNodeId())) {
TestCaseReportModuleResultDTO moduleResult = moduleResultMap.get(rootNodeId);
if (moduleResult == null) {
moduleResult = new TestCaseReportModuleResultDTO();
moduleResult.setCaseCount(0);
moduleResult.setPassCount(0);
moduleResult.setModuleId(rootNodeId);
}
moduleResult.setCaseCount(moduleResult.getCaseCount() + 1);
if (StringUtils.equals(testCase.getStatus(), TestPlanTestCaseStatus.Pass.name())) {
moduleResult.setPassCount(moduleResult.getPassCount() + 1);
}
moduleResultMap.put(rootNodeId, moduleResult);
return;
}
});
}
private void getChildIds(TestCaseNodeDTO rootNode, Set<String> childIds) {
childIds.add(rootNode.getId());
List<TestCaseNodeDTO> children = rootNode.getChildren();
if(children != null) {
Iterator<TestCaseNodeDTO> iterator = children.iterator();
while(iterator.hasNext()){
getChildIds(iterator.next(), childIds);
}
}
}
}

View File

@ -8,7 +8,7 @@
<el-row type="flex" justify="space-between">
<el-col :span="12">
<span>所属项目</span>
<span class="item-value">{{reportInfo.project}}</span>
<span class="item-value">{{reportInfo.projectName}}</span>
</el-col>
<el-col :span="12">
<span>测试负责人</span>
@ -54,7 +54,7 @@
type: Object,
default() {
return {
project: '项目名称',
projectName: '项目名称',
principal: '由丽媛',
executors: ['由丽媛','王振','陈建星'],
startTime: '2020-6-18',

View File

@ -4,7 +4,7 @@
<template>
<ms-pie-chart :text="'测试结果统计图'" :name="'测试结果'" :data="charData"/>
<ms-pie-chart v-if="isShow" :text="'测试结果统计图'" :name="'测试结果'" :data="charData"/>
</template>
@ -21,38 +21,48 @@
components: {MsPieChart, CommonComponent},
data() {
return {
charData: [
{
value:235, name:'通过',
itemStyle: {
color: '#67C23A'
}
},
{
value:274, name:'阻塞',
itemStyle: {
color: '#E6A23C'
}
},
{
value:310, name:'失败',
itemStyle: {
color: '#F56C6C'
}
},
{
value:335, name:'跳过',
itemStyle: {
color: '#909399'
}
},
{
value:400, name:'未完成',
itemStyle: {
color: 'lightskyblue'
}
}
]
dataMap: new Map([
["Pass", {value:235, name:'通过', itemStyle: {color: '#67C23A'}}],
["Blocking", {value:274, name:'阻塞', itemStyle: {color: '#E6A23C'}}],
["Skip", {value:335, name:'跳过', itemStyle: {color: '#909399'}}],
["Prepare", {value:265, name:'未开始', itemStyle: {color: '#DEDE10'}}],
["Failure", {value:310, name:'失败', itemStyle: {color: '#F56C6C'}}],
["Underway", {value:245, name:'进行中', itemStyle: {color: 'lightskyblue'}}]
]),
charData: [],
isShow: true
}
},
props: {
executeResult: {
type: Array
}
},
watch: {
executeResult() {
this.charData = [];
this.executeResult.forEach(item => {
let data = this.dataMap.get(item.status);
data.value = item.count;
this.charData.push(data);
});
this.reload();
}
},
created() {
this.charData.push(this.dataMap.get('Pass'));
this.charData.push(this.dataMap.get('Blocking'));
this.charData.push(this.dataMap.get('Skip'));
this.charData.push(this.dataMap.get('Prepare'));
this.charData.push(this.dataMap.get('Failure'));
this.charData.push(this.dataMap.get('Underway'));
},
methods: {
reload() {
this.isShow = false;
this.$nextTick(function () {
this.isShow = true;
})
}
}
}

View File

@ -1,14 +1,13 @@
<template>
<common-component :title="'测试结果'">
<template>
<el-table
:data="testResults"
stripe
style="width: 100%">
<el-table-column
prop="module"
prop="moduleName"
:label="'模块'"
width="180">
</el-table-column>
@ -20,6 +19,9 @@
<el-table-column
prop="passRate"
:label="'通过率'">
<template v-slot:default="scope">
{{scope.row.passRate}}%
</template>
</el-table-column>
<el-table-column
prop="flawCount"
@ -37,29 +39,25 @@
export default {
name: "TestResultComponent",
components: {CommonComponent},
data() {
return {
}
},
props: {
testResults: {
type: Array,
default() {
return [
{
module: '模块1',
moduleName: '模块1',
caseCount: '14',
passRate: 10.8,
flawCount: 3
},
{
module: '模块2',
moduleName: '模块2',
caseCount: '24',
passRate: 40,
flawCount: 6
},
{
module: '模块3',
moduleName: '模块3',
caseCount: '50',
passRate: 76.9,
flawCount: 8

View File

@ -108,7 +108,7 @@
this.isRouterAlive = false;
this.$nextTick(function () {
this.isRouterAlive = true;
})
});
}
}
}

View File

@ -26,9 +26,9 @@
<div class="container">
<el-main>
<div class="preview" v-for="item in previews" :key="item.id">
<base-info-component v-if="item.id == 1"/>
<test-result-component v-if="item.id == 2"/>
<test-result-chart-component v-if="item.id == 3"/>
<base-info-component :report-info="metric" v-if="item.id == 1"/>
<test-result-component :test-results="metric.moduleExecuteResult" v-if="item.id == 2"/>
<test-result-chart-component :execute-result="metric.executeResult" v-if="item.id == 3"/>
<rich-text-component :preview="item" v-if="item.type != 'system'"/>
</div>
</el-main>
@ -61,6 +61,7 @@
previews: [],
report: {},
reportId: '',
metric: {},
componentMap: new Map(
[
[1, { name: "基础信息", id: 1 , type: 'system'}],
@ -71,6 +72,11 @@
)
}
},
props: {
planId: {
type: String
}
},
methods: {
open(id) {
if (id) {
@ -86,6 +92,7 @@
if (this.report.content.customComponent) {
this.report.content.customComponent = jsonToMap(this.report.content.customComponent);
}
this.getMetric();
this.initPreviews();
});
},
@ -110,6 +117,13 @@
},
handleEdit() {
this.$refs.templateEdit.open(this.reportId, true);
},
getMetric() {
this.result = this.$get('/case/report/get/metric/' + this.planId, response => {
this.metric = response.data;
this.metric.startTime = this.report.startTime;
this.metric.endTime = this.report.endTime;
});
}
}
}

View File

@ -109,7 +109,7 @@
@refreshTable="search"/>
<test-report-template-list @openReport="openReport" :plan-id="planId" ref="testReporTtemplateList"/>
<test-case-report-view ref="testCaseReportView"/>
<test-case-report-view :plan-id="planId" ref="testCaseReportView"/>
</el-card>
</template>