在Concordion降价中使用变量 [英] Using variables in Concordion markdown

查看:69
本文介绍了在Concordion降价中使用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在用Concordion编写测试规范时,有时需要在脚本中包含调用的输出.例如,我想通过向其发布新对象来测试REST服务,然后验证返回的对象是否包括其自己的URI字符串.在这种情况下,我认为将URI字符串的格式包含在测试脚本中,而不是将其隐藏在灯具中是正确的.

When writing a test specification in Concordion, you sometimes want to include the output of a call in the script. For example, I want to test a REST service by posting a new object to it and then verifying that the returned object includes its own URI string. In these circumstances, I think it's right that the format of the URI string is included in the test script rather than buried within a fixture.

假设已经以某种方式创建了名为newProduct的对象,我想编写如下内容:

Assuming that an object named newProduct has been created somehow, I would like to write something like this:

When I [post a new product](- "#response=post(#newProduct)")<br/>
Then a [product record](- "#product=getContent(#response)") is returned<br/>
and its [id](- "c:set=#productId=getId(#product)") is [ ](- "c:echo=#productId)")<br/>
and its HAL reference matches [products/#productId](- "?=getHalRef(#product)")

不幸的是,最后一行中的变量productId无法解析.您会推荐哪种方法?

Unfortunately the variable productId in the last line is not resolved. What approach would you recommend?

推荐答案

我建议在规范中说明URI字符串的静态格式,而不是实际值(动态值会动态生成,并且每次都会导致不同的规范).

I'd recommend stating the static format of the URI string in the specification rather than the actual values (which are dynamic and will lead to a different spec each time).

灯具可以比较预期格式和实际格式.在仪器文档.

The fixture can compare the expected and actual formats. This technique is described in the context of date conversion in the instrumentation documentation.

使用此技术,您的Markdown可以写为:

Using this technique, your Markdown could be written as:

When I [post a new product](- "#response=post(#newProduct)")<br/> Then a [product record](- "#product=getContent(#response)") is returned<br/> with a HAL reference matching [products/#productId](- "?=checkHalRef(#product, #TEXT)") ( _[#productId](- "#productId=getId(#product)") is [ ](- "c:echo=#productId")_ )

When I [post a new product](- "#response=post(#newProduct)")<br/> Then a [product record](- "#product=getContent(#response)") is returned<br/> with a HAL reference matching [products/#productId](- "?=checkHalRef(#product, #TEXT)") ( _[#productId](- "#productId=getId(#product)") is [ ](- "c:echo=#productId")_ )

使用checkHalRef方法:

public String checkHalRef(String product, String expected) { String halRef = getHalRef(product); String expectedHalRef = expected.replace("#productId", getId(product)); if (halRef.equals(expectedHalRef)) { return expected; } return halRef; }

public String checkHalRef(String product, String expected) { String halRef = getHalRef(product); String expectedHalRef = expected.replace("#productId", getId(product)); if (halRef.equals(expectedHalRef)) { return expected; } return halRef; }

成功后,输出文档将显示:

On success, the output documentation would show:

以及失败时:

这篇关于在Concordion降价中使用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆