17
Daniel Davis Daniel Davis @ourmaninjapan @ourmaninjapan Testharness.js Testharness.js の基礎 の基礎

testharness.js の基礎

Embed Size (px)

DESCRIPTION

W3C の Web テストを行うため、testharness.js が必要になります。このプレゼンで testharness.js の基本情報と使い方を紹介します。

Citation preview

Page 1: testharness.js の基礎

Daniel DavisDaniel Davis

@ourmaninjapan@ourmaninjapan

Testharness.jsTestharness.js の基礎の基礎

Page 2: testharness.js の基礎

テストの悪い事例テストの悪い事例

Page 3: testharness.js の基礎
Page 4: testharness.js の基礎

やっぱりロボットがほしい!

Page 5: testharness.js の基礎

testharness.jstestharness.js はは

あなたのあなたの

ロボットロボット

Page 6: testharness.js の基礎

最終的に…最終的に…

信頼できる、統一性のあるブラウザがほしい。信頼できる、統一性のあるブラウザがほしい。

Page 7: testharness.js の基礎

そのため…そのため…

信頼できる、統一性のあるテストが必要。信頼できる、統一性のあるテストが必要。

Page 8: testharness.js の基礎

そのため、こういうテストが必要そのため、こういうテストが必要

Page 9: testharness.js の基礎

良い良い WebWeb テストの必須項目テストの必須項目

•   WebWeb プラットフォームのテストスイートプラットフォームのテストスイート

•   testharness.jstestharness.js 等等

• 対象メソッド、要素、属性等 対象メソッド、要素、属性等

• テストコード自体 テストコード自体

Page 10: testharness.js の基礎

testharness.jstestharness.js のパッケージのパッケージ

•   testharness.jstestharness.js 等を等を /resources/resources に入れるに入れる

• できればローカルサーバーで実行する できればローカルサーバーで実行する

•   id=”log”id=”log” の要素を作るの要素を作る

• テストを書く テストを書く

Page 11: testharness.js の基礎

testharness.jstestharness.js の使い方の使い方

• なるべくシンプルに なるべくシンプルに

•   test()test() とと async_test()async_test() が使えるが使える

•   assert_assert_ 何とか 何とか == 「◯◯なのか」「◯◯なのか」

• 各テストは条件とタイトルが必要 各テストは条件とタイトルが必要

• 既存のテストをパクった方が楽 既存のテストをパクった方が楽

• テストを先に書きましょう テストを先に書きましょう

Page 12: testharness.js の基礎

Demo timeDemo time

Page 13: testharness.js の基礎

サンプルサンプル

<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>

Page 14: testharness.js の基礎

テストの種類テストの種類

assert_trueassert_true

assert_falseassert_false

assert_equalsassert_equals

assert_not_equalsassert_not_equals

……

Page 15: testharness.js の基礎

参考参考

• /webstorage//webstorage/

• /XMLHttpRequest//XMLHttpRequest/

/html/dom/elements/global-attributes//html/dom/elements/global-attributes/

Page 16: testharness.js の基礎

おまけおまけ

おすすめの簡単なサーバー:おすすめの簡単なサーバー:

python -m SimpleHTTPServerpython -m SimpleHTTPServer

Page 17: testharness.js の基礎

リンク集リンク集

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