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?
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' | _
'' | _
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.