Friday, October 14, 2016

Spock data driven testing with interactions (Mocks)

You can do data driven testing with Mocks and interactions, the key is that your interaction should be in the setup: block For Example
    @Unroll
    def "createOtherField test to see if label override works #fieldName override(#fieldLabel) == #resultName"() {
        setup:
        FormFieldMapManager formFieldMapManager = Mock()
        String onlineFormId = '1'
        List<LabelValue> otherFields = []
        1*formFieldMapManager.getMappedFields(onlineFormId, false) >> [new FormFieldMap()]

        expect:
        List<LabelValue> result = ProcessorUtil.createOtherField(formFieldMapManager, onlineFormId, otherFields, fieldName, 'fieldValue')
        result[0].label == resultName

        where:
        fieldName   | fieldLabel    || resultName
        'fieldName' | null          || 'fieldName'
        'fieldName' | ''            || 'fieldName'
        ''          | null          || ''
        'fieldName' | 'OVERRIDE'    || 'OVERRIDE'
    }

No comments:

Post a Comment