使用Spock的Grails单元测试自定义编解码器 [英] Grails unit testing custom codec using Spock

查看:102
本文介绍了使用Spock的Grails单元测试自定义编解码器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个Spock单元测试来测试我创建的自定义编解码器。我看到的大多数测试自定义编解码器的示例都在扩展GrailsUnitTestCase来执行此操作。有人可以指出我正确的方向,如何使用Spock做到这一点?

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?

推荐答案

我最终做了以下工作:

@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' | _
        ''       | _
    }

}

这篇关于使用Spock的Grails单元测试自定义编解码器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆