javaunit-testingmavensurefire

What is a good way in maven/surefire to clean up after unit tests, whether they pass or not?


We have some unit tests that unfortunately create memory-mapped NIO files that cannot be deleted by the process that created them (some windows issue).

Regardless, I would like to run some sort of clean up after these tests, whether they passed or not. I was going to run a small ant script at the prepare-package phase, but if any test fails, surefire exits immediately.

Apart from going to the failsafe plugin which has a post-test phase, is there any clever way I can run my cleanup regardless of pass or fail?

I suspect not - I've gone through all the surefire config options...

edit: memory-mapped nio files cannot be deleted in the same process, even by deleteOnExit.


Solution

  • You should bound the thing you want to do into the post-integration-test lifecycle phase which is running afterwards the integration-test phase which is handled by the maven-failsafe-plugin. It might work if you configure the maven-clean-plugin to do so.