Back to Skills

ert

verified

A guide to using ERT (Emacs Lisp Regression Testing) for testing Emacs Lisp code.

View on GitHub

Marketplace

library-skills

hugoduncan/library-skills

Plugin

emacs-libraries

emacs

Repository

hugoduncan/library-skills
3stars

plugins/emacs-libraries/skills/ert/SKILL.md

Last Verified

January 23, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/hugoduncan/library-skills/blob/main/plugins/emacs-libraries/skills/ert/SKILL.md -a claude-code --skill ert

Installation paths:

Claude
.claude/skills/ert/
Powered by add-skill CLI

Instructions

# ERT: Emacs Lisp Regression Testing

ERT is Emacs's built-in testing framework for automated testing of Emacs Lisp code. It provides facilities for defining tests, running them interactively or in batch mode, and debugging failures with integrated tooling.

## Overview

ERT (Emacs Lisp Regression Testing) is included with Emacs and requires no additional installation. It leverages Emacs's dynamic and interactive nature to provide powerful testing capabilities for unit tests, integration tests, and regression prevention.

**Key Characteristics:**
- Built into Emacs (available in Emacs 24+)
- Interactive debugging with backtrace inspection
- Flexible test selection and organization
- Batch mode for CI/CD integration
- Dynamic binding for easy mocking
- No external dependencies

## Core Concepts

### Test Definition

Tests are defined using `ert-deftest`, which creates a named test function:

```elisp
(ert-deftest test-name ()
  "Docstring describing what the test verifies."
  (should (= 2 (+ 1 1))))
```

### Assertions (Should Forms)

ERT provides three assertion macros:

- `should` - Assert that a form evaluates to non-nil
- `should-not` - Assert that a form evaluates to nil
- `should-error` - Assert that a form signals an error

Unlike `cl-assert`, these macros provide detailed error reporting including the form, evaluated subexpressions, and resulting values.

### Test Selectors

Selectors specify which tests to run:

- `t` - All tests
- `"regex"` - Tests matching regular expression
- `:tag symbol` - Tests tagged with symbol
- `:failed` - Tests that failed in last run
- `:passed` - Tests that passed in last run
- Combinations using `(and ...)`, `(or ...)`, `(not ...)`

## API Reference

### Defining Tests

#### `ert-deftest`
```elisp
(ert-deftest NAME () [DOCSTRING] [:tags (TAG...)] BODY...)
```

Define a test named NAME.

**Parameters:**
- `NAME` - Symbol naming the test
- `DOCSTRING` - Optional description of what the test verifies
- `:tags` - Optional list of t

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
21457 chars