Unit testing

Introduction

There are a few libraries for unit testing in Common Lisp

  • FiveAM
  • Prove, with a few unique features like extensive test reporters, colored output, report of test duration and asdf integration.
  • Lisp-Unit2, similar to JUnit
  • Fiasco, focusing on providing a good testing experience from the REPL. Successor to hu.dwim.stefil

Using FiveAM

Loading the library

(ql:quickload "fiveam")

Define a test case

(fiveam:test sum-1
  (fiveam:is (= 3 (+ 1 2))))

;; We'll also add a failing test case
(fiveam:test sum2
  (fiveam:is (= 4 (+ 1 2))))

Run tests

(fiveam:run!)

which reports

Running test suite NIL
 Running test SUM2 f
 Running test SUM1 .
 Did 2 checks.
    Pass: 1 (50%)
    Skip: 0 ( 0%)
    Fail: 1 (50%)
 Failure Details:
 --------------------------------
 SUM2 []: 
      
(+ 1 2)

 evaluated to 

3

 which is not 

=

 to 

4

..
 --------------------------------
NIL

Notes

  • Tests are grouped by test-suites
  • By defaults tests are added to the global test-suite


2016-07-22
2017-02-14
common-lisp Pedia
Icon