go-test-report icon indicating copy to clipboard operation
go-test-report copied to clipboard

Show separate summary with the slowest tests

Open afbjorklund opened this issue 3 years ago • 0 comments

The excellent gotestsum tool has a feature to show the slowest tests:

Usage:
    gotestsum tool slowest [flags]

Read a json file and print or update tests which are slower than threshold.
The json file may be created with 'gotestsum --jsonfile' or 'go test -json'.
If a TestCase appears more than once in the json file, it will only appear once
in the output, and the median value of all the elapsed times will be used.

[...]

Flags:
      --debug                enable debug logging.
      --jsonfile string      path to test2json output, defaults to stdin
      --skip-stmt string     add this go statement to slow tests, instead of printing the list of slow tests
      --threshold duration   test cases with elapsed time greater than threshold are slow tests (default 100ms)

It would be nice if this list was available on a separate tab/page, with links ?

Example output of tool, after make out/unittest.json and "DONE 899 tests, 2 skipped in 13.313s" BTW: something is fishy here, go-test-report says 895 (not 899) "✓ Passed: 893 ‐ Skipped: 2 ✗ Failed: 0" ? --> filed Bug #19

$ gotestsum tool slowest < out/unittest.json
k8s.io/minikube/pkg/drivers/kic/oci TestRunCmdWarnSlowOnce 6.02s
k8s.io/minikube/pkg/minikube/perf TestTimeCommandLogs 4.03s
k8s.io/minikube/pkg/minikube/tunnel TestTunnelManagerDelayAndContext 1.1s
k8s.io/minikube/pkg/minikube/bootstrapper TestSetupCerts 1.09s
k8s.io/minikube/pkg/minikube/tunnel TestTunnelManagerEventHandling 420ms
k8s.io/minikube/pkg/minikube/tunnel TestTunnelManagerEventHandling/tunnel_always_quits_when_ctrl_c_is_pressed 420ms
k8s.io/minikube/pkg/util TestGenerateSignedCert 380ms
k8s.io/minikube/pkg/util TestGenerateSignedCert/valid_cert 270ms
k8s.io/minikube/cmd/minikube/cmd TestDeleteAllProfiles 270ms
k8s.io/minikube/cmd/minikube/cmd TestDeleteProfile 270ms
k8s.io/minikube/pkg/util TestGenerateCACert 230ms
k8s.io/minikube/cmd/minikube/cmd TestValidateImageRepository 140ms

So it shows all tests that ran slower than 100ms (slider?), sorted by duration...

Most of them run in "0s" (as they should), so this a nice way of finding culprits.

Web enhancements:

  • show inline bar of the times, for comparison
  • slider for dynamically choosing the threshold

afbjorklund avatar May 02 '21 07:05 afbjorklund