feat (接口定义): 执行断言增加名称 #1002504

--story=1002504 --user=赵勇 【github#5375】接口c... https://www.tapd.cn/55049933/s/1037118
This commit is contained in:
fit2-zhao 2021-08-20 11:44:14 +08:00 committed by fit2-zhao
parent 696a73635c
commit 8d13d1bd63
4 changed files with 48 additions and 32 deletions

View File

@ -67,11 +67,11 @@ public class MsAssertions extends MsTestElement {
private ResponseAssertion responseAssertion(MsAssertionRegex assertionRegex) {
ResponseAssertion assertion = new ResponseAssertion();
assertion.setEnabled(this.isEnable());
assertion.setName(assertionRegex.getDescription());
if(StringUtils.isEmpty(assertionRegex.getDescription())){
assertion.setName("AssertionRegex");
if (StringUtils.isNotEmpty(assertionRegex.getDescription())) {
assertion.setName(this.getName() + "==" + assertionRegex.getDescription());
} else {
assertion.setName(this.getName() + "==" + "AssertionRegex");
}
assertion.setName(StringUtils.isNotEmpty(assertionRegex.getDescription()) ? assertionRegex.getDescription() : this.getName());
assertion.setProperty(TestElement.TEST_CLASS, ResponseAssertion.class.getName());
assertion.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("AssertionGui"));
assertion.setAssumeSuccess(assertionRegex.isAssumeSuccess());
@ -96,11 +96,11 @@ public class MsAssertions extends MsTestElement {
private JSONPathAssertion jsonPathAssertion(MsAssertionJsonPath assertionJsonPath) {
JSONPathAssertion assertion = new JSONPathAssertion();
assertion.setEnabled(this.isEnable());
assertion.setName(StringUtils.isNotEmpty(assertionJsonPath.getDescription()) ? assertionJsonPath.getDescription() : this.getName());
if(StringUtils.isEmpty(assertion.getName())){
assertion.setName("JSONPathAssertion");
if (StringUtils.isNotEmpty(assertionJsonPath.getDescription())) {
assertion.setName(this.getName() + "==" + assertionJsonPath.getDescription());
} else {
assertion.setName(this.getName() + "==" + "JSONPathAssertion");
}
/* assertion.setName(StringUtils.isNotEmpty(this.getName()) ? this.getName() : "JSONPathAssertion");*/
assertion.setProperty(TestElement.TEST_CLASS, JSONPathAssertion.class.getName());
assertion.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("JSONPathAssertionGui"));
assertion.setJsonPath(assertionJsonPath.getExpression());
@ -120,11 +120,11 @@ public class MsAssertions extends MsTestElement {
private XPath2Assertion xPath2Assertion(MsAssertionXPath2 assertionXPath2) {
XPath2Assertion assertion = new XPath2Assertion();
assertion.setEnabled(this.isEnable());
assertion.setName(StringUtils.isNotEmpty(assertionXPath2.getExpression()) ? assertionXPath2.getExpression() : this.getName());
if(StringUtils.isEmpty(assertion.getName())){
assertion.setName("XPath2Assertion");
if (StringUtils.isNotEmpty(assertionXPath2.getExpression())) {
assertion.setName(this.getName() + "==" + assertionXPath2.getExpression());
} else {
assertion.setName(this.getName() + "==" + "XPath2Assertion");
}
/*assertion.setName(StringUtils.isNotEmpty(this.getName()) ? this.getName() : "XPath2Assertion");*/
assertion.setProperty(TestElement.TEST_CLASS, XPath2Assertion.class.getName());
assertion.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("XPath2AssertionGui"));
assertion.setXPathString(assertionXPath2.getExpression());
@ -135,8 +135,10 @@ public class MsAssertions extends MsTestElement {
private DurationAssertion durationAssertion(MsAssertionDuration assertionDuration) {
DurationAssertion assertion = new DurationAssertion();
assertion.setEnabled(this.isEnable());
assertion.setName("Response In Time: " + assertionDuration.getValue());
/* assertion.setName(StringUtils.isNotEmpty(this.getName()) ? this.getName() : "Response In Time: " + assertionDuration.getValue());*/
assertion.setName("" + "==" + "Response In Time: " + assertionDuration.getValue());
if (StringUtils.isNotEmpty(this.getName())) {
assertion.setName(this.getName() + "==" + "Response In Time: " + assertionDuration.getValue());
}
assertion.setProperty(TestElement.TEST_CLASS, DurationAssertion.class.getName());
assertion.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("DurationAssertionGui"));
assertion.setAllowedDuration(assertionDuration.getValue());
@ -146,11 +148,11 @@ public class MsAssertions extends MsTestElement {
private JSR223Assertion jsr223Assertion(MsAssertionJSR223 assertionJSR223) {
JSR223Assertion assertion = new JSR223Assertion();
assertion.setEnabled(this.isEnable());
assertion.setName(StringUtils.isNotEmpty(assertionJSR223.getDesc()) ? assertionJSR223.getDesc() : this.getName());
if(StringUtils.isEmpty(assertion.getName())){
assertion.setName("JSR223Assertion");
if (StringUtils.isNotEmpty(assertionJSR223.getDesc())) {
assertion.setName(this.getName() + "==" + assertionJSR223.getDesc());
} else {
assertion.setName(this.getName() + "==" + "JSR223Assertion");
}
/*assertion.setName(StringUtils.isNotEmpty(this.getName()) ? this.getName() : "JSR223Assertion");*/
assertion.setProperty(TestElement.TEST_CLASS, JSR223Assertion.class.getName());
assertion.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
assertion.setProperty("cacheKey", "true");

View File

@ -7,6 +7,8 @@ public class ResponseAssertionResult {
private String name;
private String content;
private String message;
private boolean pass;

View File

@ -219,7 +219,9 @@ public class MsResultService {
}
//xpath 提取错误会添加断言错误
if (StringUtils.isBlank(responseAssertionResult.getMessage()) ||
(StringUtils.isNotBlank(responseAssertionResult.getName()) && !responseAssertionResult.getName().endsWith("XPath2Extractor"))) {
(StringUtils.isNotBlank(responseAssertionResult.getName()) && !responseAssertionResult.getName().endsWith("XPath2Extractor"))
|| (StringUtils.isNotBlank(responseAssertionResult.getContent()) && !responseAssertionResult.getContent().endsWith("XPath2Extractor"))
) {
responseResult.getAssertions().add(responseAssertionResult);
}
}
@ -252,6 +254,15 @@ public class MsResultService {
private ResponseAssertionResult getResponseAssertionResult(AssertionResult assertionResult) {
ResponseAssertionResult responseAssertionResult = new ResponseAssertionResult();
responseAssertionResult.setName(assertionResult.getName());
if (StringUtils.isNotEmpty(assertionResult.getName()) && assertionResult.getName().indexOf("==") != -1) {
String array[] = assertionResult.getName().split("==");
responseAssertionResult.setName(array[0]);
StringBuffer content = new StringBuffer();
for (int i = 1; i < array.length; i++) {
content.append(array[i]);
}
responseAssertionResult.setContent(content.toString());
}
responseAssertionResult.setPass(!assertionResult.isFailure() && !assertionResult.isError());
if (!responseAssertionResult.isPass()) {
responseAssertionResult.setMessage(assertionResult.getFailureMessage());

View File

@ -1,14 +1,15 @@
<template>
<el-table :data="assertions" :row-style="getRowStyle" :header-cell-style="getRowStyle">
<el-table-column prop="name" :label="$t('api_report.assertions_name')" width="300"/>
<el-table-column prop="name" :label="$t('api_report.assertions_name')" width="200" show-overflow-tooltip/>
<el-table-column prop="content" label="内容" width="300" show-overflow-tooltip/>
<el-table-column prop="message" :label="$t('api_report.assertions_error_message')"/>
<el-table-column prop="pass" :label="$t('api_report.assertions_is_success')" width="180">
<el-table-column prop="pass" :label="$t('api_report.assertions_is_success')" width="100">
<template v-slot:default="{row}">
<el-tag size="mini" type="success" v-if="row.pass">
{{$t('api_report.success')}}
{{ $t('api_report.success') }}
</el-tag>
<el-tag size="mini" type="danger" v-else>
{{$t('api_report.fail')}}
{{ $t('api_report.fail') }}
</el-tag>
</template>
</el-table-column>
@ -16,19 +17,19 @@
</template>
<script>
export default {
name: "MsAssertionResults",
export default {
name: "MsAssertionResults",
props: {
assertions: Array
},
props: {
assertions: Array
},
methods: {
getRowStyle() {
return {backgroundColor: "#F5F5F5"};
}
methods: {
getRowStyle() {
return {backgroundColor: "#F5F5F5"};
}
}
}
</script>
<style scoped>