SoWeLie
SoWeLie

Reputation: 1391

Grails Integration Test: Domain Classes Not Functioning

I've created simple Grails plugin project in STS. I'm using the Spring Security Core plugin, which added a handful of domain classes. I've created an integration test which simply creates an instance of one of the domain classes (User), and saves it. I am getting the following error upon running the integration test:

Failure:  testSomething(com.resonance.rwp.core.tests.UserServiceTests)
groovy.lang.MissingMethodException: No signature of method: com.resonance.rwp.core.domain.User.save() is applicable for argument types: () values: []
Possible solutions: save(), save(boolean), save(java.util.Map), wait(), any(), wait(long)
    at com.resonance.rwp.core.tests.UserServiceTests.setUp(UserServiceTests.groovy:14)

I don't understand, it seems like the Domain classes aren't being mapped via GORM for some reason. Everything I've come across involves people trying to use GORM in unit tests, but I am definitely running an integration test. Any help is much appreciated.

Here is the source, it is really simple:

class UserServiceTests {

@Before
void setUp() {
    User user = new User(username: "Test");
    user.save();
}

@After
void tearDown() {
    // Tear down logic here
}

@Test
void testSomething() {
    fail "Implement me"
}
}

I also tried moving everything into the test itself. It is obviously failing on the setUp method.

Upvotes: 2

Views: 3552

Answers (4)

August Lilleaas
August Lilleaas

Reputation: 54593

I had this problem too on a newly generated plugin, and found that the issue is that newly generated plugins doesn't depend on hibernate. I added the following to BuildConfig.groovy:

plugins {
    runtime ":hibernate:$grailsVersion"
}

This caused the problem to go away. I'm not familiar enough with Grails to have any theories as to why the error message hinted to the actual existence of the persistence methods like save, but at least I got it working :)

http://jira.grails.org/browse/GRAILS-9163?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

Upvotes: 2

Interlated
Interlated

Reputation: 5926

If you have a single test that still uses:

extends GrailsUnitTestCase 

you will see this. You need to change all unit tests to annotation based tests in grails 2+

http://grails.org/doc/latest/guide/testing.html#unitTesting

Upvotes: 0

Esteban
Esteban

Reputation: 2579

Just had a problem like yours creating some integration tests with Grails 2.0.0

The integration tests failed when run as grails test-app but did work when run as grails test-app --integration. To my surprise, unit tests were polluting the test environment in some way. Even more surprisingly, deleting some auto-generated (i.e. empty) unit tests did the trick! Tests are now passing with both commands.

There has been a discussion on the topic in another question, the asker needed to migrate his unit tests to the Grails 2.0.0 way of writing tests (i.e. JUnit 4 and grails' test mixins) to make his integration tests work, you can see how to do that in the docs.

I will try to file a bug report if I can reproduce in a minimal application built for that purpose. Hope this helps!

Upvotes: 1

Andrew Eisenberg
Andrew Eisenberg

Reputation: 28757

It looks like the Grails AST transforms are not running in this case for some reason. I am guessing that you are running Grails 2.0, but you haven't actually said. Try running a clean build inside of STS (Project -> Clean...).

I tried this out in a simple Grails 2.0 project. Looks like it works for me. I think your best bet is to create a simple grails project that has this problem, export it as a zip and raise a jira issue. https://issuetracker.springsource.com/browse/STS

Upvotes: 0

Related Questions