Using variables in Concordion markdown

流过昼夜 提交于 2019-12-25 06:49:59

问题


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.

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)")

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


回答1:


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.

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")_ )

with the checkHalRef method:

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:

and on failure:



来源:https://stackoverflow.com/questions/38186716/using-variables-in-concordion-markdown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!