【问题标题】:Can I configure Grails to see test classes in my plugin?我可以配置 Grails 以在我的插件中查看测试类吗?
【发布时间】:2012-09-12 02:19:52
【问题描述】:

我有一个大型 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
   ^

【问题讨论】:

    标签: unit-testing grails classpath


    【解决方案1】:

    您可以将 AbstractGiftInstanceRelatedUnitTest 放入插件的 src/groovy 文件夹,而不是 test 文件夹。这样您就可以将它包含在插件和其他项目的测试用例中。

    【讨论】:

    • 是的,我最终做到了。我会给你答案的。只是感觉不对:-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-27
    • 2018-12-27
    • 2017-07-23
    • 2014-06-08
    • 2021-11-14
    • 1970-01-01
    相关资源
    最近更新 更多