Marty Pitt
Marty Pitt

Reputation: 29280

Grails - save() failing with MissingMethodExcepition in integration test

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: "[email protected]")
        user.save()
    }
}

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

What have I missed?

Upvotes: 3

Views: 1986

Answers (1)

Burt Beckwith
Burt Beckwith

Reputation: 75671

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/

Upvotes: 3

Related Questions