LoginSignup
49
45

More than 5 years have passed since last update.

GoogleAppsScriptでユニットテスト

Last updated at Posted at 2013-11-22

ユニットテストの必要性を感じてきたので調べてみた。

Google Apps Script用Qunitというのがあるらしいので、使ってみます。

まずはライブラリに追加
MxL38OxqIK-B73jyDTvCe-OBao7QLBR4j
library.png
ライブラリダイアログに表示されたらバージョンを4にして保存。

次にdoGetメソッドを書く

doGet.gs
function doGet( e ) {
  QUnit.urlParams( e.parameter );
  QUnit.config({ title: "Unit tests for my project" });
  QUnit.load( myTests );
  return QUnit.getHtml();
};

QUnit.helpers(this);

そしてテストコード。

myTest.gs
function myTests() {
  module("dummy module");

  test("dummy test", 1, function() {
    ok(true);
  });
}

あとは「ウェブアプリケーションとして導入」で「最新のコードでテスト」リンクをクリックすると以下のウェブページが表示されます。
✔ Unit tests for my project.png

あとはQunitの仕様に合わせてmodule、test,ok equalとか notEqualの記述をしていけばいいようです。

Qunitについての詳細はQunit解説サイトでどうぞ。

49
45
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
49
45