سؤال

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?

هل كانت مفيدة؟

المحلول

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]]

نصائح أخرى

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)
*/
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top