ert

Run ERT tests for Emacs Lisp with assertions and batch mode.

3|Updated Nov 10, 2025
One-click install
npx skills add https://github.com/hugoduncan/library-skills --skill ert
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ert
Source: https://github.com/hugoduncan/library-skills/tree/main/plugins/emacs-libraries/skills/ert
Command: npx skills add https://github.com/hugoduncan/library-skills --skill ert

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

ERT provides a structured framework for defining and running Emacs Lisp tests, enabling interactive and batch testing, with helpful failure reports to reduce debugging time and guard against regressions.

Core Features & Use Cases

  • Test Definitions: Write tests with ert-deftest, including optional docstrings and metadata.
  • Assertions: Use should, should-not, and should-error for precise validations and error checks.
  • Test Execution: Run tests interactively via M-x ert or in batch mode for CI/CD workflows.
  • Debugging: Integrated debugging support with backtraces and reruns to quickly locate and fix issues.
  • Mocking & Fixtures: Leverage common patterns (e.g., cl-letf, unwind-protect) to isolate tests.

Quick Start

To get started:

  • Require the library: (require 'ert)
  • Define a simple test:
    (ert-deftest my-test ()
      "Simple test."
      (should (= 1 1)))
    
  • Run tests interactively: M-x ert RET t RET
  • Run tests in batch mode for CI: emacs -batch -l ert -f ert-run-tests-batch-and-exit
  • Review results in the ERT buffer and press d to debug a failing test.

Frequently Asked Questions about ert

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write and run automated tests for Emacs Lisp code?

Use ERT (Emacs Lisp Regression Testing) to write tests with `ert-deftest`, define assertions using `should`, `should-not`, and `should-error`, then run them interactively via M-x ert or in batch mode for CI/CD pipelines. ERT is built into Emacs 24+.

Can I run Emacs Lisp tests in batch mode for continuous integration?

Yes, ERT supports batch-mode execution with `emacs -batch -l ert -f ert-run-tests-batch-and-exit`, enabling automated testing in CI/CD workflows. Results include failure reports and exit codes for pipeline integration.

How do I debug failing Emacs Lisp tests and understand test failures?

ERT provides integrated debugging with backtraces and interactive reruns. Press `d` in the *ERT* buffer to debug a failing test, view detailed failure reports, and quickly locate issues without leaving Emacs.

How do I isolate tests using mocking and fixtures in Emacs Lisp?

Use patterns like `cl-letf` for dynamic binding and `unwind-protect` for resource cleanup to mock dependencies and isolate tests. These techniques ensure robust test cleanup and prevent state leakage between test runs.

What's the best way to organize and structure Emacs Lisp tests?

ERT supports tag-based organization and naming conventions for test structure. Use metadata, docstrings, and test selectors to categorize and filter tests, enabling flexible test execution and clear test intent.