April 19th 2026 - How to Write Tests in Emacs

Testing is important. Although, the number of test cases don't correlate with code smells[1], having a suite of tests does help prevent regression.

In Emacs we can use the ert-deftest[2] function to create tests:

(ert-deftest testing-sum ()
  "This tests sum is working"
  (should (= (+ 1 2) 3)))

We then run M-x: ert and select our test from the menu to run it.

Alternative packages

  • emacs-buttercup which is similar to Jasmine in JS and has nice documentation. Has set up and tear down features which are missing from ert.

Mocking the file system

Instead of using real files when testing you can mock them with mock-fs.