Skip to content

Commit

Permalink
ci: Print slowest test cases (#2970)
Browse files Browse the repository at this point in the history
Print the 20 slowest test cases after running unit tests.
  • Loading branch information
philipphofmann committed Apr 27, 2023
1 parent 21fd61f commit 1db04d8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ jobs:
# manipulating string in expressions.
run: ./scripts/xcode-test.sh ${{matrix.platform}} ${{matrix.test-destination-os}} $GITHUB_REF_NAME ci test-without-building

- name: Slowest Tests
if: ${{ always() }}
run: ./scripts/xcode-slowest-tests.sh

- name: Archiving DerivedData Logs
uses: actions/upload-artifact@v3
if: failure()
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ GIT-REF := $(shell git rev-parse --abbrev-ref HEAD)
test:
@echo "--> Running all tests"
./scripts/xcode-test.sh iOS latest $(GIT-REF) YES
./scripts/xcode-slowest-tests.sh
.PHONY: test

run-test-server:
Expand Down
10 changes: 10 additions & 0 deletions scripts/xcode-slowest-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# Finds the x amount of slowest test cases in the raw-test-output.log file.
# Logic copied from https://stanislaw.github.io/2016/08/04/how-to-find-the-slowest-xctest.html.

RAW_TEST_OUTPUT_LOG=${1:-raw-test-output.log}
NUMBER_OF_SLOWEST_TEST="${2:-20}"

echo "The $NUMBER_OF_SLOWEST_TEST slowest test cases:"
cat $RAW_TEST_OUTPUT_LOG | grep 'Test\ Case.*seconds' | awk -F '[()]' '{print $2 " -> " $1}' | sort -rn | head -n $NUMBER_OF_SLOWEST_TEST

0 comments on commit 1db04d8

Please sign in to comment.