Reputation: 433
Below is the example of my CSV file
A1,B1
A2,B2
A3,B3
Here is my Spock test:
def testCSV() {
when:
def A = ValueOfA
def B = ValueOfA
then:
println A
println B
where:
ValueOfA | ValueOfA
**get these value from csv file**
}
Is it possible to read the csv file and pass the value in the where clause?
Upvotes: 0
Views: 743
Reputation: 33
def testCSV() {
when:
def A = inputValues.split(",")[0]
def B = inputValues.split(",")[1]
then:
println A
println B
where:
inputValues << new File( "\\src\\test\\resources\\test.txt").readLines().toList()
/* To get specific Rows
inputValues << new File( "\\src\\test\\resources\\test.txt").readLines().toList().subList(1,10)
*/
}
Upvotes: 0
Reputation: 2050
You can read the csv file in a private method like this http://groovy-almanac.org/csv-parser-with-groovy-categories/ and then you can assign the variables a and b like this:
where:
a << [readCSVAMap[0],readCSVAMap[1],readCSVAMap[2]]
b << [readCSVBMap[0],readCSVBMap[1],readCSVBMap[2]]
Upvotes: 4