bdp*_*ish 5 grails integration-testing grails-orm grails-domain-class
我在Eclipse中有两个Grails项目.我使用Configure Build Path设置引用另一个项目.然而,运行测试会引发错误java.lang.IllegalStateException: Method on class [com.example.domain.Phone] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.
通常用@Mock(使用Mockito)或mockDomain()来修复,但我不在单元测试中,因此看不到这些项目.
如果无法看到我需要使用的域对象,如何通过集成测试来测试我的服务层?这些域对象是分开的,因为需要在多个项目中使用它们.
有适用于 Spring Boot 的 GORM。https://spring.io/guides/gs/accessing-data-gorm/中的示例
如果您正在编写测试,可以使用HibernateTestMixin或使用HibernateDatastoreSpringInitializer来初始化 GORM。