unit-testing - 我可以配置 Grails 以在我的插件中查看测试类吗?

标签 unit-testing grails classpath

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

相关文章:

grails - 如何强制 Grails 只使用一种语言?

java - 通过REST提交EMR Yarn应用程序

java - 在单元测试中捕获 SQLException 而不是 Spring DataIntegrityViolationException

grails - 使用groovy 1.8及更高版本重写渲染方法

grails - Spring Security ACL和Postgres

java - 无法在 Tomcat 的应用程序中加载 .properties

java - 无法解决注释处理器的 jar 依赖关系

java - 为什么 FetchType.EAGER 在单元测试中不起作用?

java - Mockito - 在单元测试中期望模拟时返回 null

ruby-on-rails - 用于测试的未定义方法 `users'