测试用例执行相关优化
This commit is contained in:
@@ -6,6 +6,7 @@ import com.test.common.core.domain.AjaxResult;
|
||||
import com.test.common.core.page.TableDataInfo;
|
||||
import com.test.common.enums.BusinessType;
|
||||
import com.test.common.utils.DateUtils;
|
||||
import com.test.common.utils.uuid.IdUtils;
|
||||
import com.test.test.domain.TestCase;
|
||||
import com.test.test.domain.qo.IDQO;
|
||||
import com.test.test.domain.qo.TestCaseListQO;
|
||||
@@ -82,16 +83,29 @@ public class TestCaseController extends BaseController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行用例
|
||||
* 异步执行用例
|
||||
*/
|
||||
@Log(title = "用例", businessType = BusinessType.OTHER)
|
||||
@PostMapping("/run")
|
||||
public AjaxResult run(@RequestBody IDQO qo) {
|
||||
log.info("执行用例 id:{}, jmeterHomePath:{}", qo.getId(), jmeterHomePath);
|
||||
String caseSid = IdUtils.simpleUUID();
|
||||
// 异步执行任务
|
||||
CompletableFuture.runAsync(() -> {
|
||||
testCaseService.executeTestCaseById(qo.getId(), jmeterHomePath);
|
||||
testCaseService.executeTestCaseById(qo.getId(), jmeterHomePath, caseSid);
|
||||
});
|
||||
return toAjax(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步执行用例
|
||||
*/
|
||||
@Log(title = "用例", businessType = BusinessType.OTHER)
|
||||
@PostMapping("/runSync")
|
||||
public AjaxResult runSync(@RequestBody IDQO qo) {
|
||||
log.info("同步执行用例 id:{}, jmeterHomePath:{}", qo.getId(), jmeterHomePath);
|
||||
String caseSid = IdUtils.simpleUUID();
|
||||
testCaseService.executeTestCaseById(qo.getId(), jmeterHomePath, caseSid);
|
||||
return AjaxResult.success("执行成功", caseSid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,8 @@ public interface ITestCaseService
|
||||
*
|
||||
* @param id 用例主键id
|
||||
* @param jmeterHomePath jmeter安装路径
|
||||
* @param caseSid 用例执行uuid
|
||||
* @return 是否成功
|
||||
*/
|
||||
public String executeTestCaseById(Long id, String jmeterHomePath);
|
||||
public String executeTestCaseById(Long id, String jmeterHomePath, String caseSid);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.test.test.service.impl;
|
||||
|
||||
import com.test.common.utils.DateUtils;
|
||||
import com.test.common.utils.uuid.IdUtils;
|
||||
import com.test.test.domain.TestTask;
|
||||
import com.test.test.domain.TestTaskCase;
|
||||
import com.test.test.domain.TestTaskResult;
|
||||
@@ -139,11 +140,12 @@ public class TaskManagerService {
|
||||
try {
|
||||
// 测试用例执行逻辑
|
||||
log.info("Executing test case {} for task {}", testCaseId, taskId);
|
||||
String result = testCaseService.executeTestCaseById(testCaseId, jmeterHomePath);
|
||||
String caseSid = IdUtils.simpleUUID();
|
||||
String result = testCaseService.executeTestCaseById(testCaseId, jmeterHomePath, caseSid);
|
||||
if (result==null && retry == 0) {
|
||||
if (retryCount != null && retryCount > 0) {
|
||||
for (int i = 0; i < retryCount; i++) {
|
||||
result = testCaseService.executeTestCaseById(testCaseId, jmeterHomePath);
|
||||
result = testCaseService.executeTestCaseById(testCaseId, jmeterHomePath, caseSid);
|
||||
if (result!=null) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import com.test.common.utils.JMeterUtil;
|
||||
import com.test.common.utils.MySQLExecutor;
|
||||
import com.test.common.utils.StringUtils;
|
||||
import com.test.common.utils.sql.TinyIntTypeAdapter;
|
||||
import com.test.common.utils.uuid.IdUtils;
|
||||
import com.test.test.domain.*;
|
||||
import com.test.test.domain.qo.*;
|
||||
import com.test.test.mapper.TestCaseLogMapper;
|
||||
@@ -132,10 +131,11 @@ public class TestCaseServiceImpl implements ITestCaseService
|
||||
*
|
||||
* @param id 用例主键id
|
||||
* @param jmeterHomePath jmeter安装路径
|
||||
* @param caseSid 用例执行uuid
|
||||
* @return 是否成功
|
||||
*/
|
||||
@Override
|
||||
public String executeTestCaseById(Long id, String jmeterHomePath) {
|
||||
public String executeTestCaseById(Long id, String jmeterHomePath, String caseSid) {
|
||||
TestCase testCase = this.selectTestCaseById(id);
|
||||
if (testCase == null || "2".equals(testCase.getDelFlag())) {
|
||||
log.error("用例计划已被删除,不能执行!");
|
||||
@@ -145,9 +145,8 @@ public class TestCaseServiceImpl implements ITestCaseService
|
||||
testCase.setContextResultMap(contextResultMap);
|
||||
TestCaseLog testCaseLog = new TestCaseLog();
|
||||
testCaseLog.setCaseId(id);
|
||||
testCaseLog.setCreateTime(DateUtils.getNowDate());
|
||||
testCaseLog.setOperTime(DateUtils.getNowDate());
|
||||
testCaseLog.setOperType("执行");
|
||||
String caseSid = IdUtils.simpleUUID();
|
||||
testCaseLog.setCaseSid(caseSid);
|
||||
testCase.setCaseSid(caseSid);
|
||||
List<TestCaseStep> testCaseStepList = testCaseStepService.selectTestCaseStepListByCaseId(id);
|
||||
@@ -632,6 +631,12 @@ public class TestCaseServiceImpl implements ITestCaseService
|
||||
} else {
|
||||
ruleResult.setResult("未通过");
|
||||
}
|
||||
} else if ("不等于".equals(fn)) {
|
||||
if (!target.equals(value)) {
|
||||
ruleResult.setResult("通过");
|
||||
} else {
|
||||
ruleResult.setResult("未通过");
|
||||
}
|
||||
} else {
|
||||
ruleResult.setResult("未通过");
|
||||
}
|
||||
|
||||
@@ -53,3 +53,13 @@ export function runCase(id) {
|
||||
data: {id}
|
||||
})
|
||||
}
|
||||
|
||||
// 同步执行用例
|
||||
export function runCaseSync(id) {
|
||||
return request({
|
||||
url: '/test/case/runSync',
|
||||
method: 'post',
|
||||
data: {id},
|
||||
timeout: 60000
|
||||
})
|
||||
}
|
||||
|
||||
@@ -178,6 +178,32 @@ export default {
|
||||
let compareName = '${' + name + '}';
|
||||
return this.extract_object.some(obj => obj.value === compareName);
|
||||
},
|
||||
handleTableEdit(e, flag, scope) {
|
||||
if (flag === "assignment") {
|
||||
if (e && this.form.assignment.length === scope.$index + 1) {
|
||||
this.form.assignment.push({
|
||||
key: "",
|
||||
value: ""
|
||||
})
|
||||
}
|
||||
}
|
||||
if (flag === "assertion") {
|
||||
if (e && this.form.assertion.length === scope.$index + 1) {
|
||||
this.form.assertion.push({
|
||||
key: "",
|
||||
value: ""
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
handleDelete(flag, scope) {
|
||||
if (flag === "assignment") {
|
||||
this.form.assignment.splice(scope.$index, 1)
|
||||
}
|
||||
if (flag === "assertion") {
|
||||
this.form.assertion.splice(scope.$index, 1)
|
||||
}
|
||||
},
|
||||
handleLogChange(val) {
|
||||
const selectedItem = this.form.testCaseResultList.find(item => item.title === val);
|
||||
if (selectedItem) {
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<script>
|
||||
import FolderPage from "@/components/FolderPage/index.vue";
|
||||
import Report from "@/views/test/case/report/index.vue";
|
||||
import {addCase, delCase, listCase, runCase} from "@/api/test/case";
|
||||
import {addCase, delCase, listCase, runCaseSync} from "@/api/test/case";
|
||||
|
||||
export default {
|
||||
name: "Case",
|
||||
@@ -89,12 +89,14 @@ export default {
|
||||
});
|
||||
},
|
||||
handleRun(id) {
|
||||
this.loading = true;
|
||||
this.$modal.confirm('是否确认执行用例?').then(function () {
|
||||
return runCase(id);
|
||||
return runCaseSync(id);
|
||||
}).then((res) => {
|
||||
this.$modal.msgSuccess("执行成功");
|
||||
this.caseSID = res.msg
|
||||
this.caseSID = res.data
|
||||
this.open = true;
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
handleRowClick(row) {
|
||||
|
||||
Reference in New Issue
Block a user