はじめに
おはようございます。当ブログにアクセス頂き、ありがとうございます。夜6時以降は炭水化物を摂取しない、たなけんです。本エントリでは、アプリケーションのテスト(3)について記載します。アプリケーションのテスト(3)
関数の機能を変更したため、テストコードも変更しました。テスト事項は以下となります。
- interface-for-clientのテスト
- call-apiのテスト
- 抽出関数のテスト
- test/data/test-dictionary.xml
- test/data/test-thesaurus.xml
- test/data/test-slang.xml
- test/data/test-etymology.xml
- test/data/test-example.xml
- test/data/test-questionanswer.xml
- test/data/test-synonym.xml
- test/data/test-random-dictionary.xml
- test/data/test-random-thesaurus.xml
- test/data/test-spelling.xml
- test/data/test-wotd.xml
interface-for-clientのテスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(deftest test-interfece-for-client-dictionary | |
(is (:status (interface-for-client {:request-method :get :uri "/dictionary/define/test"})) | |
200)) |
httpのGETリクエストからcall-apiを呼び出し、正常に処理されることを確認します。
call-apiのテスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(deftest test-call-api | |
(is (call-api root-url (list [:vid (:vid test-properties)] ["q" "test"] ["type" "define"] ["site" "dictionary"]) extract-dictionary) | |
(json/generate-string test-dictionary-result))) |
url、パラメータ及び抽出関数を引数に、call-apiが期待する動作をするかどうかを確認します。
抽出関数のテスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(deftest test-extract-dictionary | |
(is (extract-dictionary test-dictionary-xml) | |
test-dictionary-result)) | |
(deftest test-extract-example | |
(is (extract-example test-example-xml) | |
test-example-result)) | |
(deftest test-extract-spelling | |
(is (extract-spelling test-spelling-xml) | |
test-spelling-result)) | |
(def test-dictionary-result {:word "test", :entries '({:pos "noun", :text "the means used to determine the quality, content, etc., of something"} {:pos "noun", :text "examination to evaluate a student or class"} {:pos "verb (used with object)", :text "to subject to a test"})}) | |
(def test-example-result {:word "test", :entries '("noun : to put to the test. <br>verb (used without object) : People test better in a relaxed environment. <ex>,</ex>to test for diabetes. <br>.")}) | |
(def test-spelling-result {:word "teest", :entries '("testy" "tees" "weest" "deist" "doest" "toast" "reset" "retest" "tersest" "truest" "teased" "teat" "tee's" "teed" "tests" "Tevet" "detest" "tenet" "tester" "tweet" "teats" "Tet" "taste" "tasty" "EST" "beset" "desert" "est" "tamest" "DST" "teds" "Tess" "Tues" "teas" "text" "ties" "toes" "attest" "Ted's")}) |
与えられたxmlから、期待される値が抽出されることを確認します。
また期待される値を定数として定義します。
テストデータの登録
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def test-dictionary-xml (slurp "test/data/test-dictionary.xml")) | |
(def test-thesaurus-xml (slurp "test/data/test-thesaurus.xml")) | |
(def test-slang-xml (slurp "test/data/test-slang.xml")) | |
(def test-etymology-xml (slurp "test/data/test-etymology.xml")) | |
(def test-example-xml (slurp "test/data/test-example.xml")) | |
(def test-questionanswer-xml (slurp "test/data/test-questionanswer.xml")) | |
(def test-synonym-xml (slurp "test/data/test-synonym.xml")) | |
(def test-random-dictionary-xml (slurp "test/data/test-random-dictionary.xml")) | |
(def test-random-thesaurus-xml (slurp "test/data/test-random-thesaurus.xml")) | |
(def test-spelling-xml (slurp "test/data/test-spelling.xml")) | |
(def test-thesaurus-xml (slurp "test/data/test-wotd.xml")) |
Dictionary.comの各APIにアクセスした際に取得されるxmlを定義します。
今回の作業は以上。最後までお読み頂きありがとうございました。
たなけん (作業時間30分)
0 件のコメント:
コメントを投稿