0

我有一张工作台:

#some javascript stuff
!define or { || }

#my stuff
!define headers { !-Authorization: Basic YWRtaW46cGFzc3dvcmQ=
Accept: application/json -! }

|Table:smartrics.rest.fitnesse.fixture.RestFixture|http://admin:password@localhost:5984/|
|setHeaders|${headers} |
|DELETE    |/q-couch | | | jsonbody.ok ${or} jsonbody.error=="not_found"  |

我现在想重新分解以制作可重用的组件,以及更具可读性的测试。我试过这个:

#what I hoped would be a reusable component.
|scenario|deletedb|name|
|Table:smartrics.rest.fitnesse.fixture.RestFixture|http://admin:password@localhost:5984/|
|setHeaders|${headers} |
|DELETE|/@dbName | | |jsonbody.ok ${or} jsonbody.error=="not_found"  |   

#A more readable test
|Script|
|deletedb|q-couch|

当我按下测试时,我会The instance scriptTableActor. does not exist在脚本中进入场景中的每一行。

我在做什么有效吗?我究竟做错了什么?

4

1 回答 1

3

为什么错误

scriptTableActor.发生错误是因为您没有在脚本表头中提供对任何夹具的引用。从ScriptTable 指南中截取:

第一行是简单的单词“Script”,后跟夹具的名称和构造函数参数(称为“actor”),表的其余部分将使用它们。如果没有指定演员,那么将使用此测试页面上的前一个脚本表的演员。

RestFixture 有一个用于脚本表的特殊夹具,因此您的第一行应定义为:

|Script|RestScriptFixture|http://admin:password@localhost:5984/|

可重用的 RestFixture 组件

我使用了一种场景结构(在ScenarioLibrary中定义)和我们包含的构建块来获得可重用的组件。此策略也可以用于 RestFixture 以外的其他固定装置。

在你的情况下,我会定义以下场景

!|Scenario|When a |http_verb |is sent to |service |with headers set to |headers|
|setHeaders|@headers|
|@http_verb|@service|

!|Scenario|the response should contain |element |equal to |value |or |second_element |equal to |second_value|
|check|js|(response.jsonbody.hasOwnProperty('@element') && response.jsonbody.@element.toString()==@value)!-||-!(response.jsonbody.hasOwnProperty('@second_element') && response.jsonbody.@second_element.toString()==@second_value)|true|

第二种情况有点沉重,因此可能需要进行解释。由于我不知道是否ok并且error总是在您的响应中返回,因此首先它检查元素是否存在response.jsonbody.hasOwnProperty('@element'),然后检查它是否具有正确的值response.jsonbody.@element.toString()==@value)。我已经用 . 转义了 or 运算||!--!

构建块 wiki 如下所示:

|Script|RestScriptFixture|${server}|
|When a |delete |is sent to |${service} |with headers set to |${headers}|
|the response should contain |${element} |equal to |${value} |or |${second_element} |equal to |${second_value}|

测试维基将是:

!define TEST_SYSTEM {slim}
!define server {http://admin:password@localhost:5984/}
!define headers { !-Authorization: Basic YWRtaW46cGFzc3dvcmQ=
Accept: application/json -! }
!define service {/q-couch/}
!define element {ok}
!define value {0}
!define second_element {error}
!define second_value {not_found}

!include PathTo.BuildingBlock

上面的一些定义,我可能会放在 SetUp wiki 中。

于 2014-01-29T10:44:12.497 回答