Start testing your Emacs Lisp code like your Java code with JUnit.
For best visualization, also install fringe-helper.
(add-to-list 'load-path "/path/to/elk-test") (autoload 'elk-test-mode "elk-test" nil t) (add-to-list 'auto-mode-alist '("\\.elk\\'" . elk-test-mode)) (define-key elk-test-mode-map (kbd "M-<f7>") 'elk-test-run-buffer) (define-key emacs-lisp-mode-map (kbd "<f7>") 'elk-test-run-a-buffer)
Define tests (sample), then use M-x elk-test-run or M-x elk-test-run-buffer to run the test.
Tests can be defined with deftest
and conducted with assert-equal
, assert-eql
, assert-eq
, assert-nonnil
, assert-t
, assert-nil
and assert-error
.
To jump to failures, use next-error
, or click on the links in the error buffer. The optional elk-test-result-follow-mode
will automatically display the corresponding failure location. To enable it by default, use the following configuration:
(add-hook 'elk-test-result-mode-hook 'elk-test-result-follow-mode)
To create your own assertions, use assert-that
. For example, the following code defines assert-eq
using assert-that
:
(defmacro assert-eq (expected actual) "Assert that ACTUAL equals EXPECTED, or signal a warning." `(assert-that (lambda (actual) (eq ,expected ,actual)) actual "assert-eq" (lambda (actual) (format "expected <%s>, was <%s>" ,expected ,actual))))
Also available via ELPA.
If you have any feedback, please email me, or visit this package's page at the Emacs wiki.