在一个 where: 块中传递一个值在 Spock 测试中 [英] Passing a value in a where: block in Spock test

查看:40
本文介绍了在一个 where: 块中传递一个值在 Spock 测试中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以像这样在 where 块中传递一个值.

Is it possible to pass a value in where block like this.

这个我试过了.但它失败了并给出了 MissingPropertyException.

I have tried this. But it fails and gives MissingPropertyException.

我希望 name1 和 name2 位于方法内部.

And I want the name1 and name2 to be inside the method.

def "length of names #name"()  {    
        def name1 = "Spock"
        def name2 = "Java"

        expect:
            name.size() == length

        where:
            name        || length
            name1       || 5
            name2       || 2
    }

推荐答案

试试这个:

def "test length of names"()  {
    expect:
        name.size() == length   
    where:
    [name,length]<<getTestData()

}

def getTestData(){
        [["Ram"  ,3 ] ,["Test" ,4] ]
    }

希望有帮助!!!

谢谢

这篇关于在一个 where: 块中传递一个值在 Spock 测试中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆