Running Android Unit Tests before Git Push

This is a quick note about a Git hook I use to double check that everything is fine before pushing to our remote Git repo.

This covers a paranoid scenario, I know, but sometimes a refactoring can go wrong and lose pieces between production code and tests: every now and then, one of my tests goes out-of-sync and when I push to Github/CI, I get some silly error because of a typo somewhere. This trick will re-run every Unit Test when I give git push and will actually push only if tests pass.

The Script

Create a file named pre-push and place it in your_repo/.git/hooks . Be sure the file is executable: chmod +x pre-push

Copy this snippet into the file:


This uses ./gradlew clean test, but you can use ./gradle check or any other Gradle task you use to run your tests.


Git hooks are quite handy in lots of scenarios and there are plenty of them. Check out http://githooks.com/.

Personally, I find pretty useful my pre-push hook and, obviously, lolcommits! 😀

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.