Embracing the Messiness in Search of Epic Solutions

Spock: Reading Test Data from CSV File



Following up on my recent post about creating a Spock specification to read the test data from a CSV file without loading all the data into the memory, I created a CSVReader that implements Iterable that allows me to pull this off. You may download the source code here.

With this implementation, I can now write an elegant Spock specification:-

class MySpockSpec extends Specification {
    def "#firstNum + 1 == #secondNum"() {
        Integer.valueOf(firstNum as String) + 1 == Integer.valueOf(secondNum as String)

        [firstNum, secondNum] << new CSVReader(getClass().getClassLoader().getResourceAsStream("test.csv"))



One response to “Spock: Reading Test Data from CSV File”

  1. Harish Avatar

    It would be good if there was a section in the csv file for each Spec.testcase .That way there will be only one file for the entire project

Leave a Reply