3

I'm new to using ERT for testing my Elisp code, and I have a question that doesn't seem to be covered in the manual: according to best practices, where does one typically put the ERT tests? Do they go at the end of the elisp file that is to be tested, or should I put them in a separate file? I'm sure they'll work either way, but is one or the other preferred?

  • Please never define test cases inline. There's no need to force your tests upon end users. – lunaryorn Oct 7 '15 at 17:40
  • Yeah, I figured that wasn't the answer, but I still wasn't sure what the convention was. – Ryan C. Thompson Oct 7 '15 at 18:10
5

I would place the tests in a test directory and name it thepackage-test.el. Alternatively, thepackage-test-onething.el and thepackage-test-anotherthing.el.

Using a test directory is especially useful if the tests require auxiliary files.

Another advantage is that it simplifies the MELPA recipe, as subdirectories aren't included by default.

For an example of a package with relative complex tests, you can take a look at my font-lock rules for CMake: https://github.com/Lindydancer/cmake-font-lock

|improve this answer|||||
3

Separate file, of course. The end users need not load it. In fact, if you distribute through MELPA, the tests won't be bundled. The convention is to name the file foo-test.el.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.