lundi 29 août 2016

Using Spock data driven tests in Grails 3 unit test

I am upgrading a series of unit tests that worked in Grails 2 to Grails 3 and having problems with domain tests that use the Spock data driven test format to drive tests.

import grails.test.mixin.TestFor
import grails.test.mixin.TestMixin
import grails.test.mixin.support.GrailsUnitTestMixin
import spock.lang.Unroll

import com.spiekerpoint.ark.test.ConstraintsTestSupport

 /**
  * Unit test for domain class ContactPhoneNumber.
  */
 @TestFor(ContactPhoneNumber)
 class ContactPhoneNumberSpec implements ConstraintsTestSupport {

    def setup() {
        mockForConstraintsTests(ContactPhoneNumber, [new ContactPhoneNumber()])
    }

    def cleanup() {
    }

    @Unroll
    void "test ContactPhoneNumber type constraints"() {
        when:
        ContactPhoneNumber obj = new ContactPhoneNumber("$field": val)

        then:
        validateConstraints(obj, field, error)

        where:
        error       | field         | val
       'valid'      | 'type'        | 'HOME'
       'valid'      | 'type'        | 'MOBILE'
       'valid'      | 'type'        | 'WORK'
       'valid'      | 'type'        | 'PAGER'
       'valid'      | 'type'        | 'FAX'
    }
}

I am getting a groovy.lang.MissingPropertyException at ContactPhoneNumberSpec.groovy:26

when I execute the test because the test execution is not filling in the error, field and val references in the test. As mentioned, this test works with Grails 2.5.5, so I suspect that I'm missing something that I need in Grails 3.

Aucun commentaire:

Enregistrer un commentaire