Get It:
Download
Change Log
Learn It:
Install
Tutorial
API Doc
Discuss It:
Mailing List
Follow It:
Code

Tutorial Part 10. HTTP経由でアプリケーションをテスト

HTTP経由でアプリケーションをテストをする為の関数とマクロ

※ http-test-get-instance-by-oidを利用するには、id属性にslot idを指定したタグでslotの値を囲む必要があります。slot idはslot-idにて取得可能です。

genpagesマクロで作成したアプリケーションのテスト

アプリケーションコード

(eval-when (:compile-toplevel :load-toplevel :execute)
  (asdf:oos 'asdf:load-op :web4r))

(in-package :cl-user)
(defpackage :wiki (:use :cl :web4r))
(in-package :wiki)

(ele:open-store *example-bdb*)

(defpclass wiki ()
  ((title :length 256 :index t)
   (body  :length 3000)))
(genpages wiki)

(start-server)

テストコード

(let ((class 'wiki))
  (with-new-cookie
    (let ((oid (http-test-make-instance class :title "title1" :body "body1")))
      (http-test-get-instance-by-oid class oid)
      (http-test-update-instance class oid '((title . "title1c") (body . "body1c")))
      (http-test-drop-instance-by-oid class oid))))

Tutorial Part 9で作成した認証付きblogアプリケーションのテスト

テストコード

(let ((class 'blog)
      (id    "user1")
      (pass  "pass1"))
  (with-new-cookie
    (http-test-regist `((id    . ,id)
                        (pass  . ,pass)
                        (email . "1@1.com")
                        (blog-title . "user1's blog")))
    (http-test-login :id id :pass pass)
    (let ((oid (http-test-make-instance class :title "title1" :body "body1")))
      (http-test-get-instance-by-oid class oid)
      (http-test-update-instance class oid '((title . "title1c") (body . "body1c")))
      (http-test-drop-instance-by-oid class oid))
    (http-test-logout)))

デバッグモード

debug-mode-onはデバッグモードを開始し、debug-mode-offはデバッグモードを終了します。

デバッグモードはエラー発生時に次の2つのことを行います。

  1. Lispエラーの内容をHTTP経由でHTMLとして表示
  2. Lispエラーとそのバックトレースを*debug-log-file*に記録