Include time spent on "setUp" in test execution time

I use Gradle 6.6 RC6 with TestNG 7. Several of my tests spend a lot of time in the code surrounding the test, i.e. setting up the Spring context, and doing things in setUp (@BeforeMethod). Sadly, this time is not shown in the “Tests” overview of my build scan.

Is there a way to include this time? Is there any other comfortable way to identify tests that are slow because of (mostly) code outside the individual @Test method?

With the following configuration I get testng-results.xml files, which contain individual XML snippets both for test methods, and each invocation of setUp methods. I’d love to have a nicer presentation of this, but it’s a start.

tasks.withType(Test) {
    useTestNG() {
        useDefaultListeners = true
    }
//     turn off Gradle's HTML report to avoid replacing the
//     reports generated by TestNG library:
//    reports.html.enabled = false
}
<class name="com.foo.BarTest">
<test-method status="PASS" signature="setUp()[pri:0, instance:com.foo.BarTest@4e24fc08]" name="setUp" is-config="true" duration-ms="6917" started-at="2020-08-10T17:29:32 BST" finished-at="2020-08-10T17:29:39 BST">
<reporter-output> </reporter-output>
</test-method>
<!--  setUp  -->
<test-method status="PASS" signature="testSomething()[pri:0, instance:com.foo.BarTest@4e24fc08]" name="testSomething" duration-ms="147" started-at="2020-08-10T17:29:39 BST" finished-at="2020-08-10T17:29:39 BST">
<reporter-output> </reporter-output>
</test-method>
<!--  testSomething  -->
[...]

Some ugly bash magic:

By method:

for i in `find -name testng-results.xml`; do cat $i | sed 's/.*<test-method status="PASS" signature=".*\.\(.*\)@........]" name="\([^"]*\)".*duration-ms="\(.*\)" started-at.*/\3\t\1.\2 XXX/'| grep XXX | sed 's/ XXX//g'; done | awk '{sums[$2] += $1} END { for (i in sums) printf("%s %s\n", sums[i], i)}' - | sort -gr

By class:

for i in `find -name testng-results.xml`; do cat $i | sed 's/.*<test-method status="PASS" signature=".*instance:\(.*\)@........]" name="\([^"]*\)".*duration-ms="\(.*\)" started-at.*/\3\t\1\t\2 XXX/'| grep XXX | sed 's/ XXX//g'; done | awk '{sums[$2] += $1} END { for (i in sums) printf("%s %s\n", sums[i], i)}' - | sort -gr

By package:

for i in `find -name testng-results.xml`; do cat $i | sed 's/.*<test-method status="PASS" signature=".*\.\(.*\)@........]" name="\([^"]*\)".*duration-ms="\(.*\)" started-at.*/\3\t\1.\2 XXX/'| grep XXX | sed 's/ XXX//g'; done | awk '{sums[$2] += $1} END { for (i in sums) printf("%s %s\n", sums[i], i)}' - | sort -gr