我可以配置Grails来查看插件中的测试类吗



我有一个大型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文件夹,而不是测试文件夹。这样,您就可以将它包含在插件和其他项目的测试用例中。

最新更新