开发者

Grails - save() failing with MissingMethodExcepition in integration test

开发者 https://www.devze.com 2023-02-12 21:23 出处:网络
I\'m learning groovy / grails, and writing my first integration test. It\'s currently failing with: 开发者_开发知识库

I'm learning groovy / grails, and writing my first integration test.

It's currently failing with:

开发者_开发知识库

groovy.lang.MissingMethodException: No signature of method: com.mangofactory.scurry.User.save() is applicable for argument types: () values: []

My test isn't doing anything fancy:

class UserEventControllerTests extends ControllerUnitTestCase {
    protected void setUp() {
        super.setUp()
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testAddingAUser()
    {
        def user = new User(emailAddress: "martypitt@test.com")
        user.save()
    }
}

Saving the entity works fine when I do it through the scaffolded pages provided by grails.

What have I missed?


If you want it to be an integration tests it shouldn't extend one of the unit test base classes, so change it to

class UserEventControllerTests extends GroovyTestCase {
...
}

and make sure it's in test/integration, not test/unit.

But it looks like you want to test a controller (it's called UserEventControllerTests) which should extend ControllerUnitTestCase. If that's the case then you should be doing unit tests, but mocking the domain layer (using mockDomain and others) since you want to focus on controller logic, not persistence. Test domain classes in proper integration tests using a database.

This is all described in chapter 10 of the docs: http://grails.org/doc/latest/

0

精彩评论

暂无评论...
验证码 换一张
取 消