|
1 | | -# Coverage percentage commands (target-level) |
| 1 | +# Coverage commands (split schemes + merged report) |
2 | 2 |
|
3 | | -# 1) Generate a fresh coverage bundle |
4 | | -make test |
| 3 | +# 1) Run unit tests with coverage output |
| 4 | +xcodebuild test \ |
| 5 | + -project CycleOne.xcodeproj \ |
| 6 | + -scheme CycleOne-Unit \ |
| 7 | + -destination 'platform=iOS Simulator,name=iPhone 17 Pro' \ |
| 8 | + -parallel-testing-enabled YES \ |
| 9 | + -derivedDataPath build/deriveddata \ |
| 10 | + -enableCodeCoverage YES \ |
| 11 | + -resultBundlePath UnitCoverage.xcresult |
5 | 12 |
|
6 | | -# 2) Show coverage % for every target in TestResults.xcresult |
7 | | -xcrun xccov view --report --json TestResults.xcresult \ |
8 | | - | jq -r '.targets[] | "\(.name): \((.lineCoverage * 100) | tostring)% (\(.coveredLines)/\(.executableLines))"' |
| 13 | +# 2) Run UI tests with coverage output |
| 14 | +xcodebuild test \ |
| 15 | + -project CycleOne.xcodeproj \ |
| 16 | + -scheme CycleOne-UI \ |
| 17 | + -destination 'platform=iOS Simulator,name=iPhone 17 Pro' \ |
| 18 | + -parallel-testing-enabled YES \ |
| 19 | + -derivedDataPath build/deriveddata \ |
| 20 | + -enableCodeCoverage YES \ |
| 21 | + -resultBundlePath UICoverage.xcresult |
9 | 22 |
|
10 | | -# 3) Show only the main project targets |
11 | | -xcrun xccov view --report --json TestResults.xcresult \ |
12 | | - | jq -r '.targets[] |
13 | | - | select(.name == "CycleOne.app" or .name == "CycleOneTests.xctest" or .name == "CycleOneUITests.xctest") |
14 | | - | "\(.name): \((.lineCoverage * 100) | tostring)% (\(.coveredLines)/\(.executableLines))"' |
| 23 | +# 3) Export coverage payloads and merge unit + UI reports |
| 24 | +rm -rf coverage_export |
| 25 | +mkdir -p coverage_export/unit coverage_export/ui coverage_export/merged |
15 | 26 |
|
16 | | -# 4) Enforce minimum target percentage (example: 100) |
17 | | -MIN_PERCENT=100 |
18 | | -xcrun xccov view --report --json TestResults.xcresult \ |
19 | | - | jq -e --argjson min "$MIN_PERCENT" ' |
20 | | - .targets |
21 | | - | map(select(.name == "CycleOne.app" or .name == "CycleOneTests.xctest" or .name == "CycleOneUITests.xctest")) |
22 | | - | all((.lineCoverage * 100) >= $min) |
23 | | - ' |
| 27 | +xcrun xcresulttool export coverage --path UnitCoverage.xcresult --output-path coverage_export/unit |
| 28 | +xcrun xcresulttool export coverage --path UICoverage.xcresult --output-path coverage_export/ui |
24 | 29 |
|
25 | | -# jq exits 0 when all targets meet the threshold, non-zero otherwise. |
| 30 | +xcrun xccov merge \ |
| 31 | + --outReport coverage_export/merged/merged.xccovreport \ |
| 32 | + --outArchive coverage_export/merged/merged.xccovarchive \ |
| 33 | + 'coverage_export/unit/0_Test_iPhone 17 Pro_CoverageReport' \ |
| 34 | + 'coverage_export/unit/0_Test_iPhone 17 Pro_CoverageArchive' \ |
| 35 | + 'coverage_export/ui/0_Test_iPhone 17 Pro_CoverageReport' \ |
| 36 | + 'coverage_export/ui/0_Test_iPhone 17 Pro_CoverageArchive' |
26 | 37 |
|
27 | | -# 5) Run localization integrity checks |
| 38 | +# 4) Show merged target coverage percentages |
| 39 | +xcrun xccov view --report --json coverage_export/merged/merged.xccovreport \ |
| 40 | + | jq -r '.targets[] | "\(.name): \(((.lineCoverage * 100) | tostring))% (\(.coveredLines)/\(.executableLines))"' |
| 41 | + |
| 42 | +# 5) Enforce 100% for app target |
| 43 | +xcrun xccov view --report --json coverage_export/merged/merged.xccovreport \ |
| 44 | + | jq -e '.targets[] | select(.name == "CycleOne.app") | (.coveredLines == .executableLines)' |
| 45 | + |
| 46 | +# 6) Run localization integrity checks (unit scheme) |
28 | 47 | DEST_ID=$(xcrun simctl list devices available | awk -F '[()]' '/iPhone/ {print $2; exit}') |
29 | 48 | if [ -z "$DEST_ID" ]; then echo "No available iPhone simulator found."; exit 1; fi |
30 | 49 |
|
31 | | -xcodebuild test -project CycleOne.xcodeproj -scheme CycleOne -destination "id=${DEST_ID}" \ |
| 50 | +xcodebuild test -project CycleOne.xcodeproj -scheme CycleOne-Unit -destination "id=${DEST_ID}" \ |
32 | 51 | -parallel-testing-enabled NO \ |
33 | 52 | -only-testing:CycleOneTests/LocalizationCoverageTests \ |
34 | 53 | -only-testing:CycleOneTests/AppLanguageTests |
0 commit comments