Next: , Previous: , Up: How to Run Tests   [Contents]

2.2 Running Tests in Batch Mode

ERT supports automated invocations from the command line or from scripts or makefiles. There are two functions for this purpose, ert-run-tests-batch and ert-run-tests-batch-and-exit. They can be used like this:

emacs -batch -l ert -l my-tests.el -f ert-run-tests-batch-and-exit

This command will start up Emacs in batch mode, load ERT, load my-tests.el, and run all tests defined in it. It will exit with a zero exit status if all tests passed, or nonzero if any tests failed or if anything else went wrong. It will also print progress messages and error diagnostics to standard output.

You can also redirect the above output to a log file, say output.log, and use the ert-summarize-tests-batch-and-exit function to produce a neat summary as shown below:

emacs -batch -l ert -f ert-summarize-tests-batch-and-exit output.log

If ERT is not part of your Emacs distribution, you may need to use -L /path/to/ert/ so that Emacs can find it. You may need additional -L flags to ensure that my-tests.el and all the files that it requires are on your load-path.