【发布时间】:2016-01-19 17:03:35
【问题描述】:
我是 Grails 的新手,我想使用 Spock 为服务编写单元测试。但是我有以下问题。
import grails.transaction.Transactional
@Transactional
class BService {
boolean createB(){
return true
}
...
}
对于这门课,我写了以下测试:
class BServiceTest extends Specification {
def "test createB"(){
given:
def service = new BService()
when:
def boolean temp
temp = service.createB()
then:
temp == true
}
}
我在运行此测试时遇到的错误如下:
java.lang.IllegalStateException: No transactionManager was specified. Using @Transactional or @Rollback requires a valid configured transaction manager. If you are running in a unit test ensure the test has been properly configured and that you run the test suite not an individual test method.
and it shows in GrailsTransactionTemplate.groovy:60
如果有人能给我一个提示,我真的很感激。
【问题讨论】:
-
就这些了吗?没有其他测试,项目中没有交易?
-
类Bservice包含更多方法,但我没有附上它们
标签: unit-testing grails groovy spock