I have an integration test task, that performs integration test naturally. The flow is like this: 1. Create a new glassfish domain 2. Create a database in MS SQL 3. Deploy the jtds driver to glassfish 4. Start glassfish 5. Build an ear 6. Deploy the ear to glassfish 7. Run integration tests using jUnit 8. Stop glassfish and then delete the domain 9. Delete the database
I have done this by creating a test task:
task integrationTest(type: Test) {
dependsOn ear
dependsOn intTestClasses }
I then have several doFirst and doLast that do the setup off glassfish and the database, as well as a teardown. The problem is that doLast doesn’t seem to get run if the tests fails, so the cleanup isn’t done. This leaves the glassfish instance running, and the database remains.
I tried earlier to instead have try {} finally {} blocks, but there doesn’t seem to be a way of invoking tests without extending the Test type.
I guess the caveat with this approach is that if you’re using the Gradle daemon (which I gather will soon be the default behaviour), then the shutdown hook won’t be executed until the daemon process is shut down…