1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
6 ;;;; Purpose: Example file for XLUnit
8 ;;;; *************************************************************************
10 (defpackage #:xlunit-example
12 (:export #:math-test-suite))
14 (in-package #:xlunit-example)
16 ;;; First we define some basic test-cases that we are going to need to
17 ;;; perform our tests. A test-case is a place to hold data we need
18 ;;; during testing. Often there are many test cases that use the same
19 ;;; data. Each of these test cases is an instance of a test-case.
21 (defclass math-test-case (test-case)
22 ((numbera :accessor numbera)
23 (numberb :accessor numberb))
24 (:documentation "Test test-case for math testing"))
26 ;;; Then we define a set-up method for the test-case. This method is run
27 ;;; prior to perfoming any test with an instance of this test-case. It
28 ;;; should perform all initialization needed, and assume that it is starting
29 ;;; with a pristine environment, well to a point, use your head here.
31 (defmethod set-up ((tcase math-test-case))
32 (setf (numbera tcase) 2)
33 (setf (numberb tcase) 3))
36 (def-test-method test-addition ((test math-test-case) :run nil)
37 (let ((result (+ (numbera test) (numberb test))))
38 (assert-true (= result 5))))
40 (def-test-method test-subtraction ((test math-test-case) :run nil)
41 (let ((result (- (numberb test) (numbera test))))
42 (assert-equal result 1)))
44 ;;; This method is meant to signal a failure
45 (def-test-method test-subtraction-2 ((test math-test-case) :run nil)
46 (let ((result (- (numbera test) (numberb test))))
47 (assert-equal result 1 "This is meant to failure")))
49 ;;;; Finally we can run our test suite and see how it performs.
50 (textui-test-run (get-suite math-test-case))