added a comment - - edited
Attached is a patch that simply removes report files at the end of test execution if it was successful (in AbstractFileReporter). Note: It is difficult to avoid writing the file in the first place, since test logs are streamed directly to the file as the test runs (no buffering) and you only know that a test was successful after it has completed. However, the remove-on-completion works fine. It is backwards-compatible, because the default value for the new option is "true", which will write successful tests as before. Most of the many code changes apply to all the places where the new configuration has to be stored and passed around. Since I had to extend the ReporterConfiguration constructor with a new boolean parameter, there were places where the invocations via reflection had to be changed. I hope I got them all right, normal mvn test calls work fine for me.
I haven't written a unit test for that, as I don't know which place would be the best (api tests or integration-tests). To be able to run "mvn test" in the surefire projects itself (all successful for me), I had to change the maven-surefire-plugin version in the root pom to "2.7.3-SNAPSHOT" - it seems that useSystemClassLoader=false doesn't help, as I get reflection exceptions with 2.7.2 (see below). However, with 2.7.3-SNAPSHOT you can't build from the reactor, as maven stops detecting a cyclic reference now
[INFO] — maven-surefire-plugin:2.7.2:test (default-test) @ surefire-integration-tests —
[INFO] Surefire report directory: /Users/alex/Day/code/maven-surefire/surefire-integration-tests/target/surefire-reports
org.apache.maven.surefire.util.SurefireReflectionException: java.lang.NoSuchMethodException: org.apache.maven.surefire.report.ReporterConfiguration.<init>(java.util.List, java.io.File, java.lang.Boolean, java.lang.Integer); nested exception is java.lang.NoSuchMethodException: org.apache.maven.surefire.report.ReporterConfiguration.<init>(java.util.List, java.io.File, java.lang.Boolean, java.lang.Integer)
java.lang.NoSuchMethodException: org.apache.maven.surefire.report.ReporterConfiguration.<init>(java.util.List, java.io.File, java.lang.Boolean, java.lang.Integer)
As a side node, I think the code base could be simplified enormously if a generic configuration system would be used (like property lists); the use of reflection contradicts with the hight amount of type-enforcement done with the various config objects and type hierarchies. But I guess this is a sign of evolution