[clojure] lein-autoexpectで自動テスト[plugin]

2013.08.14

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

ソース変更での自動テスト実行

lein-autoexpectは、ソース変更を検知して自動でテストを実行してくれる、leiningen用のプラグインです。
もともとleiningenを使っていればテスト実行は楽ですが、このプラグインを使うことでさらに楽になります。

環境構築方法

今回使用した動作環境は以下のとおりです。

  • OS : MacOS X 10.7.5
  • leiningen : 2.3.1

leinコマンドが使える状態にしておいてください。

lein-autoexpectを試してみる

最初からプロジェクトを作ってもいいのですが、Githubからcloneしてくればそのまま試すことができるので、
持ってきてしまいましょう。

% git clone git@github.com:jakemcc/lein-autoexpect.git

次に、設定ファイル(~/.lein/profiles.clj)に、autoexpectプラグインを追加します。

#peofiles.cljに追加
{:user {:plugins [[lein-autoexpect "1.0"]]}}

project.cljを下記のように編集し、lein depsコマンドを実行しておきましょう。

#project.clj
(defproject lein2 "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.5.1"]]
  :plugins [[lein-autoexpect "1.0"]]
  :profiles {:dev {:dependencies [[expectations "1.4.52"]]}})

lein-autoexpect/lein2ディレクトリに移動し、下記のようにautoexpectコマンドを実行してみましょう。
すでにtest/lein2ディレクトリにはテストが用意してあり、そのテストが実行された後、ファイル変更を待ち受けます。

% cd lein-autoexpect/lein2 
% lein autoexpect                                                                                                                                [~/lein-autoexpect/lein2:20:37]
*********************************************
*************** Running tests ***************

Ran 1 tests containing 1 assertions in 25 msecs
0 failures, 0 errors.

コンソールをこの状態にしておき、src/lein2/core.cljやtest/lein2/sample_expectations.cljを編集してみましょう。
そのたびにテストが実行され、結果がコンソールに表示されます。
いちいちtestコマンドを実行しなくてすむので、楽ですね。

参考サイトなど