我有一个大型 grails 项目,分为几个“就地”插件,以保持良好和模块化。我的一个插件,称为“核心服务”,包含我所有的域类,以及在由许多单元测试共享的抽象测试类中的一些不错的设置工作(添加模拟域实例等)。
这对于同样存在于插件中的单元测试来说非常有用,但我想使用该抽象测试类在使用该插件的其他 grails 项目测试中设置模拟数据。运行测试时,插件的测试类似乎没有包含在类路径中。有什么方法可以告诉 Grails 包含它们吗?:
//this abstract test class is in the core service plugin's test directory. My IDE has no problem with this import
import com.myproject.coreservices.service.AbstractGiftInstanceRelatedUnitTest
//this test class is in the project that uses the plugin
class ClaimGiftControllerTests extends AbstractGiftInstanceRelatedUnitTest {
.. my tests
}
以及输出(删除了非重要部分):
| Error Compilation error compiling [unit] tests: startup failed:
...../test/unit/com/myproject/ClaimGiftControllerTests.groovy: 3: unable to resolve class com.myproject.coreservices.service.AbstractGiftInstanceRelatedUnitTest
@ line 3, column 1.
import com.myproject.coreservices.service.AbstractGiftInstanceRelatedUnitTest
^
最佳答案
您可以将 AbstractGiftInstanceRelatedUnitTest 放入插件的 src/groovy 文件夹,而不是测试文件夹。这样您就可以将它包含在插件和其他项目的测试用例中。
关于unit-testing - 我可以配置 Grails 以在我的插件中查看测试类吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12500389/