Automate Tests in iOS with Git Hooks

Tom Pearson
Mar 24 · 3 min read

Running Tests through the Command Line

xcodebuild \
-project YourProject.xcodeproj \
-scheme “YourTestScheme” \
-destination ‘platform=iOS Simulator,name=iPhone XR,OS=12.1’ test

Fishing for Commits

#!/bin/bash
GIT_DIR=$(git rev-parse --git-dir)
echo "Installing hooks…"
ln -s ../../scripts/pre-commit.bash $GIT_DIR/hooks/pre-commit
echo “Done!”
#!/bin/bash
echo “Running pre-commit hook”
xcodebuild -quiet -project YourProject.xcodeproj -scheme “YourTestScheme” -destination 'platform=iOS Simulator,name=iPhone XR,OS=12.1' test
if [ $? -ne 0 ]; then
echo “Tests must pass before commit!”
exit 1
fi
git commit --no-verify …
chmod +x install-hooks.bash pre-commit.bash

Wrapping Up

Alternative Approach

Sources/Further Reading

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade