- 追加された行はこの色です。
- 削除された行はこの色です。
**目次 [#z93ea414]
#contents
** Jsunit [#f47075b4]
|カテゴリー|Jsunit|
|優先順位|至急|
|イテレーション|[[イテレーション1]]|
|状態|完了|
|完了予定日|2007/10/5|
|工数||
|対応者|清原|
----
**使い方 [#b783e9c7]
テストケースの作成
jsUnitCore.jsをロードする
-「test」で始まるメソッドを作成しテスト内容を記述する
テスト内容では以下のassertion関数が使用できる
|関数|説明|
|assert([comment], booleanValue)|booleanValueがTrueか|
|assertTrue([comment], booleanValue)|assertと同意|
|assertFalse([comment], booleanValue)|booleanValueがFalseか|
|assertEquals([comment], value1, value2)|value2==value1か|
|assertNotEquals([comment], value1, value2)|value2!=value1か|
|assertNull([comment], value)|value==Nullか|
|assertNotNull([comment], value)|value!=Nullか|
|assertUndefined([comment], value)|value==Undefinedか|
|assertNotUndefined([comment], value)|value!=Undefinedか|
|assertNaN([comment], value)|value==NaNか|
|assertNotNaN([comment], value)|value!=NaNか|
|fail(comment)|必ずエラーにする|
-テストケースの実行
testRunner.htmlをブラウザで起動し、テストケースを記述したファイルを選択しRunで実行
-テストケースファイルが複数あり、一度で実行する場合
TestSuiteを作成
suite()メソッドを作成し、メソッド内でjsUnitTestSuiteクラスを生成し、各テストケースファイルを追加する
**作成したテストケース [#v21c768b]
今回はtest-div.htmlとtest-pytha.htmlの2つのテストケースを用意した
以下はtest-pytha.html
<html>
<head>
<script language="javascript" src="../../jsunit/jsunit/app/jsUnitCore.js"></script>
<script language="javascript" src="CalcClass.js"></script>
</head>
<body>
<script language="javascript">
function testAbnormalpytha(){
var max =999999999999999999......(ものスゴく巨大な数字)
assertEquals('10:x = positiveInfinity y = 5','InfinityError',pythagoras(max,5));
assertEquals('11:x = 49 y = negativeInfinity','InfinityError',pythagoras(49,-(max)))
assertEquals('12:NotNumber','NotNumber',pythagoras('r',9));
assertEquals('13:Empty','ArgumentEmptyError',pythagoras('',5));
assertEquals('14:NotNumber','NotNumber',pythagoras('0.00.3',5));
}
function testNormalpytha(){
assertEquals("17:x = -2.2 y = 3",Math.sqrt(13.84),pythagoras(-2.2,3));
assertEquals('18:x = 4 y = 2',Math.sqrt(20),pythagoras(4,2));
assertEquals('19:x = 3 y = 5',Math.sqrt(34),pythagoras(3,5));
assertEquals('20:x = 10 y = 9',Math.sqrt(181),pythagoras(10,9));
assertEquals('21:x = 2 y = -6',Math.sqrt(40),pythagoras(2,-6));
}
</script>
</body>
</html>
-test-suite.html
<html>
<head>
<script language="javascript" src="../../jsunit/jsunit/app/jsUnitCore.js"></script>
<script language="javascript" type="text/javascript">
function suite(){
var newsuite = new top.jsUnitTestSuite();
newsuite.addTestPage("../../training/js/test-div.html");
newsuite.addTestPage("../../training/js/test-pytha.html");
return newsuite;
}
</script>
</head>
<body>
</body>
</html>