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
}
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