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:
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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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... | |
} | |
} |