fitnesse.fixtures.StringFixture

问题描述 投票:1回答:2

谁能提供一个例子,说明如何使用 FitNesse字符串夹具?

下面的内容不能用。

|fitnesse.fixtures.StringFixture|
|value|expected|contains?       |
|hello|lo      |true            |

为了提供上下文,我想验证一下... ... Id 字段的REST调用的输出。

|Table:smartrics.rest.fitnesse.fixture.RestFixture | http://localhost|
|GET|/data/1234|  |                                                | |
|let|body      |js| JSON.parse(response.body)                      | |
|let|id        |js| JSON.parse(response.body).Data[0].Id           | |

如果可能的话,我希望不要写任何代码。

json fitnesse fitnesse-slim
2个回答
2
投票

).对于字符串:nl.hsac.fitnesse.fixture.slim.StringFixture。对于JSON(使用

JsonPath

|script|string fixture                                                                                    |
|check |value of             |Hello                      |Hello                                           |
|check |length of            |Hello                      |5                                               |
|ensure|text                 |Hello world!               |contains    |world                              |
|reject|text                 |Hello world!               |contains    |moon                               |
|ensure|value                |Hello                      |differs from|Hell                               |
|ensure|value                |Hello                      |equals      |Hello                              |
|check |convert to upper case|Bye                        |BYE                                             |
|check |convert to lower case|Bye                        |bye                                             |
|check |normalize whitespace |!-   Hello    World    -!  |Hello World                                     |
|check |replace all          |Hello ([A-Za-z]+)          |in          |Hello World|with|$1      |World    |
|check |replace all          |(\d{4})-(\d{1,2})-(\d{1,2})|in          |1975-12-3  |with|$3-$2-$1|3-12-1975|

): nl.hsac.fitnesse.fixture.slim.JsonHttpTest。所以你的REST检查应该是这样的。

|script  |json http test                            |
|get from|http://echo.jsontest.com/key/value/one/two|
|show    |response                                  |
|check   |json path       |$.key       |value       |
|check   |json path       |$.one       |two         |

|script  |json http test                 |
|get from|http://localhost/data/1234     |
|show    |response                       |
|check   |json path      |$.Data[0].Id |1|
|note    |or assign to symbols           |
|$body=  |response                       |
|$id=    |json path      |$.Data[0].Id   |
Looks like contains() Returns expected, not truefalse. 看起来像 contains() 返回预期的结果,而不是 truefalse. 所以测试应该是

1
投票

|fitnesse.fixtures.StringFixture|
|value|expected|contains?|
|hello|lo|lo|

© www.soinside.com 2019 - 2024. All rights reserved.