Can anyone let me know how can I get the time taken by each of the unit tests in a unit test class in a single file via maven-surefire
? I have seen my target/surefire-report
it has files for each test. Basically I am looking for a single file with all the execution times summarized. If possible also sort the result by execution time of each test.
I am using maven 3.5 & surefire-plugin 2.4.2 on MacOSX 10.12.6.
You can use surefire-report-plugin for aggregation the results (but it still won't been sorted)
or
if you've already build the project with surefire plugin.
This will generate surefire-report.html in your root target directory where you can find time stats for each module and each test suite.
The
maven-surefire-plugin
currently doesn't let you do this. It writes all the results in separate files. You could create a feature-request in its issue tracker, if you feel like this is a missing feature.However you can use some Linux commands to convert the output to what you need. Here are some commands that turn the separate XML files into a single file that looks like what you want:
Update: Numeric sorting has problems with varying number of fraction digits. Use
awk
version below to solve this.The same thing could be done with
awk
a bit shorter and less cryptic:You have to execute these commands from the toplevel directory of your maven project after the surefire-reports were generated.
If you have multi-module project, use this instead:
The resulting file is
output.txt
and contains lines of the following format:The result is sorted by consumed time.
I wrote a small bash script with Martin Höller's snippet that might help someone: