Skip to main content
Daniel DavisDaniel Davis
@ourmaninjapan@ourmaninjapan
Testharness.jsTestharness.js の基礎の基礎
テストの悪い事例テストの悪い事例
やっぱりロボットがほしい!
testharness.jstestharness.js はは
あなたのあなたの
ロボットロボット
最終的に…最終的に…
信頼できる、統一性のあるブラウザがほしい。信頼できる、統一性のあるブラウザがほしい。
そのため…そのため…
信頼できる、統一性のあるテストが必要。信頼できる、統一性のあるテストが必要。
そのため、こういうテストが必要そのため、こういうテストが必要
良い良い WebWeb テストの必須項目テストの必須項目
•
   WebWeb プラットフォームのテストスイートプラットフォームのテストスイート
•
   testharness.jstestharness.js 等等
•
 対象メソッド、要素、属性等 対象メソッド、要素、属性等
•
 テストコード自体 テストコード自体
testharness.jstestharness.js のパッケージのパッケージ
•
   testharness.jstestharness.js 等を等を /resources/resources に入れるに入れる
•
 できればローカルサーバーで実行する できればローカルサーバーで実行する
•
   id=”log”id=”log” の要素を作るの要素を作る
•
 テストを書く テストを書く
testharness.jstestharness.js の使い方の使い方
•
 なるべくシンプルに なるべくシンプルに
•
   test()test() とと async_test()async_test() が使えるが使える
•
   assert_assert_ 何とか何とか == 「◯◯なのか」「◯◯なのか」
•
 各テストは条件とタイトルが必要 各テストは条件とタイトルが必要
•
 既存のテストをパクった方が楽 既存のテストをパクった方が楽
•
 テストを先に書きましょう テストを先に書きましょう
Demo timeDemo time
サンプルサンプル
<div<div id="id="loglog""></div>></div>
<div<div id="id="testEltestEl" class="" class="BobBob""></div>></div>
<script><script>
var testEl = document.getElementById('var testEl = document.getElementById('testEltestEl');');
test(function() {test(function() {
assert_equals(testEl.getAttribute('assert_equals(testEl.getAttribute('classclass'), ''), 'BobBob');');
}, '}, 'Can get class attribute with getAttribute()Can get class attribute with getAttribute()');');
</script></script>
テストの種類テストの種類
assert_trueassert_true
assert_falseassert_false
assert_equalsassert_equals
assert_not_equalsassert_not_equals
……
参考参考
•
/webstorage//webstorage/
•
/XMLHttpRequest//XMLHttpRequest/
/html/dom/elements/global-attributes//html/dom/elements/global-attributes/
おまけおまけ
おすすめの簡単なサーバー:おすすめの簡単なサーバー:
python -m SimpleHTTPServerpython -m SimpleHTTPServer
リンク集リンク集
hoppipolla.co.uk/talks/ttwf/testharness.htmlhoppipolla.co.uk/talks/ttwf/testharness.html
darobin.github.io/test-harness-tutorial/docs/using-testharness.htmldarobin.github.io/test-harness-tutorial/docs/using-testharness.html