1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; ID: $Id: example.lisp,v 1.5 2003/08/04 16:13:58 kevin Exp $
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 fixtures that we are going to need to
17 ;;; perform our tests. A fixture 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-fixture (test-case)
22 ((numbera :accessor numbera)
23 (numberb :accessor numberb))
24 (:documentation "Test fixture for math testing"))
26 ;;; Then we define a set-up method for the fixture. This method is run
27 ;;; prior to perfoming any test with an instance of this fixture. 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 ((fix math-fixture))
32 (setf (numbera fix) 2)
33 (setf (numberb fix) 3))
35 ;;; Then we define a teardown method, which should return the instance
36 ;;; to it's original form and reset the environment. In this case
37 ;;; there is little for us to do since the fixture is quite static.
38 ;;; In other cases we may need to clear some database tables, or
39 ;;; otherwise get rid of state built up while perofmring the test.
40 ;;; Here we just return T.
42 (defmethod tear-down ((fix math-fixture))
45 (def-test-method test-addition ((test math-fixture))
46 (let ((result (+ (numbera test) (numberb test))))
47 (test-assert (= result 5))))
49 (def-test-method test-subtraction ((test math-fixture))
50 (let ((result (- (numberb test) (numbera test))))
51 (assert-equal result 1)))
53 ;;; This method is meant to signal a failure
54 (def-test-method test-subtraction-2 ((test math-fixture))
55 (let ((result (- (numbera test) (numberb test))))
56 (assert-equal result 1)))
58 ;;;; Finally we can run our test suite and see how it performs.
59 (textui-test-run (make-test-suite 'math-fixture))