使用 junit 在 grails 2.5 中设置集成测试的正确方法是什么?

What is the proper way to setup integration tests in grails 2.5 using junit?

对于 grails 2.2,以下代码(这是对 GORM class 的集成测试)工作正常:

public class DbDeploymentIntegrationTests extends GroovyTestCase
{
  DeploymentStorageImpl deploymentStorage

  DeploymentService deploymentService

  @Override
  protected void setUp()
  {
    super.setUp()
    deploymentStorage = deploymentService.deploymentService.deploymentStorage
  }
...
}

当我更新到 grails 2.5 时,现在失败了:

| Failure:  testIncludeDetails(org.linkedin.glu.console.domain.DbDeploymentIntegrationTests)
|  java.lang.NullPointerException: Cannot get property 'deploymentService' on null object
    at org.linkedin.glu.console.domain.DbDeploymentIntegrationTests.setUp(DbDeploymentIntegrationTests.groovy:41)

文档 (http://grails.github.io/grails-doc/2.5.0/guide/upgradingFrom22.html) 说明如下:

Dependency Injection for Integration Tests

In order to support alternate JUnit4 test runners, Grails 2.3 no longer uses a special test runner to run tests and integration tests should no longer extend GroovyTestCase.

This change requires that any JUnit integration tests that require dependency injection now need to be annotated with:

@TestMixin(IntegrationTestMixin)

我尝试添加这个注释,但没有效果:代码在 setup 方法中仍然失败。如果我在测试方法中直接注释掉 setup 并访问 deploymentService 它确实有效。所以依赖注入发生了。不只是在 setup 方法中。它曾经正常工作。

知道如何解决这个问题吗?

谢谢

参见 https://jira.grails.org/browse/GRAILS-10584

您的测试不应扩展 GroovyTestCase,而应使用 JUnit 4 样式