• Home
  • Pre-commit hook for behat tests

Pre-commit hook for behat tests


If you are working on small project and you’re using Behat tests, there will be times when you change code and as consequence of that, introduce a bug or break a feature. And more often than that, because we are humans and we forget to do things all the time, you will not run your functional ( in my case Behat ) tests, so bug will go live.

So in order to automate that i created a pre-commit hook that runs Behat test and then rejects commit if they fail.


if behat --config=behat.yml | grep -q 'Failed\ scenarios\:'; then

    echo "\033[0;31mYou have failing Behat scenarios, therefore commit is rejected\033[0m"

    exit 1


Git hooks are located in your .git directory and you can have your own bash code executed on every git event you choose, pre or post event.

Feel free to play with this little script and improve it as it pleases your needs.

P.S. If you want to skip this check then you can commit your code with

git commit --no-verify


About the Author

Follow me

30 year old software developer from Mostar, Bosnia and Herzegovina, currently living and working in Frankfurt am Main, Germany.

Leave a Reply

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

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}