Reputation: 2325
I have a simple grails service:
@Transactional
class SearchService {
def doSomething() {
10
}
}
with a simple unit test:
class SearchServiceSpec extends Specification implements ServiceUnitTest<SearchService>{
def setup() {
}
def cleanup() {
}
void "test something"() {
expect:
service.doSomething() == 10
}
}
When I run the test, I get the following exception:
Anyone know what this means?
Strange thing is it works if I change doSomething
to getSomething
and then do service.something
.
I have following versions: | Grails Version: 3.3.0 | Groovy Version: 2.4.11 | JVM Version: 1.8.0_60
Upvotes: 3
Views: 362
Reputation: 12228
This is due to the fact that the getter method is not having transactional behavior applied to it. To test a transactional method, you need to have a GORM implementation setup. The easiest way to do that for your test is to implement grails.testing.gorm.DataTest
.
Upvotes: 8