我最近开始认真地使用 Grails 2.0,但我遇到了一个对我来说没有多大意义的障碍。我已经编写了一个集成测试,它对控制器使用 @TestFor 注释,但是我从中得到了非常奇怪的错误。以下是测试,精简到重复此问题的最小情况:
import org.junit.*
import grails.test.mixin.TestFor
@TestFor(OrderController)
class OrderControllerIntegrationTests {
public EndUser user
@Before public void initialize() {
user = new EndUser(username: UUID.randomUUID().toString(), password: "secret");
user.save()
}
@Test public void get() {
assert true
}
@Test public void create() {
assert true
}
}
总之,我得到的输出是我的测试设置中的 save() 方法不再存在于此类中的第二个测试。这似乎……很奇怪。
以下是 grails test-app exampleapp.OrderControllerIntegrationTests 的完整输出:
Testsuite: exampleapp.OrderControllerIntegrationTests
Tests run: 2, Failures: 0, Errors: 1, Time elapsed: 0.769 sec
------------- Standard Output ---------------
--Output from get--
2012-05-15 22:35:03,491 [main] DEBUG transaction.JDBCTransaction - begin
2012-05-15 22:35:03,493 [main] DEBUG transaction.JDBCTransaction - current autocommit status: true
2012-05-15 22:35:03,493 [main] DEBUG transaction.JDBCTransaction - disabling autocommit
2012-05-15 22:35:03,689 [main] DEBUG hibernate.SQL - insert into widget_user (id, version, password, username, class) values (null, ?, ?, ?, 'exampleapp.EndUser')
2012-05-15 22:35:03,970 [main] DEBUG transaction.JDBCTransaction - rollback
2012-05-15 22:35:03,970 [main] DEBUG transaction.JDBCTransaction - re-enabling autocommit
2012-05-15 22:35:03,970 [main] DEBUG transaction.JDBCTransaction - rolled back JDBC Connection
--Output from create--
2012-05-15 22:35:03,979 [main] DEBUG transaction.JDBCTransaction - begin
2012-05-15 22:35:03,979 [main] DEBUG transaction.JDBCTransaction - current autocommit status: true
2012-05-15 22:35:03,979 [main] DEBUG transaction.JDBCTransaction - disabling autocommit
2012-05-15 22:35:04,207 [main] DEBUG transaction.JDBCTransaction - rollback
2012-05-15 22:35:04,207 [main] DEBUG transaction.JDBCTransaction - re-enabling autocommit
2012-05-15 22:35:04,207 [main] DEBUG transaction.JDBCTransaction - rolled back JDBC Connection
------------- ---------------- ---------------
------------- Standard Error -----------------
--Output from get--
--Output from create--
------------- ---------------- ---------------
Testcase: get took 0.51 sec
Testcase: create took 0.251 sec
Caused an ERROR
No signature of method: exampleapp.EndUser.save() is applicable for argument types: () values: []
Possible solutions: save(), save(), save(boolean), save(java.util.Map), save(boolean), save(java.util.Map)
groovy.lang.MissingMethodException: No signature of method: exampleapp.EndUser.save() is applicable for argument types: () values: []
Possible solutions: save(), save(), save(boolean), save(java.util.Map), save(boolean), save(java.util.Map)
at exampleapp.OrderControllerIntegrationTests.initialize(OrderControllerIntegrationTests.groovy:17)
有没有人有任何想法?