This commit is contained in:
2025-03-18 08:42:06 +08:00
parent e10c58b661
commit 10fd28dc57
9 changed files with 111 additions and 155 deletions

View File

@@ -87,7 +87,6 @@ public class TestCaseController extends BaseController {
@PostMapping("/run")
public AjaxResult run(@RequestBody IDQO qo) {
log.info("执行用例 id:{}, jmeterHomePath:{}", qo.getId(), jmeterHomePath);
testCaseService.executeTestCaseById(qo.getId(), jmeterHomePath);
return toAjax(true);
return success(testCaseService.executeTestCaseById(qo.getId(), jmeterHomePath));
}
}

View File

@@ -2,6 +2,7 @@ package com.test.test.controller;
import com.test.common.core.controller.BaseController;
import com.test.common.core.domain.AjaxResult;
import com.test.test.domain.TestCaseResult;
import com.test.test.domain.qo.IDQO;
import com.test.test.service.ITestCaseResultService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -28,4 +29,11 @@ public class TestCaseResultController extends BaseController
{
return success(testCaseResultService.selectTestCaseResultById(qo.getId()));
}
@GetMapping("/list")
public AjaxResult getList(@RequestParam String sid) {
TestCaseResult testCaseResult = new TestCaseResult();
testCaseResult.setCaseSid(sid);
return success(testCaseResultService.selectTestCaseResultList(testCaseResult));
}
}

View File

@@ -0,0 +1,11 @@
package com.test.test.domain.vo;
import com.test.test.domain.TestCaseResult;
import com.test.test.domain.TestCaseStep;
import lombok.Data;
@Data
public class TestCaseResultVO {
TestCaseStep step;
TestCaseResult result;
}

View File

@@ -68,5 +68,5 @@ public interface ITestCaseService
* @param jmeterHomePath jmeter安装路径
* @return 是否成功
*/
public boolean executeTestCaseById(Long id, String jmeterHomePath);
public String executeTestCaseById(Long id, String jmeterHomePath);
}

View File

@@ -139,18 +139,18 @@ public class TaskManagerService {
try {
// 测试用例执行逻辑
log.info("Executing test case {} for task {}", testCaseId, taskId);
boolean result = testCaseService.executeTestCaseById(testCaseId, jmeterHomePath);
if (!result && retry == 0) {
String result = testCaseService.executeTestCaseById(testCaseId, jmeterHomePath);
if (result==null && retry == 0) {
if (retryCount != null && retryCount > 0) {
for (int i = 0; i < retryCount; i++) {
result = testCaseService.executeTestCaseById(testCaseId, jmeterHomePath);
if (result) {
if (result!=null) {
break;
}
}
}
}
return result;
return result!=null;
} catch (Exception e) {
log.error("Test case {} for task {} failed: ", testCaseId, taskId, e);
return false;

View File

@@ -135,11 +135,11 @@ public class TestCaseServiceImpl implements ITestCaseService
* @return 是否成功
*/
@Override
public boolean executeTestCaseById(Long id, String jmeterHomePath) {
public String executeTestCaseById(Long id, String jmeterHomePath) {
TestCase testCase = this.selectTestCaseById(id);
if (testCase == null || "2".equals(testCase.getDelFlag())) {
log.error("用例计划已被删除,不能执行!");
return false;
return null;
}
TestCaseLog testCaseLog = new TestCaseLog();
testCaseLog.setCaseId(id);
@@ -157,7 +157,7 @@ public class TestCaseServiceImpl implements ITestCaseService
testCaseLog.setOperDetail("失败");
testCaseLogMapper.insertTestCaseLog(testCaseLog);
log.error("用例步骤:{}执行失败!", testCaseStep.getName());
return false;
return null;
}
} else if (testCaseStep.getType() == 2L) {
// 数据库接口处理
@@ -166,7 +166,7 @@ public class TestCaseServiceImpl implements ITestCaseService
testCaseLog.setOperDetail("失败");
testCaseLogMapper.insertTestCaseLog(testCaseLog);
log.error("数据源用例步骤:{}执行失败!", testCaseStep.getName());
return false;
return null;
}
} else if (testCaseStep.getType() == 3L) {
// 循环节点处理
@@ -175,7 +175,7 @@ public class TestCaseServiceImpl implements ITestCaseService
testCaseLog.setOperDetail("失败");
testCaseLogMapper.insertTestCaseLog(testCaseLog);
log.error("循环用例步骤:{}执行失败!", testCaseStep.getName());
return false;
return null;
}
} else if (testCaseStep.getType() == 4L) {
// 轮询节点处理
@@ -184,7 +184,7 @@ public class TestCaseServiceImpl implements ITestCaseService
testCaseLog.setOperDetail("失败");
testCaseLogMapper.insertTestCaseLog(testCaseLog);
log.error("轮询用例步骤:{}执行失败!", testCaseStep.getName());
return false;
return null;
}
} else {
log.error("错误的用例步骤类型!");
@@ -192,7 +192,7 @@ public class TestCaseServiceImpl implements ITestCaseService
}
testCaseLog.setOperDetail("成功");
testCaseLogMapper.insertTestCaseLog(testCaseLog);
return true;
return caseSid;
}
/**