Created
March 24, 2012 08:00
-
-
Save nnabeyang/2179858 to your computer and use it in GitHub Desktop.
GitのNotesで文章を管理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 917538814d304a01b750db8c84d3fe0e08c9e435 | |
Author: noriaki watanabe <nabeyang@gmail.com> | |
Date: Thu Mar 22 09:12:22 2012 +0900 | |
initial commit | |
diff --git a/src/unit.rb b/src/unit.rb | |
new file mode 100644 | |
index 0000000..e69de29 | |
commit af6ca73473c77f46a67f5c0e5ecee2aa5985c131 | |
Author: noriaki watanabe <nabeyang@gmail.com> | |
Date: Thu Mar 22 09:16:41 2012 +0900 | |
とは失敗と成功の数を数える | |
Notes: | |
$successes, $failuresを導入 | |
= テストの成功と失敗 | |
テスティング・フレームワークをケント・ベックのテスト駆動開発の方法で開発する。 | |
標準ライブラリにテスティング・フレームワークがある言語の場合は必ずしも必要はないけれども、 | |
ここではテスティング・フレームワークを開発を自分自身のコードのテストを書くようにして開発することを試みる。 | |
== <%= title%> | |
この場合、はじめからテストの成功と失敗が扱える必要がある。 そうでなければフレームワークをテストしているテストは、 | |
フレームワークにテストの成功、失敗などの概念がなくなり、そのフレームワーク自身を使ってテストを書くことができない。 | |
テストの成功と失敗を数えるために、2つのグローバル変数$successes, $failuresを導入する。 | |
//source[<%=subject%>]{ | |
<%=diff%>//} | |
diff --git a/src/unit.rb b/src/unit.rb | |
old mode 100644 | |
new mode 100755 | |
index e69de29..3f3d33d | |
--- a/src/unit.rb | |
+++ b/src/unit.rb | |
@@ -0,0 +1,3 @@ | |
+#!/usr/bin/env ruby | |
+$successes = 0 | |
+$failures = 0 | |
commit f7127bb86f4020d08483c43ca23af375ef718f75 | |
Author: noriaki watanabe <nabeyang@gmail.com> | |
Date: Thu Mar 22 09:25:10 2012 +0900 | |
WasRunを定義 | |
Notes: | |
WasRunクラスの定義 | |
次に具体的なテストケースを考える。はじめのテストケースとして、テストケースインスタンスをrunすると、 | |
テストメソッドが実行されるというテストを書く。このテストケースのクラス名はWasRunとしよう。 | |
//source[<%= subject%>]{ | |
<%= diff%>//} | |
diff --git a/src/unit.rb b/src/unit.rb | |
index 3f3d33d..46325e5 100755 | |
--- a/src/unit.rb | |
+++ b/src/unit.rb | |
@@ -1,3 +1,12 @@ | |
#!/usr/bin/env ruby | |
$successes = 0 | |
$failures = 0 | |
+$wasrun = false | |
+class WasRun | |
+ def initialize name | |
+ $wasrun = false | |
+ @__name__ = name | |
+ end | |
+ def run; test_method end | |
+ def test_method; $wasrun = true end | |
+end | |
commit 5becf58e26c10414852dba338a184efe1a1d99b9 | |
Author: noriaki watanabe <nabeyang@gmail.com> | |
Date: Thu Mar 22 09:31:20 2012 +0900 | |
checkメソッドを追加 | |
Notes: | |
checkメソッドを追加 | |
仕様としてはWasRunは、生成されるときに与えられたnameのテストメソッドを実行するが、 | |
今の実装としては nameにかかわらずテストメソッドtest_methodが実行される。 | |
この仕様と実装の差から成功するテストと失敗するテストが書ける。 | |
//source[<%= subject%>]{ | |
<%= diff%>//} | |
diff --git a/src/unit.rb b/src/unit.rb | |
index 46325e5..bb901e3 100755 | |
--- a/src/unit.rb | |
+++ b/src/unit.rb | |
@@ -10,3 +10,5 @@ def initialize name | |
def run; test_method end | |
def test_method; $wasrun = true end | |
end | |
+ | |
+def check condition;end | |
commit 4d2a5ed1026f90dd6251102f609625a7abfb5ea7 | |
Author: noriaki watanabe <nabeyang@gmail.com> | |
Date: Thu Mar 22 09:33:18 2012 +0900 | |
テストコードの追加 | |
Notes: | |
テストケースの追加 | |
//source[<%= subject%>]{ | |
<%= diff%>//} | |
diff --git a/src/unit.rb b/src/unit.rb | |
index bb901e3..7ab7e30 100755 | |
--- a/src/unit.rb | |
+++ b/src/unit.rb | |
@@ -12,3 +12,18 @@ def test_method; $wasrun = true end | |
end | |
def check condition;end | |
+ | |
+puts "success case" | |
+test = WasRun.new('test_method') | |
+check((not $wasrun)) | |
+test.run | |
+check($wasrun) | |
+puts 'failures:%d' % [$failures] #=> 0 | |
+ | |
+puts "failuar case" | |
+test = WasRun.new('no_such_method') | |
+check((not $wasrun)) | |
+test.run | |
+check((not $wasrun)) | |
+puts 'failures:%d' % [$failures] #=> 1 | |
+puts 'successes+failures=%d' % [$successes+$failures] #=>4 | |
commit fdc4c2708c99dbb0125780d47b4b812df792c3d5 | |
Author: noriaki watanabe <nabeyang@gmail.com> | |
Date: Thu Mar 22 10:04:03 2012 +0900 | |
checkメソッドの実装 | |
Notes: | |
checkメソッドの実装 | |
checkをconditionがtrueのとき$successes、失敗したときは$failuresがインクリメントする | |
メソッドとして定義すると、チェックした回数と失敗した回数が正しく計算できる。 | |
//source[<%= subject%>]{ | |
<%= diff%>//} | |
=== 関連事項 | |
1.定数 | |
2.クラスの定義の仕方 | |
3.グローバル変数 | |
4.initialize | |
5.文字リテラル | |
diff --git a/src/unit.rb b/src/unit.rb | |
index 7ab7e30..20ee203 100755 | |
--- a/src/unit.rb | |
+++ b/src/unit.rb | |
@@ -11,7 +11,13 @@ def run; test_method end | |
def test_method; $wasrun = true end | |
end | |
-def check condition;end | |
+def check condition | |
+ if condition | |
+ $successes += 1 | |
+ else | |
+ $failures += 1 | |
+ end | |
+end | |
puts "success case" | |
test = WasRun.new('test_method') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment