- will talk to database, so it will be slower than unit test
- will persist data to database - make sure Your test environment database setting don't point to production or development database
- You have to initialize the service class yourself, there is no dynamic injection. It is the same way as it was during unit testing.
- If the service has other service class inside it, You have to initialize and assign it manually. Also it is the same way as it was during unit testing.
- Sometimes it is useful to flush session in order to persist to database immediately - else You might get weird thing like no "id" for the supposedly saved domain object or deleted objects would be not deleted. How to do that? It's very easy, please look at the simple example:
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.
Hello,
ReplyDeleteThe Article on Grails Integration Testing is informative. It gives detailed information about it.Thanks for Sharing the information on Integration Testing .For More information check the detail on Integration testing check, Software Testing Services