【问题标题】:How to refer to a row index in a Fancordion fixture table?如何引用 Fancordion 夹具表中的行索引?
【发布时间】:2015-12-12 03:49:55
【问题描述】:

使用Fancordion v1.0.4中的表,如何使用列命令中的行索引来验证其值。

例如,如果我的灯具是:

class MyFixture : FixtureTest {

    [Str:Obj?][] getCountries() {
         return [["code":"AU", "name":"Australia"], ["code":"NZ", "name":"New Zealand"], ["code":"UK", "name":"United Kingdom"]]
    }
}

规格是:

table:
col[0]+verifyEq:getCountries[#ROW]["code"]
col[1]+verifyEq:getCountries[#ROW]["name"]

Country Code    Country Name
------------    ------------
AU              Australia
NZ              New Zealand
UK              United Kingdom

我应该使用什么来代替上面规范示例中的#ROW 占位符?

有没有更好的方法来编写这个规范和夹具?例如在夹具中创建一个方法来检索列表中的每个单独地图而不是完整列表是否更好?

【问题讨论】:

  • #ROW 宏已添加到此 commit - 感谢您的想法!
  • 感谢您的添加。它可能非常有用。

标签: fantom afbedsheet fancordion


【解决方案1】:

正如您所说,没有 #ROW 宏(但它可能是一个不错的补充!)所以目前您需要更改断言或数据结构。

更改断言:

这里我们稍微改变断言并引入我们自己的 row 字段,该字段在每次行迭代结束时递增:

**  Hi!
** 
**   table:
**   col[0]+verifyEq:getCountries[#FIXTURE.row]["code"]
**   col[1]+verifyEq:getCountries[#FIXTURE.row]["name"]
**   row+exe:row++
**
**   Country Code    Country Name
**   ------------    ------------
**   AU              Australia
**   NZ              New Zealand
**   UK              United Kingdom
** 
class CountryTest : FixtureTest {
    Int row := 0

    [Str:Obj?][] getCountries() {
         return [["code":"AU", "name":"Australia"], ["code":"NZ", "name":"New Zealand"], ["code":"UK", "name":"United Kingdom"]]
    }
}

改变数据结构:

更好的方法可能是将正在测试的数据更改为列表列表。因为当测试数据太多或太少时,这具有失败的额外优势。

**  Hi!
** 
**   table:
**   verifyRows:getCountries()
**
**   Country Code    Country Name
**   ------------    ------------
**   AU              Australia
**   NZ              New Zealand
**   UK              United Kingdom
** 
class CountryTest : FixtureTest {

    Str[][] getCountries() {
        countries := [["code":"AU", "name":"Australia"], ["code":"NZ", "name":"New Zealand"], ["code":"UKs", "name":"United Kingdom"]]
        return countries.map { it.vals }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-16
    • 1970-01-01
    • 2011-05-25
    • 1970-01-01
    • 2019-03-15
    相关资源
    最近更新 更多