Weitere ähnliche Inhalte Ähnlich wie Reloaded (20) Mehr von Shunsaku Kudo (8) Kürzlich hochgeladen (20) Reloaded4. quot; Have you ever had a dream,
Neo, that you were so sure was
real?
What if you were unable to wake
from that dream, Neo?
How would you know the
difference between the dream
world and the real. quot;
Morpheus
6. Water Fall
• 予測、目録
• 大量のドキュメント
– 変更ができない、実際との乖離
– フィードバックの欠如
• 欠陥、浪費
• プレッシャー、ストレス
• 繰り返す、雪だるま式、混沌
11. Antithesis
• Agile
– http://www.agilealliance.com/
• eXtreme Programming
– XP
– http://www.xprogramming.com/
– http://www.xpjug.org/
– Test-Driven Development (TDD)
17. JUnitでテストをつくろう
• サブクラスを作ってテストを書きます。
– junit.framework.TestCase
– テストクラス名は、Testで終わる名前にします。
– XxxTest
• メソッド内にテストする内容を書きます。
– メソッド名は、testで始まる名前にします。
– testXxx
– テストは、Assertクラスのアサーションメソッドを使い
ます。
– junit.framework.Assert
20. JUnitの実行
• TestRunner
– junit.textui.TestRunner
– junit.swingui.TestRunner
public static void main(String[] args) {
junit.textui.TestRunner.run(StringConcatenationTest.class);
}
C:¥>java junit.textui.TestRunner StringConcatenationTest
C:¥>java junit.swingui.TestRunner
26. テスト1:二つの文字列が空。
• まずは、このテストコードを書きます。
• assertEquals 二つの値が等しいか?
public void testEmpty() {
assertEquals(quot;quot;, cat.concatenate(quot;quot;, quot;quot;));
}
• まだ、コンパイルはできません。
• 次にコードを書きましょう。
27. 実装1:二つの文字列が空。
• コンパイルできるようにコードを書きます。
• とりあえず、nullを返すようにしました。
public String concatenate(String left, String right) {
return null;
}
• さあ、コンパイルしてテストしてみましょ。
• どうでしたか?
29. 再実装1:二つの文字列が空。
• テストは、空文字列を期待しているので、
それを返すようにしました。
public String concatenate(String left, String right) {
return quot;quot;;
}
• さあ、もう一回テストをしましょ。
• 今度は… グリーン?
32. 実装2:最初の文字列が空。
• テストが成功しないので、先ほどの実装を
また変えます。
• 両方のテストが通るようにするには…
public String concatenate(String left, String right) {
return right;
}
• さあどうでしょう?
33. テスト3:二番目の文字列が空。
• ここまでで二つのテストが成功しました。
• 今度は、このテストコードを書きます。
public void testRightEmpty() {
assertEquals(quot;abcquot;, cat.concatenate(quot;abcquot;, quot;quot;));
}
• これでテストするともちろん…
34. 実装3:二番目の文字列が空。
• 今度はどうしましょう。
• テストを3つとも成功させるには…
public String concatenate(String left, String right) {
if ( right.length() == 0) {
return left;
}
return right;
}
36. 実装4:両方とも空ではない。
• すべてのテスト成功させるには…
public String concatenate(String left, String right) {
if (right.length() > 0 && left.length() > 0 ) {
return left + right;
} else if ( right.length() == 0) {
return left;
}
return right;
}
• グリーン?そしてクリーン?
37. 実装5:お掃除
• コードが重複しているような気が…
• right が空だったら、
– quot;leftquot; = quot;leftquot; + quot;rightquot;
public String concatenate(String left, String right) {
if (left.length() > 0 ) {
return left + right;
}
return right;
}
• これもグリーン?そしてクリーン?
38. 実装6:お掃除の続き
• left が空だったら、
– quot; right quot; = quot;leftquot; + quot;rightquot;
public String concatenate(String left, String right) {
return left + right;
}
• これはシンプル!クリーン!
• そして、これもグリーン?
41. Real Cycle
• Outline the test we will need
• Then
– Write a test
– Make it compile
– Make it run
– Eliminate all duplication
– Repeat
42. quot; There is a difference
between knowing the road
and following it. quot;
Morpheus
44. スタックのイメージ
• オブジェクトを挿入
– push( Object obj )
• オブジェクトを取り出す
– pop( )
• スタックが空かどうかを真/偽で返す
– isEmpty( )
• スタックのサイズを返す
– size( )
46. スタック step1
• test
public void testEmpty() {
assertTrue(stack.isEmpty()); // step 1
}
• implementation
public boolean isEmpty() {
return true; // step 1
}
47. スタック step2
• test
public void testEmpty() {
…
assertEquals(0, stack.size()); // step 2
}
• implementation
public int size() {
return 0; // step 2
}
48. スタック step3
• test
public void testOneIn() {
stack.push(new String(quot;firstquot;)); // step 3
}
• implementation
public void push(Object o) { // step 3
}
50. スタック step4 impl.
private boolean empty_ ; // step 4
public Stack() {
empty_ = true; // step 4
}
public boolean isEmpty() {
return empty_; // step 4
}
public void push(Object o) {
empty_ = false; // step 4
}
52. スタック step5 impl.
private List stack_; // step 5
public Stack() {
stack_ = new ArrayList(); // step 5
}
public boolean isEmpty() {
if ( stack_.size() > 0) { // step 5
return false;
}
return true;
}
public void push(Object o) {
…
stack_.add(o); // step 5
}
53. スタック step6
• test
public void testOneInAndOutEmpty() {
stack.push(new String(quot;firstquot;));
stack.pop(); // step 6
}
• implementation
public Object pop() {
return new Object(); // step 6
}
54. スタック step7
• test
public void testOneInAndOutEmpty() {
…
assertTrue(stack.isEmpty()); // step 7
}
• implementation
public Object pop() {
return stack_.remove(size()-1); // step 7
}
55. スタック step8
• test
public void testLastInFirstOut() {
stack.push(new String(quot;firstquot;));
stack.push(new String(quot;secondquot;));
stack.push(new String(quot;thirdquot;));
assertEquals(quot;thirdquot;, stack.pop()); // step 8
}
• Implementation
– Remains as it is.
56. スタック step9
• test
public void testLastInFirstOut() {
…
assertEquals(quot;secondquot;, stack.pop());
assertEquals(quot;firstquot;, stack.pop()); // step 9
}
• Implementation
– Remains as it is.
57. スタック step10
• clean
public boolean isEmpty() {
return stack_.isEmpty(); // step 10
}
58. スタック step excessive
public void testLastInFirstOutAndFirstInLastOut () {
assertTrue(stack.isEmpty());
assertEquals(0, stack.size());
stack.push(new String(quot;firstquot;));
assertFalse(stack.isEmpty());
assertEquals(1, stack.size());
stack.push(new String(quot;secondquot;));
assertEquals(2, stack.size());
stack.push(new String(quot;thirdquot;));
assertEquals(3, stack.size());
assertEquals(quot;thirdquot;, stack.pop());
assertEquals(2, stack.size());
assertEquals(quot;secondquot;, stack.pop());
assertEquals(1, stack.size());
assertEquals(quot;firstquot;, stack.pop());
assertEquals(0, stack.size());
assertTrue(stack.isEmpty());
}
60. quot; Denial is the most
predictable of all human
response. quot;
The Architect
61. quot; To deny our own
impulses is to deny the
very things that makes us
human. quot;
Mouse
72. quot; Touch me and that hand
will never touch anything
again. quot;
Trinity
73. Eclipse
• IDE
– Integrated Development Environment
– 統合開発環境
– Javaの開発も可能
• オープンソースプロジェクト
– eclipse.org
– 当初IBMにより開発
• プラグインにより拡張
– 様々なプラグインが公開されている
74. Eclipse で JUnit
• JUnit プラグイン が組み込まれています。
• Ctrl + S
– セーブとコンパイル
• Ctrl + F11
– 前回の実行。
75. Ant
• ビルド・ツール
– UNIXでのquot;makequot;ツールみたいなもの
• Java-based
– Ant自身がJavaでできている
– Java開発環境での必須標準ビルドツール
– 標準でいくつかのタスクが用意されている
– 拡張も可能
• build.xml
77. CVS
• Concurrent Versions System
• バージョン管理ツール
– UNIXでのquot;SCCSquot;やquot;RCSquot;みたいなもの
• ファイルのリポジトリ(保管場所)
• サーバー・クライアントで使える。
– WinCVS, TortoiseCVS, …
• チームでの開発に特に有効
81. quot; How many people keep
silver bullets in their gun? quot;
Persephone
88. Bibliography
• Rebirth
– Kent Beck
– http://www.tech-arts.co.jp/xp/Rebirth.pdf
• Test-Driven Development
– Kent Beck
– TDD Training text [2002/09/11-12]
– http://www.tech-arts.co.jp/training/topics.html
– 但し、テキストは公開されていないようです。
91. Resources
• http://www.junit.org/
• http://www.eclipse.org/
• http://ant.apache.org/
• http://www.cvshome.org/
• http://www.wincvs.org/
• http://www.tortoisecvs.org/
• http://maven.apache.org/
• http://subversion.tigris.org/
• http://rapidsvn.tigris.org/
• http://xdoclet.sourceforge.net/
• http://www.xprogramming.com/software.htm
94. quot; But I can only show you
the door, you have to walk
through it. quot;
Morpheus