问题
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