Using variables in Concordion markdown

2019-09-04 23:01发布

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条回答
时光不老,我们不散
2楼-- · 2019-09-04 23:25

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:

successful example

and on failure:

enter image description here

查看更多
登录 后发表回答