Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
286 views
in Technique[技术] by (71.8m points)

groovy - How can I search and return the values and pass it to the method from spock table

Currently implementing GEB,Spock,Groovy. I come across the scenario like

There is a set of data's in the spock table. I have to pass the modulename as a parameter, Search from the spock table then return two values user id and password. Below code is skeleton code

My question is how to search module name based on parameter? How to return two data's ?

Class Password_Collection extends Specification {

def "Secure password for search and Data Driven"(String ModuleName) {

   expect:
           // Search based on modulename in where
           // pick the values and return the picked data


            where:
            Module              | User_Name     | Pass_word
            login_Pass          | cqauthor1     | SGVsbG8gV29ybGQ =
            AuthorPageTest_Pass | cqauthor2     | DOIaRTd35f3y4De =
            PublisherPage_pass  | cqaauthor3    | iFK95JKasdfdO5 ==

}
        }

If you provide the code it would be great help to learn and imeplement.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You don't need to search the table yourself or pick that data. Spock will do that automatically for you

In the expect: block just write your unit test that uses Module, User_Name and Pass_word. Spock will automatically run the test 3 times (as many as the rows of the table) passing each row in turn to your test.

Remove the argument ModuleName from the test method. It is not needed.

I suggest you read the Spock documentation on Data Driven tests a bit more.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...