| Grails Integration Testing: common information |
|
Integration tests differ from unit tests in that you have full access to the Grails environment within the test. Grails will use an in-memory HSQLDB database (or another configured data source, for instance MySQL) for integration tests and clear out all the data from the database in between each test. You have to understand that each test is wrapped into transaction which will be rolled back lately. So integration test:
A couple of helpful thoughts concerning integration tests:
class DocumentServiceTests extends GroovyTestCase {
def documentService
// Dynamic injection of session factory. def sessionFactory
void setUp() {
// You have to initialize service, // there is no dynamic injection. documentService = new DocumentService() }
void testSomething() {
// Some logic. For instance, // documentService.deleteDocumentById(1L). // But document is still not // deleted after execution. // You have to manually flush the session // before assertions. sessionFactory.currentSession.flush() sessionFactory.currentSession.clear()
// Assertions. }
}
That's all for now. |