fix(接口测试): 修复While循环内计数器多计数一次的问题

【while循环控制器,当变量小于判断条件时,也会执行】https://www.tapd.cn/33805590/bugtrace/bugs/view?bug_id=1133805590001008502
This commit is contained in:
fit2-zhao 2021-12-07 12:37:01 +08:00 committed by fit2-zhao
parent cd350e217e
commit adc73158fa
3 changed files with 8 additions and 4 deletions

View File

@ -111,7 +111,7 @@ public class ElementUtil {
} }
} }
public static void addCounter(HashTree tree, List<ScenarioVariable> variables) { public static void addCounter(HashTree tree, List<ScenarioVariable> variables, boolean isInternal) {
if (CollectionUtils.isNotEmpty(variables)) { if (CollectionUtils.isNotEmpty(variables)) {
List<ScenarioVariable> list = variables.stream().filter(ScenarioVariable::isCounterValid).collect(Collectors.toList()); List<ScenarioVariable> list = variables.stream().filter(ScenarioVariable::isCounterValid).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(list)) { if (CollectionUtils.isNotEmpty(list)) {
@ -121,7 +121,11 @@ public class ElementUtil {
counterConfig.setProperty(TestElement.TEST_CLASS, CounterConfig.class.getName()); counterConfig.setProperty(TestElement.TEST_CLASS, CounterConfig.class.getName());
counterConfig.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("CounterConfigGui")); counterConfig.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("CounterConfigGui"));
counterConfig.setName(item.getName()); counterConfig.setName(item.getName());
if (isInternal) {
counterConfig.setStart((item.getStartNumber() + 1));
} else {
counterConfig.setStart(item.getStartNumber()); counterConfig.setStart(item.getStartNumber());
}
counterConfig.setEnd(item.getEndNumber()); counterConfig.setEnd(item.getEndNumber());
counterConfig.setVarName(item.getName()); counterConfig.setVarName(item.getName());
counterConfig.setIncrement(item.getIncrement()); counterConfig.setIncrement(item.getIncrement());

View File

@ -162,7 +162,7 @@ public class MsScenario extends MsTestElement {
tree.add(ParameterConfig.valueSupposeMock(arguments)); tree.add(ParameterConfig.valueSupposeMock(arguments));
} }
ElementUtil.addCsvDataSet(tree, variables, config, "shareMode.group"); ElementUtil.addCsvDataSet(tree, variables, config, "shareMode.group");
ElementUtil.addCounter(tree, variables); ElementUtil.addCounter(tree, variables, false);
ElementUtil.addRandom(tree, variables); ElementUtil.addRandom(tree, variables);
if (CollectionUtils.isNotEmpty(this.headers)) { if (CollectionUtils.isNotEmpty(this.headers)) {
config.setHeaders(this.headers); config.setHeaders(this.headers);

View File

@ -60,7 +60,7 @@ public class MsLoopController extends MsTestElement {
final HashTree groupTree = controller(tree); final HashTree groupTree = controller(tree);
if (CollectionUtils.isNotEmpty(config.getVariables())) { if (CollectionUtils.isNotEmpty(config.getVariables())) {
ElementUtil.addCsvDataSet(groupTree, config.getVariables(), config, "shareMode.thread"); ElementUtil.addCsvDataSet(groupTree, config.getVariables(), config, "shareMode.thread");
ElementUtil.addCounter(groupTree, config.getVariables()); ElementUtil.addCounter(groupTree, config.getVariables(), true);
ElementUtil.addRandom(groupTree, config.getVariables()); ElementUtil.addRandom(groupTree, config.getVariables());
} }