Igor Igor - 1 year ago 82
Groovy Question

How to create a method that returns a Multi Variable Data Pipe "grid"?

I have some tests that are common for different kind of users.
I need the same test in different places with different outputs.

Right now I'm using data table like this:

containerType | name
ContentTypes.BOX |ContentNames.TEST_BOX
ContentTypes.BOX |ContentNames.TEST_BOX_2

What I'm trying to do is to add those tests into an abstract Spec, and do something like:

[containerType, name] << getMyData()

How to I create a method that returns this multi variable data pipe?


Answer Source

What you need is a method that returns a list of lists:

def getMyData() {
    return [
       [ContentTypes.BOX, ContentNames.TEST_BOX],
       [ContentTypes.BOX, ContentNames.TEST_BOX2],
       [ContentTypes.BOX_CONTAINER, ContentNames.TEST_BOX_CONTAINER]

Then you can use the method above with:

[containerType, name] << getMyData()