Grails unit testing custom codec using Spock

可紊 提交于 2019-12-25 02:51:52

问题


I'd like to create a Spock unit test to test a custom codec I created. Most of the examples I see to test custom codecs are extending GrailsUnitTestCase to do this. Can someone point me in the right direction on how to do this using Spock?


回答1:


I ended up doing the following:

@TestMixin(GrailsUnitTestMixin)
class SecureCodecSpec extends Specification {
    def setup() {
        grailsApplication.config.acme.encryption.password = 'topsecret'
        mockCodec(SecureCodec)
    }

    @Unroll
    def "SecureCodec with string value #original encodes and decodes properly"() {
        when:
        def encoded = original.encodeAsSecure()
        def decoded = encoded.decodeSecure()

        then:
        original != encoded
        encoded != decoded
        original == decoded

        where:
        original | _
        'secret' | _
        ''       | _
    }

}



来源:https://stackoverflow.com/questions/24124678/grails-unit-testing-custom-codec-using-spock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!