Skip to content

Instantly share code, notes, and snippets.

@chrisvasselli
Created September 29, 2023 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisvasselli/6a533738c5600328ad4b4bb5c0405dbb to your computer and use it in GitHub Desktop.
Save chrisvasselli/6a533738c5600328ad4b4bb5c0405dbb to your computer and use it in GitHub Desktop.
set -o pipefail && xcodebuild -workspace StudyJapanese.xcworkspace -scheme "StudyJapanese" -testPlan "AllUITests" -sdk "$SIMULATOR_SDK" $destinations -derivedDataPath "build/DerivedData" -parallel-testing-enabled YES -parallel-testing-worker-count $parallel_test_workers -retry-tests-on-failure -test-iterations 2 test -resultBundlePath artifacts/TestResults.xcresult OS_ACTIVITY_MODE='disable' $exclude_non_parallelizable_tests_args | tee artifacts/xcodebuild.log | bundle exec xcpretty || true
# Tests than failed the first time and succeeded the second time will show up in both files. Need the ones that only failed.
testRefsID=$(xcrun xcresulttool get --format json --path artifacts/TestResults.xcresult | jq --raw-output '.actions._values[0].actionResult.testsRef.id._value')
xcrun xcresulttool get --format json --path artifacts/TestResults.xcresult --id $testRefsID | jq '.summaries._values[0].testableSummaries._values[0].tests._values[0].subtests._values[0].subtests._values[].subtests | select( . != null ) | ._values[] | select(.testStatus._value | contains("Success")) | .identifier._value' | sort > build/successfulTestRuns.txt
xcrun xcresulttool get --format json --path artifacts/TestResults.xcresult --id $testRefsID | jq '.summaries._values[0].testableSummaries._values[0].tests._values[0].subtests._values[0].subtests._values[].subtests | select( . != null ) | ._values[] | select(.testStatus._value | contains("Failure")) | .identifier._value' | sort | grep -v "StudyJapaneseUITests-Runner .*encountered an error" > build/failedTestRuns.txt || [[ $? == 1 ]] # exit code of 1 is no matches found (which is fine), >1 is an error
comm -23 build/failedTestRuns.txt build/successfulTestRuns.txt | uniq > build/failedTests.txt
if [ -s build/failedTests.txt ]; then
#If errors, retry failed tests and build report from those results
repeat_failed_tests_args=$(cat build/failedTests.txt | sed 's/()"//' | sed 's/\./\//' | sed 's/\"/-only-testing StudyJapaneseUITests\//' | paste -sd " " -)
repeat_failed_tests_args="$repeat_failed_tests_args $include_non_parallelizable_tests_args"
else
repeat_failed_tests_args="$include_non_parallelizable_tests_args"
fi
if [ -z "$repeat_failed_tests_args" ]; then
echo "No tests to run in serial"
else
xcrun simctl shutdown all
xcrun simctl delete all
destinations=""
initializeSimulator "standalone"
set -o pipefail && xcodebuild -workspace StudyJapanese.xcworkspace -scheme "StudyJapanese" -testPlan "SetupUITest" -sdk "$SIMULATOR_SDK" $destinations -derivedDataPath "build/DerivedData" -parallel-testing-enabled NO test -resultBundlePath artifacts/TestResultsRepeatFailuresSetup.xcresult OS_ACTIVITY_MODE='disable' | tee artifacts/repeat-failures-setup-xcodebuild.log | bundle exec xcpretty || exit_code=1
set -o pipefail && xcodebuild -workspace StudyJapanese.xcworkspace -scheme "StudyJapanese" -testPlan "AllUITests" -sdk "$SIMULATOR_SDK" $destinations -derivedDataPath "build/DerivedData" -parallel-testing-enabled NO test -resultBundlePath artifacts/TestResultsRepeatFailures.xcresult $repeat_failed_tests_args OS_ACTIVITY_MODE='disable' | tee artifacts/xcodebuildrepeatfailures.log | bundle exec xcpretty || exit_code=1
bundle exec trainer --path "$STUDY_JAPANESE_DIR/artifacts/TestResultsRepeatFailures.xcresult"
mv artifacts/TestResultsRepeatFailures.xml artifacts/result.xml
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment