feat(接口测试): 修复资源池运行时获取不到误报断言的问题

--bug=1012864 --user=宋天阳 【接口测试】使用资源池执行用例/场景,误报没有生效
https://www.tapd.cn/55049933/s/1150702
This commit is contained in:
song-tianyang 2022-04-28 09:45:18 +08:00 committed by 刘瑞斌
parent e65ae2b4b4
commit adc19d2161
2 changed files with 7 additions and 8 deletions

View File

@ -188,7 +188,7 @@
<dependency>
<groupId>io.metersphere</groupId>
<artifactId>ms-jmeter-core</artifactId>
<version>1.1.5</version>
<version>1.1.6</version>
<exclusions>
<exclusion>
<artifactId>netty</artifactId>

View File

@ -24,12 +24,11 @@ public class ErrorReportLibraryUtil {
private static final String ERROR_REPORT_SUCCESS_MESSAGE_FLAG = " Final result is success";
public static final String ASSERTION_CONTENT_REGEX_DELIMITER = "--REGEX-->";
public static ErrorReportLibraryParseDTO parseAssertions(RequestResult result) {
ErrorReportLibraryParseDTO returnDTO = new ErrorReportLibraryParseDTO();
if (result != null && result.getResponseResult() != null && CollectionUtils.isNotEmpty(result.getResponseResult().getAssertions())) {
AssertionParserResult assertionParserResult = parserAndFormatAssertion(result.getResponseResult().getAssertions());
List<ErrorReportAssertionResult> errorReportAssertionList = assertionParserResult.errorReportAssertionList;
List<ResponseAssertionResult> errorReportAssertionList = assertionParserResult.errorReportAssertionList;
Map<String, List<ResponseAssertionResult>> successAssertionMessageMap = assertionParserResult.successAssertionMessageMap;
Map<String, List<ResponseAssertionResult>> errorAssertionMessageMap = assertionParserResult.errorAssertionMessageMap;
boolean higherThanSuccess = assertionParserResult.higherThanSuccess;
@ -52,8 +51,8 @@ public class ErrorReportLibraryUtil {
Map<String, List<ResponseAssertionResult>> passedErrorReportAssertionMap = new HashMap<>();
//过滤出没有命中的误报断言并整理出命中误报断言的数据
for (ErrorReportAssertionResult assertion : errorReportAssertionList) {
if (StringUtils.endsWith(assertion.getErrorReportMessage(), ERROR_REPORT_SUCCESS_MESSAGE_FLAG)) {
for (ResponseAssertionResult assertion : errorReportAssertionList) {
if (StringUtils.endsWith(assertion.getMessage(), ERROR_REPORT_SUCCESS_MESSAGE_FLAG)) {
String regexString = assertion.getContent();
if (passedErrorReportAssertionMap.containsKey(regexString))
passedErrorReportAssertionMap.get(regexString).add(assertion);
@ -197,7 +196,7 @@ public class ErrorReportLibraryUtil {
private static AssertionParserResult parserAndFormatAssertion(List<ResponseAssertionResult> assertions){
AssertionParserResult result = new AssertionParserResult();
for (ResponseAssertionResult assertion : assertions) {
if (assertion instanceof ErrorReportAssertionResult) {
if (assertion instanceof ErrorReportAssertionResult || StringUtils.startsWith(assertion.getName(),ERROR_REPORT_NAME_START)) {
String expression = assertion.getContent().trim();
if (StringUtils.contains(expression, ASSERTION_CONTENT_REGEX_DELIMITER)) {
String[] contentArr = expression.split(ASSERTION_CONTENT_REGEX_DELIMITER);
@ -207,7 +206,7 @@ public class ErrorReportLibraryUtil {
result.higherThanError = BooleanUtils.toBoolean(contentArr[2]);
}
}
result.errorReportAssertionList.add((ErrorReportAssertionResult) assertion);
result.errorReportAssertionList.add(assertion);
} else {
if (StringUtils.isNotEmpty(assertion.getContent())) {
String expression = assertion.getContent().trim();
@ -243,7 +242,7 @@ public class ErrorReportLibraryUtil {
class AssertionParserResult {
boolean higherThanSuccess = false;
boolean higherThanError = false;
List<ErrorReportAssertionResult> errorReportAssertionList = new ArrayList<>();
List<ResponseAssertionResult> errorReportAssertionList = new ArrayList<>();
Map<String, List<ResponseAssertionResult>> successAssertionMessageMap = new HashMap<>();
Map<String, List<ResponseAssertionResult>> errorAssertionMessageMap = new HashMap<>();
}