Search code examples
gitunit-testingqunit

Post-mortem unit testing


I do version control with Git, and unit testing with QUnit. Sometimes I find a bug in my software that was not present in a past version. It's easy for me to write a unit test specifically for that bug.

Given that unit test, can I easily go trough all my past commits and test the build with that unit test, so that I can pinpoint which commit caused the breakage?


Solution

  • Use git bisect for this, please see this page.

    Since you're testing JavaScript, you will probably have to run the tests by hand and run git bisect good and git bisect bad as appropriate. However, if you can run your unit test from the command line, then you can use git bisect run to have Git execute the test repeatedly and track down the faulty commit automatically:

    $ git bisect run my-script.sh
    

    That's pure magic the first time you see it! :-)