From beecbc886f5948b2f70c2a2659ebef21ae000946 Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Tue, 29 Oct 2024 15:57:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E5=A4=9A=E4=B8=AA=E5=93=8D=E5=BA=94=E7=A0=81?= =?UTF-8?q?=E6=96=AD=E8=A8=80=EF=BC=8C=E6=96=AD=E8=A8=80=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E6=9C=89=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1046899 --user=陈建星 [接口测试]github#332222个全局断言成功+1个接口用例本身断言失败 = 最终结果为成功 https://www.tapd.cn/55049933/s/1600346 --- .../jmeter/MsCommonElementConverter.java | 35 +++++-------------- .../parser/jmeter/MsScenarioConverter.java | 11 ++++-- .../ResponseCodeAssertionConverter.java | 6 ++-- 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsCommonElementConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsCommonElementConverter.java index ae13eb5c5a..b44d27eed2 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsCommonElementConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsCommonElementConverter.java @@ -22,9 +22,7 @@ import io.metersphere.project.dto.environment.processors.ApiEnvProcessorConfig; import io.metersphere.project.dto.environment.processors.ApiEnvRequestProcessorConfig; import io.metersphere.project.dto.environment.processors.EnvProcessorConfig; import io.metersphere.project.dto.environment.processors.EnvRequestScriptProcessor; -import io.metersphere.sdk.constants.MsAssertionCondition; import org.apache.commons.lang3.BooleanUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.jorphan.collections.HashTree; import java.util.ArrayList; @@ -81,39 +79,24 @@ public class MsCommonElementConverter extends AbstractJmeterElementConverter sortAssertions = new ArrayList<>(assertions.size()); assertions.forEach(item -> { - if (item instanceof MsResponseCodeAssertion) { + if (BooleanUtils.isTrue(item.getEnable()) && item instanceof MsResponseCodeAssertion) { sortAssertions.add(item); } }); assertions.forEach(item -> { - if (!(item instanceof MsResponseCodeAssertion)) { + if (BooleanUtils.isTrue(item.getEnable()) && !(item instanceof MsResponseCodeAssertion)) { sortAssertions.add(item); } }); - sortAssertions - .forEach(assertion -> { - assertion.setProjectId(element.getProjectId()); - AssertionConverterFactory.getConverter(assertion.getClass()).parse(tree, assertion, config, isIgnoreAssertStatus(assertions)); - }); - } + for (int i = 0; i < sortAssertions.size(); i++) { + MsAssertion assertion = sortAssertions.get(i); + assertion.setProjectId(element.getProjectId()); + // 只给第一个响应码断言设置忽略状态 + boolean isIgnoreStatus = i == 0 && assertion instanceof MsResponseCodeAssertion; - /** - * 是否忽略状态码 - * - * @param assertions - * @return - */ - public static boolean isIgnoreAssertStatus(List assertions) { - boolean isIgnoreStatus = false; - for (MsAssertion assertion : assertions) { - if (assertion instanceof MsResponseCodeAssertion responseCodeAssertion) { - // 如果状态码断言添加了不校验状态码,则所有断言忽略状态码 - if (StringUtils.equals(responseCodeAssertion.getCondition(), MsAssertionCondition.UNCHECK.name())) { - isIgnoreStatus = true; - } - } + AssertionConverterFactory.getConverter(assertion.getClass()) + .parse(tree, assertion, config, isIgnoreStatus); } - return isIgnoreStatus; } private void addProcessors(HashTree tree, MsCommonElement msCommonElement, ParameterConfig config, diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsScenarioConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsScenarioConverter.java index 08f898b50c..4461825e34 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsScenarioConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsScenarioConverter.java @@ -18,6 +18,7 @@ import io.metersphere.api.parser.jmeter.processor.assertion.AssertionConverterFa import io.metersphere.plugin.api.dto.ParameterConfig; import io.metersphere.plugin.api.spi.AbstractJmeterElementConverter; import io.metersphere.project.api.assertion.MsAssertion; +import io.metersphere.project.api.assertion.MsResponseCodeAssertion; import io.metersphere.project.api.processor.MsProcessor; import io.metersphere.project.api.processor.SQLProcessor; import io.metersphere.project.dto.environment.EnvironmentConfig; @@ -241,10 +242,14 @@ public class MsScenarioConverter extends AbstractJmeterElementConverter - AssertionConverterFactory.getConverter(assertion.getClass()).parse(tree, assertion, config, ignoreAssertStatus)); + // 只给第一个响应码断言设置忽略状态 + boolean isIgnoreStatus = i == 0 && assertion instanceof MsResponseCodeAssertion; + + AssertionConverterFactory.getConverter(assertion.getClass()).parse(tree, assertion, config, isIgnoreStatus); + } } /** diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/assertion/ResponseCodeAssertionConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/assertion/ResponseCodeAssertionConverter.java index 912626813d..9729fb549c 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/assertion/ResponseCodeAssertionConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/assertion/ResponseCodeAssertionConverter.java @@ -17,18 +17,18 @@ public class ResponseCodeAssertionConverter extends AssertionConverter