feat(接口测试): 修复启用误报导致失败停止功能失效的问题
--bug=1011393 --user=宋天阳 【接口测试】场景测试,开启误报库后,不开启失败继续,遇到误报就停止了 https://www.tapd.cn/55049933/s/1121190
This commit is contained in:
parent
a3aedf20ca
commit
3d77866d42
|
@ -1,5 +1,6 @@
|
|||
package io.metersphere.api.dto;
|
||||
|
||||
import io.metersphere.dto.RequestResult;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
@ -12,6 +13,7 @@ import java.util.List;
|
|||
@Setter
|
||||
public class ErrorReportLibraryParseDTO {
|
||||
public List<String> errorCodeList;
|
||||
public RequestResult result;
|
||||
|
||||
public ErrorReportLibraryParseDTO() {
|
||||
this.errorCodeList = new ArrayList<>();
|
||||
|
|
|
@ -11,6 +11,7 @@ public class MsAssertionRegex extends MsAssertionType {
|
|||
private String expression;
|
||||
private String description;
|
||||
private boolean assumeSuccess;
|
||||
private int testType = 2;
|
||||
|
||||
public MsAssertionRegex() {
|
||||
setType(MsAssertionType.REGEX);
|
||||
|
|
|
@ -112,6 +112,10 @@ public class MsAssertions extends MsTestElement {
|
|||
assertion.setAssumeSuccess(assertionRegex.isAssumeSuccess());
|
||||
assertion.addTestString(assertionRegex.getExpression());
|
||||
assertion.setToContainsType();
|
||||
if(assertionRegex.getTestType() != 2){
|
||||
assertion.setProperty("Assertion.test_type",assertionRegex.getTestType());
|
||||
}
|
||||
|
||||
switch (assertionRegex.getSubject()) {
|
||||
case "Response Code":
|
||||
assertion.setTestFieldResponseCode();
|
||||
|
|
|
@ -64,10 +64,11 @@ public class ApiScenarioReportResultService {
|
|||
}
|
||||
}
|
||||
|
||||
private ApiScenarioReportResult newApiScenarioReportResult(String reportId, RequestResult result) {
|
||||
private ApiScenarioReportResult newApiScenarioReportResult(String reportId, RequestResult baseResult) {
|
||||
ApiScenarioReportResult report = new ApiScenarioReportResult();
|
||||
//解析误报内容
|
||||
ErrorReportLibraryParseDTO errorCodeDTO = ErrorReportLibraryUtil.parseAssertions(result);
|
||||
ErrorReportLibraryParseDTO errorCodeDTO = ErrorReportLibraryUtil.parseAssertions(baseResult);
|
||||
RequestResult result = errorCodeDTO.getResult();
|
||||
report.setId(UUID.randomUUID().toString());
|
||||
String resourceId = result.getResourceId();
|
||||
report.setResourceId(resourceId);
|
||||
|
|
|
@ -35,7 +35,9 @@ public class ExtErrorReportLibraryService {
|
|||
try {
|
||||
MsAssertions assertions = JSONObject.parseObject(item.getContent(), MsAssertions.class);
|
||||
if (assertions != null && CollectionUtils.isNotEmpty(assertions.getRegex())) {
|
||||
assertions.getRegex().get(0).setDescription("Error report:" + item.getErrorCode());
|
||||
//误报的断言要设置取反
|
||||
assertions.getRegex().get(0).setTestType(6);
|
||||
assertions.getRegex().get(0).setDescription("Check Error report:" + item.getErrorCode());
|
||||
returnList.add(assertions);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -14,29 +14,26 @@ import java.util.List;
|
|||
*/
|
||||
public class ErrorReportLibraryUtil {
|
||||
|
||||
private static final String ERROR_CODE_START = "Error report:";
|
||||
|
||||
private static final String NEW_ERROR_CODE_STATE = "Check Error report:";
|
||||
|
||||
public static ErrorReportLibraryParseDTO parseAssertions(RequestResult result) {
|
||||
ErrorReportLibraryParseDTO returnDTO = new ErrorReportLibraryParseDTO();
|
||||
if (result != null && result.getResponseResult() != null && CollectionUtils.isNotEmpty(result.getResponseResult().getAssertions())) {
|
||||
List<ResponseAssertionResult> errorReportAssertionList = new ArrayList<>();
|
||||
boolean hasOtherErrorAssertion = false;
|
||||
int otherAssertionCount = 0;
|
||||
for (ResponseAssertionResult assertion : result.getResponseResult().getAssertions()) {
|
||||
if (StringUtils.startsWith(assertion.getContent(), ERROR_CODE_START)) {
|
||||
if (StringUtils.startsWithAny(assertion.getContent(), NEW_ERROR_CODE_STATE)) {
|
||||
errorReportAssertionList.add(assertion);
|
||||
}else {
|
||||
otherAssertionCount ++;
|
||||
if(!assertion.isPass()){
|
||||
hasOtherErrorAssertion = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(errorReportAssertionList)) {
|
||||
List<ResponseAssertionResult> unMatchErrorReportAssertions = new ArrayList<>();
|
||||
int machedErrorPortAssertions = 0;
|
||||
for (ResponseAssertionResult assertion : errorReportAssertionList) {
|
||||
if (assertion.isPass()) {
|
||||
String errorCode = StringUtils.substring(assertion.getContent(), ERROR_CODE_START.length());
|
||||
if (!assertion.isPass()) {
|
||||
assertion.setPass(true);
|
||||
machedErrorPortAssertions ++;
|
||||
String errorCode = StringUtils.substring(assertion.getContent(), NEW_ERROR_CODE_STATE.length());
|
||||
returnDTO.getErrorCodeList().add(errorCode);
|
||||
} else {
|
||||
unMatchErrorReportAssertions.add(assertion);
|
||||
|
@ -45,21 +42,19 @@ public class ErrorReportLibraryUtil {
|
|||
|
||||
if (CollectionUtils.isNotEmpty(unMatchErrorReportAssertions)) {
|
||||
// 未被误报断言匹配到的结果,清除该请求的误报断言记录,并将断言涉及到的统计结果恢复正常
|
||||
if (result.getResponseResult() != null
|
||||
&& StringUtils.equalsIgnoreCase(result.getResponseResult().getResponseCode(), "200")
|
||||
&& result.getError() > 0) {
|
||||
if(otherAssertionCount == 0 || !hasOtherErrorAssertion){
|
||||
result.setError(result.getError() - 1);
|
||||
}
|
||||
}
|
||||
result.setTotalAssertions(result.getTotalAssertions() - unMatchErrorReportAssertions.size());
|
||||
int passAssertionCountg = (result.getPassAssertions() - unMatchErrorReportAssertions.size() ) + machedErrorPortAssertions;
|
||||
if(passAssertionCountg< 0){
|
||||
result.setPassAssertions(0);
|
||||
}else {
|
||||
result.setPassAssertions(passAssertionCountg);
|
||||
}
|
||||
|
||||
result.getResponseResult().getAssertions().removeAll(unMatchErrorReportAssertions);
|
||||
if (result.getError() == 0 && !result.isSuccess()) {
|
||||
result.setSuccess(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
returnDTO.setResult(result);
|
||||
return returnDTO;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,10 +14,10 @@ import java.util.Map;
|
|||
*/
|
||||
public class ResponseUtil {
|
||||
|
||||
public static RequestResultExpandDTO parseByRequestResult(RequestResult requestResult) {
|
||||
public static RequestResultExpandDTO parseByRequestResult(RequestResult baseResult) {
|
||||
//解析是否含有误报库信息
|
||||
ErrorReportLibraryParseDTO errorCodeDTO = ErrorReportLibraryUtil.parseAssertions(requestResult);
|
||||
|
||||
ErrorReportLibraryParseDTO errorCodeDTO = ErrorReportLibraryUtil.parseAssertions(baseResult);
|
||||
RequestResult requestResult = errorCodeDTO.getResult();
|
||||
RequestResultExpandDTO expandDTO = new RequestResultExpandDTO();
|
||||
BeanUtils.copyBean(expandDTO, requestResult);
|
||||
|
||||
|
|
Loading…
Reference in New Issue