0

I'm writing a griffon application with JavaFX and the JPA plugin. I have a service I'd like to test - this service makes use of the JPA plugin (withJpa {...}) and it's this database access that I want to test.

So, I want to write this test so it inserts some data, then check that the service produces the right answer thus verifying the sql query is correct.

I've written a simple test:

class ReportServiceTests extends GriffonUnitTestCase {
    GriffonApplication app

    public void testStats() {
        println app.getServices()
        println app.getControllers()
    }
}

but I cannot get hold of a valid service - both the println statements above produce "[:]".

How do I get hold of the 'ReportService' instance and exercise it against the database? I don't want to mock the database interaction.

Thanks.

4

1 回答 1

1

无需模拟数据库。如http://griffon.codehaus.org/guide/latest/guide/testing.html#integrationTesting中所述,应用程序在集成测试期间进入初始化阶段。插件在此阶段被初始化。另一方面,服务被延迟初始化,因为它们在实例化时被 MVC 成员拉入:如果你调用app.getServices(). 但是,您可以指示应用程序急切地实例化所有服务,这将使您的代码按预期工作;只需将以下标志添加到 Config.groovy

griffon.services.eager.instantiation = true

有关服务的更多信息,请访问http://griffon.codehaus.org/guide/latest/guide/controllersAndServices.html#services

于 2013-02-18T08:53:18.717 回答