fix:测试计划新建报告及报告详情显示

This commit is contained in:
pfl
2025-06-25 13:50:21 +08:00
parent ef4d51876f
commit ef741fcb64
11 changed files with 138 additions and 8 deletions

View File

@@ -29,6 +29,14 @@ public class TestCaseLog extends BaseEntity
@Excel(name = "用例id") @Excel(name = "用例id")
private Long caseId; private Long caseId;
/** 测试计划id */
@Excel(name = "测试计划id")
private Long planId;
/** 测试计划关联用例类型 */
@Excel(name = "测试计划关联用例类型")
private Integer type;
/** 操作类别 */ /** 操作类别 */
@Excel(name = "操作类别") @Excel(name = "操作类别")
private String operType; private String operType;

View File

@@ -0,0 +1,18 @@
package com.test.test.domain.vo;
import java.io.Serializable;
import lombok.Data;
@Data
public class TestCaseReportVO implements Serializable {
private static final long serialVersionUID = 6972995415807958849L;
private String name;
private String result;
private Integer caseNum;
private Integer passNum;
}

View File

@@ -17,6 +17,9 @@ public class TestReportVo extends BaseEntity {
/** 测试结果(0,未通过,1,通过) */ /** 测试结果(0,未通过,1,通过) */
private String result; private String result;
/** 测试报告jason格式存储*/
private String report;
/** 测试用例类型(0,冒烟测试,1,功能测试,2,回归测试,3,准生产测试,4,生产验证) */ /** 测试用例类型(0,冒烟测试,1,功能测试,2,回归测试,3,准生产测试,4,生产验证) */
private Long type; private Long type;

View File

@@ -2,6 +2,7 @@ package com.test.test.mapper;
import com.test.test.domain.TestCaseLog; import com.test.test.domain.TestCaseLog;
import com.test.test.domain.qo.TestReportAddQO;
import java.util.List; import java.util.List;
/** /**
@@ -28,6 +29,14 @@ public interface TestCaseLogMapper
*/ */
public List<TestCaseLog> selectTestCaseLogList(TestCaseLog testCaseLog); public List<TestCaseLog> selectTestCaseLogList(TestCaseLog testCaseLog);
/**
* 查询用例日志列表
*
* @param testCaseLog 用例日志
* @return 用例日志集合
*/
public String selectTestCaseLogCaseSid(TestReportAddQO testCaseLog);
/** /**
* 新增用例日志 * 新增用例日志
* *

View File

@@ -1,5 +1,6 @@
package com.test.test.service; package com.test.test.service;
import com.test.common.core.domain.AjaxResult;
import com.test.test.domain.TestReport; import com.test.test.domain.TestReport;
import com.test.test.domain.qo.TestReportAddQO; import com.test.test.domain.qo.TestReportAddQO;
import com.test.test.domain.vo.TestReportVo; import com.test.test.domain.vo.TestReportVo;

View File

@@ -236,6 +236,8 @@ public class TestCaseServiceImpl implements ITestCaseService
testCase.setContextResultMap(contextResultMap); testCase.setContextResultMap(contextResultMap);
TestCaseLog testCaseLog = new TestCaseLog(); TestCaseLog testCaseLog = new TestCaseLog();
testCaseLog.setCaseId(id); testCaseLog.setCaseId(id);
testCaseLog.setPlanId(testPlanCase.getPlanId());
testCaseLog.setType(testPlanCase.getType());
testCaseLog.setOperTime(DateUtils.getNowDate()); testCaseLog.setOperTime(DateUtils.getNowDate());
testCaseLog.setOperType("执行"); testCaseLog.setOperType("执行");
testCaseLog.setCaseSid(caseSid); testCaseLog.setCaseSid(caseSid);

View File

@@ -1,11 +1,18 @@
package com.test.test.service.impl; package com.test.test.service.impl;
import com.alibaba.fastjson2.JSONObject;
import com.test.common.core.domain.AjaxResult;
import com.test.common.utils.DateUtils; import com.test.common.utils.DateUtils;
import com.test.common.utils.SecurityUtils; import com.test.common.utils.SecurityUtils;
import com.test.common.utils.StringUtils;
import com.test.common.utils.bean.BeanUtils; import com.test.common.utils.bean.BeanUtils;
import com.test.test.domain.TestCaseResult;
import com.test.test.domain.TestReport; import com.test.test.domain.TestReport;
import com.test.test.domain.qo.TestReportAddQO; import com.test.test.domain.qo.TestReportAddQO;
import com.test.test.domain.vo.TestCaseReportVO;
import com.test.test.domain.vo.TestReportVo; import com.test.test.domain.vo.TestReportVo;
import com.test.test.mapper.TestCaseLogMapper;
import com.test.test.mapper.TestCaseResultMapper;
import com.test.test.mapper.TestPlanReportMapper; import com.test.test.mapper.TestPlanReportMapper;
import com.test.test.mapper.TestReportMapper; import com.test.test.mapper.TestReportMapper;
import com.test.test.service.ITestReportService; import com.test.test.service.ITestReportService;
@@ -29,6 +36,12 @@ public class TestReportServiceImpl implements ITestReportService {
@Resource @Resource
private TestPlanReportMapper testPlanReportMapper; private TestPlanReportMapper testPlanReportMapper;
@Resource
private TestCaseLogMapper testCaseLogMapper;
@Resource
private TestCaseResultMapper testCaseResultMapper;
/** /**
* 查询测试报告列表 * 查询测试报告列表
* @param planId * @param planId
@@ -46,11 +59,27 @@ public class TestReportServiceImpl implements ITestReportService {
*/ */
@Override @Override
public int addTestReport(TestReportAddQO testReportAddQO) { public int addTestReport(TestReportAddQO testReportAddQO) {
String caseSid = testCaseLogMapper.selectTestCaseLogCaseSid(testReportAddQO);
if (StringUtils.isEmpty(caseSid)) {
throw new RuntimeException("未执行用例,无法生成报告");
}
TestCaseResult testCaseResult = new TestCaseResult();
testCaseResult.setCaseSid(caseSid);
List<TestCaseResult> testCaseResults = testCaseResultMapper.selectTestCaseResultList(testCaseResult);
int count = testCaseResults.size();
int passNum = (int)testCaseResults.stream().filter(result -> "成功".equals(result.getStatus())).count();
TestCaseReportVO testCaseReportVO = new TestCaseReportVO();
testCaseReportVO.setName(testReportAddQO.getName());
testCaseReportVO.setResult("success");
testCaseReportVO.setCaseNum(count);
testCaseReportVO.setPassNum(passNum);
String reportJson = JSONObject.toJSONString(testCaseReportVO);
TestReport testReport = new TestReport(); TestReport testReport = new TestReport();
BeanUtils.copyProperties(testReportAddQO,testReport); BeanUtils.copyProperties(testReportAddQO,testReport);
testReport.setSerialNumber(generateSerialNumber()); testReport.setSerialNumber(generateSerialNumber());
testReport.setResult("0"); testReport.setResult("1");
testReport.setStatus("0"); testReport.setStatus("0");
testReport.setReport(reportJson);
testReport.setCreateTime(DateUtils.getNowDate()); testReport.setCreateTime(DateUtils.getNowDate());
testReport.setDelFlag("0"); testReport.setDelFlag("0");
testReport.setUpdateBy(SecurityUtils.getUsername()); testReport.setUpdateBy(SecurityUtils.getUsername());

View File

@@ -36,10 +36,21 @@
where id = #{id} where id = #{id}
</select> </select>
<select id="selectTestCaseLogCaseSid" resultType="java.lang.String">
SELECT case_sid
FROM test_case_log
WHERE plan_id = #{planId}
AND type = #{type}
ORDER BY id
DESC limit 1
</select>
<insert id="insertTestCaseLog" parameterType="TestCaseLog" useGeneratedKeys="true" keyProperty="id"> <insert id="insertTestCaseLog" parameterType="TestCaseLog" useGeneratedKeys="true" keyProperty="id">
insert into test_case_log insert into test_case_log
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="caseId != null">case_id,</if> <if test="caseId != null">case_id,</if>
<if test="planId != null">plan_id,</if>
<if test="type != null">type,</if>
<if test="operType != null">oper_type,</if> <if test="operType != null">oper_type,</if>
<if test="operDetail != null">oper_detail,</if> <if test="operDetail != null">oper_detail,</if>
<if test="operUser != null">oper_user,</if> <if test="operUser != null">oper_user,</if>
@@ -48,6 +59,8 @@
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="caseId != null">#{caseId},</if> <if test="caseId != null">#{caseId},</if>
<if test="planId != null">#{planId},</if>
<if test="type != null">#{type},</if>
<if test="operType != null">#{operType},</if> <if test="operType != null">#{operType},</if>
<if test="operDetail != null">#{operDetail},</if> <if test="operDetail != null">#{operDetail},</if>
<if test="operUser != null">#{operUser},</if> <if test="operUser != null">#{operUser},</if>

View File

@@ -35,6 +35,7 @@
SELECT SELECT
tr.name AS name, tr.name AS name,
tr.result AS result, tr.result AS result,
tr.report AS report,
tr.status AS status, tr.status AS status,
tpr.type AS type, tpr.type AS type,
tr.create_time AS createTime, tr.create_time AS createTime,

View File

@@ -111,6 +111,7 @@ export default {
name: row.name, name: row.name,
type: row.result, type: row.result,
planId: row.planId, planId: row.planId,
report: row.report
} }
) )
}, },

View File

@@ -31,12 +31,14 @@
<div class="report-overview"> <div class="report-overview">
<div class="overview-item"> <div class="overview-item">
<div class="value">1</div> <div class="value">{{ reportData.caseNum }}</div>
<span class="label">执行用例数</span> <span class="label">执行用例数</span>
</div> </div>
<div class="overview-item"> <div class="overview-item">
<span class="value">100%</span> <span class="value">{{ passRate }}%</span>
<div class="progress-bar"></div> <div class="progress-bar-container">
<div class="progress-bar" :style="{ width: passRate + '%' }"></div>
</div>
<div class="label">用例通过率</div> <div class="label">用例通过率</div>
</div> </div>
<div class="overview-item"> <div class="overview-item">
@@ -85,6 +87,7 @@ export default {
return { return {
reportType: '', reportType: '',
reportTitle: '', reportTitle: '',
reportData: {},
selectedResult: '', // 选择的测试结果 selectedResult: '', // 选择的测试结果
resultOptions: [ // 测试结果选项 resultOptions: [ // 测试结果选项
{ value: 'all', label: '全部' }, { value: 'all', label: '全部' },
@@ -106,7 +109,7 @@ export default {
// 用例类型分布数据 // 用例类型分布数据
caseTypeDistributionData: { caseTypeDistributionData: {
series: [ series: [
{ value: 1, name: '接口用例' ,itemStyle: {color: '#6fcdac'} } { value: 0, name: '接口用例' ,itemStyle: {color: '#6fcdac'} }
] ]
} }
}; };
@@ -114,6 +117,14 @@ export default {
created() { created() {
this.reportTitle = this.$route.query.name; this.reportTitle = this.$route.query.name;
this.reportType = this.$route.query.type; this.reportType = this.$route.query.type;
this.reportData = JSON.parse(this.$route.query.report);
// 更新饼图数据
this.resultDistributionData.series[0].value = this.reportData.passNum || 0;
this.resultDistributionData.series[1].value = this.reportData.caseNum - this.reportData.passNum || 0;
// 更新接口用例饼图数据
this.caseTypeDistributionData.series[0].value = this.reportData.caseNum || 0;
}, },
watch: { watch: {
'dict.type.test_type': { 'dict.type.test_type': {
@@ -127,11 +138,29 @@ export default {
} }
}, },
computed: { computed: {
passRate() {
if (this.reportData.caseNum === 0) return 0;
return (this.reportData.passNum / this.reportData.caseNum) * 100;
}
}, },
mounted() { mounted() {
this.initResultDistributionChart(); this.initResultDistributionChart();
this.initCaseTypeDistributionChart(); this.initCaseTypeDistributionChart();
// 强制重绘图表以应用最新数据
this.$nextTick(() => {
const chartDom = document.getElementById('result-distribution-chart');
if (chartDom) {
const myChart = echarts.getInstanceByDom(chartDom);
myChart.setOption({
series: [{
type: 'pie',
data: this.resultDistributionData.series
}]
}, true); // true 表示合并选项
}
});
}, },
methods: { methods: {
initResultDistributionChart() { initResultDistributionChart() {
@@ -268,13 +297,29 @@ export default {
font-size: 14px; font-size: 14px;
} }
.progress-bar { .progress-bar-container {
width: 100px; width: 100px;
height: 10px; height: 10px;
background-color: white; background-color: #e0e0e0; /* 背景颜色表示未完成部分 */
border-radius: 5px;
overflow: hidden;
margin-top: 10px; margin-top: 10px;
}
.progress-bar {
height: 100%;
background-color: white; /* 进度条颜色 */
border-radius: 5px; border-radius: 5px;
} }
//.progress-bar {
// width: 100px;
// height: 10px;
// background-color: white;
// margin-top: 10px;
// border-radius: 5px;
//}
} }
} }
} }