Question

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.

Was it helpful?

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.

OTHER TIPS

I would make sure the files are created in either target/ or the OS's temporary directory (using System.getProperty("java.io.tmpdir"). Then they will be cleaned up automatically when you run mvn clean, or eventually by the OS.

Add following dependancy in pom and remove existing from your POM

        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.19.1</version>
                </plugin>
            </plugins>
        </build>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top