提交 c5085307 authored 作者: mry's avatar mry

feat(base): 新增了job接口测试

上级 463e0ba2
...@@ -39,19 +39,4 @@ public class DataBean { ...@@ -39,19 +39,4 @@ public class DataBean {
*/ */
private Integer probability; private Integer probability;
/**
* 前置行动ID组,例如:1,2,3
*/
private String moveBefore;
/**
* 后置行动ID组,例如:1,2,3
*/
private String moveAfterCase;
/**
* 测试执行后行动ID组,例如:1,2,3
*/
private String moveAfterTest;
} }
package org.matrix.testNg.web.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author MRY
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DataBeanMove {
/**
* 前置行动ID组,例如:1,2,3
*/
private String moveBefore;
/**
* 后置行动ID组,例如:1,2,3
*/
private String moveAfterCase;
/**
* 测试执行后行动ID组,例如:1,2,3
*/
private String moveAfterTest;
}
...@@ -14,5 +14,9 @@ import java.util.List; ...@@ -14,5 +14,9 @@ import java.util.List;
@NoArgsConstructor @NoArgsConstructor
public class DataBeansJobVo { public class DataBeansJobVo {
private List<DataBeansVo> dataBeansVoList; private DataBean dataBean;
private List<DataBeanMove> dataBeanMoveList;
private List<DataBeans> dataBeansList;
} }
...@@ -21,6 +21,11 @@ public class DataBeansVo { ...@@ -21,6 +21,11 @@ public class DataBeansVo {
*/ */
private DataBean dataBean; private DataBean dataBean;
/**
* 动作部分
*/
private DataBeanMove dataBeanMove;
/** /**
* 细节部分 * 细节部分
*/ */
......
...@@ -5,6 +5,7 @@ import freemarker.template.Template; ...@@ -5,6 +5,7 @@ import freemarker.template.Template;
import freemarker.template.TemplateExceptionHandler; import freemarker.template.TemplateExceptionHandler;
import org.matrix.exception.GlobalException; import org.matrix.exception.GlobalException;
import org.matrix.testNg.web.entity.DataBean; import org.matrix.testNg.web.entity.DataBean;
import org.matrix.testNg.web.entity.DataBeanMove;
import org.matrix.testNg.web.entity.DataBeans; import org.matrix.testNg.web.entity.DataBeans;
import org.matrix.testNg.web.entity.ReportMessage; import org.matrix.testNg.web.entity.ReportMessage;
import org.matrix.util.ReporterUtils; import org.matrix.util.ReporterUtils;
...@@ -34,14 +35,16 @@ public class GenerateReporter { ...@@ -34,14 +35,16 @@ public class GenerateReporter {
cfg.setClassForTemplateLoading(this.getClass(), "/templates"); cfg.setClassForTemplateLoading(this.getClass(), "/templates");
cfg.setDefaultEncoding("UTF-8"); cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
Template temp = cfg.getTemplate("overviewBeautiful.ftl"); Template temp = cfg.getTemplate("overview.ftl");
Map context = new HashMap(); Map context = new HashMap();
ReporterData reporterData = new ReporterData(); ReporterData reporterData = new ReporterData();
DataBean dataBean = reporterData.testDataBean(); DataBean dataBean = reporterData.testDataBean();
DataBeanMove dataBeanMove = reporterData.testDataBeanMove();
List<DataBeans> dataBeansList = reporterData.testDataBeans(); List<DataBeans> dataBeansList = reporterData.testDataBeans();
// 这里是公共的信息. // 这里是公共的信息.
for (DataBeans bean : dataBeansList) { for (DataBeans bean : dataBeansList) {
context.put("overView", dataBean); context.put("overView", dataBean);
context.put("move", dataBeanMove);
if (bean.getResult()) { if (bean.getResult()) {
context.put("pass", bean); context.put("pass", bean);
} else { } else {
......
package org.matrix.testNg.web.report;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateExceptionHandler;
import org.matrix.exception.GlobalException;
import org.matrix.testNg.web.entity.DataBean;
import org.matrix.testNg.web.entity.DataBeanMove;
import org.matrix.testNg.web.entity.DataBeans;
import org.matrix.testNg.web.entity.ReportMessage;
import org.matrix.util.ReporterUtils;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author MRY
*/
public class GenerateReporterJob {
private static final LocalDateTime TIME = LocalDateTime.now();
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss");
private static final String STRING = DATE_TIME_FORMATTER.format(TIME);
private static final String OUTPUT_FOLDER = System.getProperty("user.dir") + "/";
private static final String FILE_NAME = STRING + "-testNg.html";
public ReportMessage generateReport() {
try {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_28);
cfg.setClassForTemplateLoading(this.getClass(), "/templates");
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
Template temp = cfg.getTemplate("overviews.ftl");
Map context = new HashMap();
ReporterDataJob reporterDatajob = new ReporterDataJob();
DataBean dataBean = reporterDatajob.testDataBean();
List<DataBeanMove> dataBeanMoves = reporterDatajob.testDataBeanMove();
List<DataBeans> dataBeansList = reporterDatajob.testDataBeans();
// 这里是公共的信息.
for (DataBeans bean : dataBeansList) {
context.put("overView", dataBean);
for (DataBeanMove dataBeanMove : dataBeanMoves) {
context.put("move", dataBeanMove);
if (bean.getResult()) {
context.put("pass", bean);
} else {
context.put("fail", bean);
}
}
}
//文件夹不存在的话进行创建
File reportDir = new File(OUTPUT_FOLDER);
if (!reportDir.exists() && !reportDir.isDirectory()) {
reportDir.mkdir();
}
// 输出流
FileOutputStream out = new FileOutputStream(OUTPUT_FOLDER + "/" + FILE_NAME);
Writer writer = new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8));
// 转换输出
temp.process(context, writer);
writer.flush();
ReportMessage reportMessage = new ReportMessage();
reportMessage.setUrl(OUTPUT_FOLDER + "/" + FILE_NAME);
return reportMessage;
} catch (Exception e) {
throw new GlobalException(e.getMessage());
} finally {
ReporterUtils.map = new HashMap<>();
}
}
}
package org.matrix.testNg.web.report; package org.matrix.testNg.web.report;
import org.matrix.testNg.web.entity.DataBean; import org.matrix.testNg.web.entity.DataBean;
import org.matrix.testNg.web.entity.DataBeanMove;
import org.matrix.testNg.web.entity.DataBeans; import org.matrix.testNg.web.entity.DataBeans;
import org.matrix.testNg.web.entity.DataBeansVo; import org.matrix.testNg.web.entity.DataBeansVo;
import org.matrix.util.ReporterUtils; import org.matrix.util.ReporterUtils;
...@@ -43,6 +44,13 @@ public class ReporterData { ...@@ -43,6 +44,13 @@ public class ReporterData {
return dataBean; return dataBean;
} }
/**
* 动作部分
*/
public DataBeanMove testDataBeanMove() {
return ReporterUtils.map.get("dataBeansVo").getDataBeanMove();
}
/** /**
* 模板的细节部分 * 模板的细节部分
* *
......
package org.matrix.testNg.web.report; package org.matrix.testNg.web.report;
import org.matrix.testNg.web.entity.DataBean;
import org.matrix.testNg.web.entity.DataBeanMove;
import org.matrix.testNg.web.entity.DataBeans;
import org.matrix.testNg.web.entity.DataBeansJobVo;
import org.matrix.util.ReporterUtils;
import java.util.List;
/** /**
* @author MRY * @author MRY
*/ */
public class ReporterDataJob { public class ReporterDataJob {
/**
* 模板公共部分
*
* @return 补全了的所有报告信息
*/
public DataBean testDataBean() {
DataBeansJobVo dataBeansJobVo = ReporterUtils.jobMap.get("dataBeansJobVo");
int passNum = 0;
int failNum = 0;
// 测试结果汇总数据
DataBean dataBean = dataBeansJobVo.getDataBean();
List<DataBeans> dataBeanLists = dataBeansJobVo.getDataBeansList();
for (DataBeans dataBeanList : dataBeanLists) {
if (dataBeanList.getResult()) {
passNum += 1;
} else {
failNum += 1;
}
}
//成功
dataBean.setPassNum(passNum);
//失败
dataBean.setFailNum(failNum);
//总数
dataBean.setTotal(passNum + failNum);
//通过率
dataBean.setProbability(passNum / (passNum + failNum));
// TODO 时间需要处理
return dataBean;
}
/**
* 动作部分
*/
public List<DataBeanMove> testDataBeanMove() {
return ReporterUtils.jobMap.get("dataBeansJobVo").getDataBeanMoveList();
}
/**
* 模板的细节部分
*
* @return 报告中细节部分的信息
*/
public List<DataBeans> testDataBeans() {
return ReporterUtils.jobMap.get("dataBeansJobVo").getDataBeansList();
}
} }
package org.matrix.testNg.web.report; package org.matrix.testNg.web.report;
import org.matrix.testNg.web.TestNg; import org.matrix.testNg.web.TestNg;
import org.matrix.testNg.web.entity.DataBeansJobVo;
import org.matrix.testNg.web.entity.DataBeansVo; import org.matrix.testNg.web.entity.DataBeansVo;
import org.matrix.testNg.web.entity.ReportMessage; import org.matrix.testNg.web.entity.ReportMessage;
import org.matrix.util.ReporterUtils; import org.matrix.util.ReporterUtils;
...@@ -13,15 +14,25 @@ import org.springframework.stereotype.Component; ...@@ -13,15 +14,25 @@ import org.springframework.stereotype.Component;
public class TestNgImpl implements TestNg { public class TestNgImpl implements TestNg {
/** /**
* 报告生成的位置 * 单挑用例执行时,报告生成的位置
* *
* @param dataBeansVo 报告中需要的信息 * @param dataBeansVo 报告中需要的信息
* @return 报告位置信息 * @return 报告位置信息
*/ */
public ReportMessage getReportUrl(DataBeansVo dataBeansVo) { public ReportMessage getReportUrl(DataBeansVo dataBeansVo) {
ReporterUtils.map.put("dataBeansVo",dataBeansVo); ReporterUtils.map.put("dataBeansVo", dataBeansVo);
GenerateReporter generateReporter = new GenerateReporter(); GenerateReporter generateReporter = new GenerateReporter();
ReportMessage reportMessage = generateReporter.generateReport(); ReportMessage reportMessage = generateReporter.generateReport();
return reportMessage; return reportMessage;
} }
/**
* 多条用例执行时,报告生成的位置
*/
public ReportMessage getReporterUrls(DataBeansJobVo dataBeansJobVo) {
ReporterUtils.jobMap.put("dataBeansJobVo", dataBeansJobVo);
GenerateReporterJob generateReporterJob = new GenerateReporterJob();
ReportMessage reportMessage = generateReporterJob.generateReport();
return reportMessage;
}
} }
package org.matrix.util; package org.matrix.util;
import org.matrix.actuators.usecase.TestCaseExecuteResult; import org.matrix.actuators.usecase.TestCaseExecuteResult;
import org.matrix.testNg.web.entity.DataBeansJobVo;
import org.matrix.testNg.web.entity.DataBeansVo; import org.matrix.testNg.web.entity.DataBeansVo;
import java.util.HashMap; import java.util.HashMap;
...@@ -18,5 +19,6 @@ public class ReporterUtils { ...@@ -18,5 +19,6 @@ public class ReporterUtils {
public static Map<String, DataBeansVo> map = new HashMap<>(); public static Map<String, DataBeansVo> map = new HashMap<>();
public static Map<String, String> mapUrl = new HashMap<>(); public static Map<String, DataBeansJobVo> jobMap = new HashMap<>();
} }
...@@ -98,6 +98,19 @@ ...@@ -98,6 +98,19 @@
</tr> </tr>
</table> </table>
<br/><br/> <br/><br/>
<table id="moveAction" class="tabNoBorder">
<tr class="columnHeadings">
<th>前置动作</th>
<th>中置动作</th>
<th>后置动作</th>
</tr>
<tr>
<td>${move.moveBefore}</td><#--用例总数-->
<td>${move.moveAfterCase}</td><#--未执行用例数-->
<td>${move.moveAfterTest}</td><#--执行通过-->
</tr>
</table>
<br/><br/>
<h2>Detail</h2> <h2>Detail</h2>
<table class="tabNoBorder"> <table class="tabNoBorder">
<tr class="columnHeadings"> <tr class="columnHeadings">
...@@ -125,15 +138,9 @@ ...@@ -125,15 +138,9 @@
<td>${failCase.moveAfterCase!}</td><#--中间动作--> <td>${failCase.moveAfterCase!}</td><#--中间动作-->
<td>${failCase.moveAfterTest!}</td><#--后置动作--> <td>${failCase.moveAfterTest!}</td><#--后置动作-->
<td>${failCase.description!}</td><#--用例描述--> <td>${failCase.description!}</td><#--用例描述-->
<td> <td>${failCase.result}</td>
<div class="failBtn">失败</div><#--<th>执行结果</th>-->
</td>
<td>${failCase.duration!}</td><#--<th>执行时间(s)</th>--> <td>${failCase.duration!}</td><#--<th>执行时间(s)</th>-->
<td> <td>${failCase.resultMessage!}</td>
${failCase.throwable!}
</br> <#--<th>结果信息</th>-->
${failCase.resultMessage!}
</td>
</tr> </tr>
</#list> </#list>
<#list pass as passCase> <#list pass as passCase>
...@@ -147,9 +154,7 @@ ...@@ -147,9 +154,7 @@
<td>${passCase.moveAfterCase!}</td><#--中间动作--> <td>${passCase.moveAfterCase!}</td><#--中间动作-->
<td>${passCase.moveAfterTest!}</td><#--后置动作--> <td>${passCase.moveAfterTest!}</td><#--后置动作-->
<td>${passCase.description}</td><#--用例描述--> <td>${passCase.description}</td><#--用例描述-->
<td> <td>${passCase.result}</td>
<div class="successBtn">成功</div><#--执行结果-->
</td>
<td>${passCase.duration!}</td><#--执行时间(s)--> <td>${passCase.duration!}</td><#--执行时间(s)-->
<td>${passCase.resultMessage!}</td><#--结果信息--> <td>${passCase.resultMessage!}</td><#--结果信息-->
</tr> </tr>
......
<?xml version="1.0" encoding="utf-8" ?>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<meta name="description" content="TestNG unit test results."/>
<style type="text/css">
body {
margin: 10px 20px;
font-size: 14px;
font-family: "Arial", "Microsoft YaHei", "黑体", "宋体", sans-serif;
}
.successBtn {
width: 60px;
padding: 3px;
background-color: #58ab48;
border-color: #58ab48;
color: #fff;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
-khtml-border-radius: 10px;
text-align: center;
vertical-align: middle;
border: 1px solid transparent;
font-weight: 500;
}
.failBtn {
width: 60px;
padding: 3px;
background-color: #ab2e2d;
border-color: #ab2e2d;
color: #fff;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px; /* future proofing */
-khtml-border-radius: 10px; /* for old Konqueror browsers */
text-align: center;
vertical-align: middle;
border: 1px solid transparent;
font-weight: 500;
}
</style>
<style>
/* Border styles */
.tabNoBorder thead, .tabNoBorder tr {
border-top-width: 1px;
border-top-style: solid;
border-top-color: rgb(211, 202, 221);
}
.tabNoBorder {
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: rgb(211, 202, 221);
}
/* Padding and font style */
.tabNoBorder td, .tabNoBorder th {
padding: 5px 10px;
font-size: 14px;
font-family: Verdana;
color: rgb(95, 74, 121);
}
/* Alternating background colors */
.tabNoBorder tr:nth-child(even) {
background: rgb(223, 216, 232)
}
.tabNoBorder tr:nth-child(odd) {
background: #FFF
}
</style>
</head>
<body>
<br/>
<h2>Summary</h2>
<table id="summary" class="tabNoBorder">
<tr class="columnHeadings">
<th>用例总数</th>
<th>未执行用例数</th>
<th>执行通过</th>
<th>执行失败</th>
<th>跳过用例数</th>
<th>执行时间(s)</th>
<th>用例通过率</th>
</tr>
<tr>
<td>${overView.allTestsSize}</td><#--用例总数-->
<td>${overView.excludeTestsSize}</td><#--未执行用例数-->
<td>${overView.passedTestsSize}</td><#--执行通过-->
<td>${overView.failedTestsSize}</td><#--执行失败-->
<td>${overView.skippedTestsSize}</td><#--跳过用例数-->
<td>${overView.testsTime}</td><#--执行时间(s)-->
<td>${overView.passPercent}</td><#--用例通过率-->
</tr>
</table>
<br/><br/>
<h2>Detail</h2>
<table class="tabNoBorder">
<tr class="columnHeadings">
<th>前置动作</th>
<th>中置动作</th>
<th>后置动作</th>
</tr>
<#list move as moveCase>
<tr>
<td>${moveCase.moveBefore}</td><#--用例总数-->
<td>${moveCase.moveAfterCase}</td><#--未执行用例数-->
<td>${moveCase.moveAfterTest}</td><#--执行通过-->
</tr>
</#list>
<table class="aaa">
<tr class="columnHeadings">
<th>编号</th>
<th>用例名称</th>
<th>用例类型</th>
<th>详细参数</th>
<th>用例描述</th>
<th>执行结果</th>
<th>执行时间(s)</th>
<th>结果信息</th>
</tr>
<#assign caseNo = 0>
<#list fail as failCase>
<tr>
<#assign caseNo=caseNo+1>
<td>${caseNo}</td><#--编号-->
<td>${failCase.testCaseName!}</td><#--用例名称-->
<td>${failCase.type!}</td><#--用例类型-->
<td>${failCase.detail!}</td><#--详细参数-->
<td>${failCase.description!}</td><#--用例描述-->
<td>${failCase.result}</td>
<td>${failCase.duration!}</td><#--<th>执行时间(s)</th>-->
<td>${failCase.resultMessage!}</td>
</tr>
</#list>
<#list pass as passCase>
<tr>
<#assign caseNo=caseNo+1>
<td>${caseNo}</td><#--编号-->
<td>${passCase.testCaseName!}</td><#--用例名称-->
<td>${passCase.type!}</td><#--用例类型-->
<td>${passCase.detail!}</td><#--详细参数-->
<td>${passCase.description}</td><#--用例描述-->
<td>${passCase.result}</td>
<td>${passCase.duration!}</td><#--执行时间(s)-->
<td>${passCase.resultMessage!}</td><#--结果信息-->
</tr>
</#list>
</table>
</table>
</body>
</html>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论