【问题标题】:How to pick the particular row value from spock table如何从 spock 表中选择特定的行值
【发布时间】:2016-10-06 05:26:35
【问题描述】:

我必须在 spock 表中存储多个数据。当需要时,我必须通过参数值传递数据,根据它应该在 spock 表中搜索,选择相应的数据。请查看代码并更正它。 实施我的项目对我很有帮助。

 def passW = "Publisher"
 def "getPassword" (passW) {

expect:

     if (secureKeyword == passW ) {

        println "Result is " + encryptPass
       }

     where:
     secureKeyword || encryptPass
     "Author"      || "aW50ZWxAMTIzNCE="
     "Publisher"   || "tsdwerDhV76wYCf="
 }

结果应该是:​tsdwerDhV76wYCf=​

【问题讨论】:

  • 认为您对测试的用途感到困惑。两者都应该通过,你为什么要运行一个?
  • 我不想运行 where 表中的所有项目。在我的应用程序中,我必须为不同的模块使用不同的凭据。所以我存储模块名称,密码。当我传递模块名称时,它应该选择相应的密码并将其设置为密码列。 (用户名会直接给出)。
  • 再一次,这不是单元/集成测试的用途。
  • tim_yates : 你能给我任何其他的解决方案来从 spock 表中提取数据吗?
  • 也许您要测试的内容有一些上下文,而不是我需要从表中选择这些数据,所以请修复下面的代码?

标签: groovy spock geb


【解决方案1】:

您可以将模块数据存储在静态(或@Shared)集合中,并在 findAll 闭包的 where 部分过滤测试输入。

def static moduleCredentials = ["Author":"aW50ZWxAMTIzNCE=",
                             "Publisher":"tsdwerDhV76wYCf="]

@Unroll
def "Module #module.key login credentials test"(){
        def moduleName = module.key
        def modulePass = module.value
        println(moduleName+":"+modulePass)
        expect:
        assert modulePass

        where:
        module << moduleCredentials.findAll {it.key=="Author"}.entrySet()
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多