This post is an extension of the prior post on precommits. If you are unfamiliar with the tool or haven’t set up pre-commit hooks on your project, go there first.

One of the next steps in getting feedback from your project is to run the quick running tests that would normally break the build.


Context: This example is going to infer there is a Jekyll based project that we’re working on, and it will infer that you are working on a Ruby based system. Please take in consideration that the command executed will be running from the shell, and the success/failure is solely based on the command’s exit code.


To run a set of unit tests right before a commit add a new local repo to your .pre-commit-config.yml file:

  - repo: local
    hooks:
      - id: UnitTestCheck
        name: Run Tests
        entry: bundle exec rake test:production
        language: system
        pass_filenames: false
        types: [ text ]

This section tells the tool that it is a localized hook, the hook name is “UnitTestCheck” and it will execute a command on the shell.

If you want to run tests for java, you would replace the entry with something like mvn test. Scala with something like: sbt test.