Integration testing Griffon services

I wanted to create an integration test for some Griffon services - where I wanted to set up some data first, then check that the service produced the appropriate results. Therefore, I wanted the database working normally, but I needed access to a configured Griffon application and the required services.

My issue was how to get hold of the services? They don't automatically get injected as I first expected. But luckily, StackOverflow and Andres to the rescue:


import griffon.test.GriffonUnitTestCase
/**
* Date: 18/02/13
*/
class ReportServiceTests extends GriffonUnitTestCase {
GriffonApplication app
ReportService reportService
ImporterService importerService
protected void setUp() {
super.setUp()
reportService = app.serviceManager.findService('reportService')
importerService = app.serviceManager.findService('importerService')
}
public void testStats() {
// implement tests here using services...
}
}

Popular posts from this blog

AspectJWeaver with JDK 7 - error - only supported at Java 5 compliance level or above

Intellij tip - Joining multiple lines into one

JUnit parameterized test with Spring autowiring AND transactions