简体   繁体   中英

Groovy/Grails Unit Test Error with custom codec

I am having an issue with the "Getting Started with Grails" tutorial from the Grails website. It is having me create a custom codec in the utils directory. I have created the codec and it works in the application, however when I add the codec to my controller unit test, as the tutorial suggests, it fails. Here is the message I get when I run "grails test-app UserController -unit":

"No such property: SHACodec for class: racetrack.UserControllerTests"

I have tried using the loadCodec() method to include the codec, but got the same message.

Does anyone have any suggestions on how to resolve this unit test issue? If it's an import issue, what would the import path be for my SHACodec.groovy file if it is in the /grails-app/utils/?

My tutorial code is available for download at http://arlitt.com/racetrack.zip .

I ran into this too (working through the code in the Grails book).

What I found works is this: explicitly load the codec. You don't need to include it in your imports. Make sure that the SHACodec.groovy file is in the grails-app/utils directory.

The following code snippet shows you how I did it.

class UserControllerTests extends ControllerUnitTestCase{
    protected void setUp() {
        super.setUp()

        loadCodec (org.codehaus.groovy.grails.plugins.codecs.Base64Codec)
        loadCodec (racetrack.SHACodec)
    }
    // ...
}

Codecs are not automatically loaded, you need to load them.

Refer to this post for more details: http://kousenit.wordpress.com/2010/02/24/using-a-codec-in-a-grails-unit-test/

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM