Rabbit Slide Show

The history of testing framework in Ruby

2015-12-12

Description

This talk describes about the history of testing framework in Ruby. Ruby 2.2 bundles two testing frameworks. They are minitest and test-unit. Do you know why two testing frameworks are bundled? Do you know that test-unit was bundled and then removed from Ruby distribution? If you can't answer these questions and you're interested in testing framework, this talk will help you. This talk describes about the history of bundled testing framework in Ruby and some major testing frameworks for Ruby in chronological order.

Text

Page: 1

The history of
testing framework
in Ruby
Kouhei Sutou
ClearCode Inc.
RubyKaigi 2015
2015-12-12
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 2

Silver sponsor
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 3

Goal
目標
You know about
/\Atest.+unit\z/i
/\Atest.+unit\z/iを知ること
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 4

Test
テスト
Which Rubies do include
/\Atest.+unit\z/i?
/\Atest.+unit\z/iを含んでいるRubyはどれでしょう?
1.4
1.9.1
2.0
2.3
The history of testing framework in Ruby
1.6
1.9.2
2.1
1.8
1.9.3
2.2
Powered by Rabbit 2.1.9

Page: 5

Answer
答え
Which Rubies do include
/\Atest.+unit\z/i?
/\Atest.+unit\z/iを含んでいるRubyはどれでしょう?
1.4
1.9.1
2.0
2.3
The history of testing framework in Ruby
1.6
1.9.2
2.1
1.8
1.9.3
2.2
Powered by Rabbit 2.1.9

Page: 6

History
歴史

Page: 7

Characters
登場人物
testsupp
Lapidary
Test::Unit
test-unit
RSpec
The history of testing framework in Ruby
RubyUnit
test/unit
minitest
Powered by Rabbit 2.1.9

Page: 8

Ruby 1.3 times
Ruby 1.3の時代
✓ 1998-1999
✓ The first testing framework
for Ruby was released
最初のRuby用のテスティングフレームワークがリリース
✓ testsupp
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 9

testsupp
✓ 1999-4-11: [ruby-talk:00634]
ANN: testsupp.rb 0.1
✓ Perl's Test like API
PerlのTestモジュールのようなAPI
✓ Perl's Test exists since 1998
PerlのTestモジュールは1998からある
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 10

testsupp: API
require "testsupp"
include TestSupp
start_tests
ok "Hello" == "Hello"
end_tests
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 11

Ruby 1.4 times
Ruby 1.4の時代
✓ 1999-2000
✓ The first xUnit testing
framework for Ruby was
released
最初のRuby用のxUnit系テスティングフレームワークが
リリース
✓ RubyUnit
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 12

RubyUnit
✓ Since 1999-11-20 at least
少なくとも1999年11月20日には存在していた
✓ [ruby-list:18594]
"RubyUnit のページは当分更新されないと思うです."
✓ The first xUnit testing
framework for Ruby
最初のRuby用のxUnit系テスティングフレームワーク
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 13

FYI: XP
参考情報:XP
✓ eXtream Programing
✓ The first XP book was
published at 1999
最初のXPの本は1999年に出版
✓ xUnit was born from XP
xUnitはXPが生み出した
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 14

RubyUnit: API
require "runit/testcase"
class TestCalc < RUNIT::TestCase
def test_add
assert_equal(3, 1 + 2)
end
end
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 15

RubyUnit: Impression
感想
Ruby-ish
Rubyっぽい
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 16

RubyUnit: FYI
RubyUnit:参考情報
✓ Test generator exists
テストジェネレーターがある
✓ Test exec command exists
テスト実行コマンドがある
gem exists since 2014-10-12
✓ rubyunit
rubyunitというgemが2014年10月12日から存在する
✓ Not
related product
関係のないプロダクト
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 17

Ruby 1.6 times: 1
Ruby 1.6の時代:1
✓ 2000-2002
✓ The second xUnit testing
framework for Ruby was
released
2つ目のRuby用のxUnit系テスティングフレームワークが
リリース
✓ Lapidary
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 18

Lapidary
✓ The first release was
2001-03-20
最初のリリースは2001年3月20日
✓ The second xUnit testing
framework for Ruby
2つ目のRuby用のxUnit系テスティングフレームワーク
✓ Maybe
たぶん
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 19

Lapidary: API
require "Lapidary/TestCase"
class TC_Adder < Lapidary::TestCase
def testAdd
assertEqual(3, 1 + 2)
end
end
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 20

Lapidary: Impression
感想
Not Ruby-ish
Rubyっぽくない
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 21

Lapidary: FYI
参考情報
✓ Has GUI test runner
GUIのテスト実行機能アリ
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 22

Ruby 1.6 times: 2
Ruby 1.6の時代:2
✓ Started trying to bundle a
testing framework to Ruby
テスティングフレームワークをRubyにバンドルする
試みを開始
✓ RubyUnit + Lapidary = Test::Unit
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 23

Test::Unit
✓ Since 2002-02:
[ruby-talk:34744]
✓ The first /\Atest.+unit\z/i
最初の/\Atest.+unit\z/i
✓ The author is the author of
Lapidary
Lapidaryの作者が作者
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 24

Test::Unit: API
require "test/unit"
class TC_Adder < Test::Unit::TestCase
def test_add
assert_equal(3, 1 + 2)
end
end
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 25

Test::Unit: Impression
感想
Ruby-ish
Rubyっぽい
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 26

Test::Unit: FYI 1
参考情報1
✓ API is based on RubyUnit
APIはRubyUnitのよう
✓ Has RubyUnit compatible API
RubyUnit互換APIアリ
✓ Impl. is based on Lapidary
実装はLapidaryベース
✓ Has GUI test runner
GUIのテスト実行機能アリ
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 27

Wrap up: Before Ruby 1.8
Ruby 1.8の前までのまとめ
✓ testsupp: Perl like API
✓ RubyUnit: Ruby-ish xUnit
✓ Lapidary: Not Ruby-ish xUnit
✓ Test::Unit:
✓ RubyUnit API + Lapidary Impl.
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 28

Ruby 1.8 times: 1
Ruby 1.8の時代:1
✓ 2003-2013
✓ Ruby bundled a testing
framework
Rubyがテスティングフレームワークをバンドルした
✓ Test::Unit aka test/unit
バンドルされたのはTest::Unit
test/unitとも呼ばれる
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 29

FYI: Why test/unit?
参考情報:なぜtest/unitと呼ぶか
require "test/unit"
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 30

Ruby 1.8 times: 2
Ruby 1.8の時代:2
RSpec was born
RSpec誕生
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 31

RSpec
✓ Since 2005-08
✓ Tool for Behavior Driven
Development
振る舞い駆動開発用のツール
✓ Active development
開発は活発
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 32

RSpec 0.1.0: API
# 2005-08
require "spec"
class SpecAdd < Spec::Context
def add
(1 + 2).should_equal 3
end
end
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 33

RSpec: 1.0.0: API
# 2007-05
require "spec"
describe "Add" do
it "should support positive + positive" do
(1 + 2).should == 3
end
end
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 34

RSpec 1.0.0: Impression
感想
Engl-ish
英語っぽい
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 35

RSpec: FYI
参考情報
✓ Test exec command exists
テスト実行コマンドがある
✓ RubyUnit like
RubyUnitみたい
✓ More features
than Test::Unit
Test::Unitより機能が多い
✓ Mock, Not implemented, ...
モックや未実装など
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 36

Test::Unit in Ruby 1.8
Ruby 1.8バンドル後のTest::Unit
✓ No active development
開発は停滞
✓ Maintainer was changed
メンテナー交代
✓ The author of minitest
後のminitestの作者
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 37

RSpec and Test::Unit
✓ RSpec is getting better but
Test::Unit isn't changed...
RSpecはよくなっているのにTest::Unitは変わらない。。。
✓ Test::Unit should also be
getting better!
Test::Unitももっとよくしたい!
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 38

Test::Unit:
new maintainer
新しいメンテナー
✓ New maintainer said:
新メンテナー曰く
✓ Can't maintain Test::Unit because
it's too complex
Test::Unitは複雑すぎてメンテナンスできない
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 39

Wrap up: Ruby 1.8 times
Ruby 1.8時代のまとめ
✓ Ruby started bundling
Test::Unit (/\Atest.+unit\z/i)
RubyがTest::Unitのバンドルを始めた
✓ But Test::Unit was died...
バンドル後、Test::Unitは死んだ。。。
✓ RSpec was born and active
RSpecが生まれ、活発だった
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 40

Ruby 1.9 times
Ruby 1.9の時代
✓ 2009-2014
✓ Ruby dropped Test::Unit
RubyがTest::Unitを捨てた
✓ Because Test::Unit is too complex
for new maintainer
新メンテナーにはTest::Unitは複雑すぎるから
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 41

Test::Unit → test-unit
✓ Released as test-unit gem
test-unit gemとしてリリース
✓ Still /\Atest.+unit\z/i
名前変更後も/\Atest.+unit\z/i
✓ test-unit
1.2.3 == Test::Unit in Ruby 1.8
✓ Maintainer was changed
メンテナー交代
✓ Me
私
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 42

test-unit
✓ Since 2008-03
✓ Active development
開発は活発
✓ High backward compatibility
高い後方互換性
✓ Exception: Inheritance
例外:継承時の挙動
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 43

minitest
✓ Since 2008-10
✓ Active development
開発は活発
✓ The author is the new
maintainer of Test::Unit
作者はTest::Unitの新メンテナー
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 44

minitest and Test::Unit
✓ Mini, simple, clean and fast
小さくてシンプルでキレイで速い
✓ The author said:
作者曰く
✓ 100% Test::Unit compatible
Test::Unitと100%互換
✓ But it's not compat in fact...
実際は互換ではなかった。。。
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 45

test/unit in Ruby 1.9
✓ Provide Test::Unit API
Test::Unit互換APIを提供
✓ Wrapper of minitest
minitestのラッパー
✓ Ruby developers developed it
not minitest author
minitestの作者ではなくRuby開発者が開発
✓ Not Test::Unit
but /\Atest.+unit\z/i
Test::Unitではないが/\Atest.+unit\z/iではある
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 46

Wrap up: Ruby 1.9 times
Ruby 1.9時代のまとめ
✓ Ruby dropped Test::Unit
RubyがTest::Unitを捨てた
✓ Test::Unit
→ test-unit gem
✓ Ruby bundled minitest
Rubyはminitestをバンドルした
✓ Ruby created test/unit
(test/unit provided Test::Unit API)
RubyはTest::Unit APIを提供するtest/unitを新しく作った
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 47

Ruby 2.0 times
Ruby 2.0の時代
✓ 2013-
✓ No highly important things
特筆すべきことはない
✓ test-unit, minitest and RSpec
were actively developed
test-unitもminitestもRSpecも活発に開発が進んでいた
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 48

Ruby 2.1 times: 1
Ruby 2.1の時代:1
✓ 2013-
✓ minitest 5 introduced
incompatible changes
minitest 5で非互換の変更が入った
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 49

minitest 5
✓ test/unit maintainer said:
test/unitメンテナー曰く
✓ Can't maintain test/unit with
minitest 5
minitest 5向けのtest/unitはメンテナンスできない
✓ test/unit for minitest was
dropped
minitestのラッパーとしてのtest/unitを捨てた
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 50

Is no test/unit problem?
test/unitがないことは問題なのか?
✓ Ruby used test/unit for
Ruby's tests
RubyはRubyのテストにtest/unitを使っていた
✓ No test/unit means existing tests
can't be worked
test/unitがなくなると既存のテストが動かない
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 51

Solution idea: 1
解決案:1
✓ Keep bundling and using
minitest 4
minitest 4のバンドルを継続し、使い続ける
✓ Users will be confused because
the latest Ruby doesn't bundle
the latest minitest
最新のRubyに最新のminitestがバンドルされていないと
ユーザーは混乱しそう
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 52

Solution idea: 2
解決案:2
✓ Bundle the latest minitest
最新のminitestをバンドルする
✓ Ruby uses minitest 4 and test/
unit for its tests
Rubyのテストにはminitest 4とtest/unitを使う
Accepted!
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 53

Note for idea 2
案2の補足
✓ Need to care existing
Test::Unit API users
既存のTest::Unit APIユーザーをケアする必要がある
✓ Backward compat is important!
後方互換性は重要!
✓ Bundle test-unit gem too for
Test::Unit API
Test::Unit互換APIのためにtest-unit gemもバンドル
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 54

Wrap up: Ruby 2.1 times
Ruby 2.1時代のまとめ
✓ Ruby developers decided to
maintain minitest 4 and test/
unit for Ruby's tests
Ruby開発者はRubyのテスト用にminitest 4とtest/unitをメ
ンテナンスすることを決めた
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 55

Ruby 2.2 times: 1
Ruby 2.2の時代:1
✓ 2014-
✓ Upgraded bundled minitest to
5
バンドルしているminitestを5に更新
✓ Moved minitest 4 and test/unit to
test/
minitest 4とtest/unitはtest/以下に移動
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 56

Upgraded minitest to 5
minitest 5に更新
-
lib/minitest/*.rb
+ test/lib/minitest/*.rb
-
lib/test/unit.rb
+ test/lib/test/unit.rb
-
lib/test/unit/**/*.rb
+ test/lib/test/unit/**/*.rb
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 57

Ruby 2.2 times: 2
Ruby 2.2の時代:2
✓ Bundled test-unit gem again
for users
再びtest-unit gemをバンドル
✓ Ruby 1.9 dropped test-unit gem
Ruby 1.9はtest-unit gemを捨てた
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 58

Bundled test-unit again
test-unitを再びバンドル
test-unit gem provides:
lib/test-unit.rb
lib/test/unit.rb
lib/test/unit/**/*.rb
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 59

test/unit in Ruby 2.2
Ruby 2.2のtest/unit
✓ For Ruby developers
Ruby開発者にとっては
✓ test/lib/test/unit
✓ For users
ユーザーにとっては
✓ lib/test/unit = test-unit gem
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 60

FYI: test/lib/test/unit
✓ Includes useful features for
Ruby's tests
Ruby本体のテストに便利な機能が入っている
✓ Leak checker for file descriptor,
thread, process...
リークチェッカー:ファイルディスクリプターやスレッ
ドのリークやゾンビプロセスを検出
✓ Memory usage profiler
メモリー使用量のプロファイラー
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 61

Wrap up: Ruby 2.2 times
Ruby 2.2時代のまとめ
✓ Bundled minitest 5
minitest 5をバンドル
✓ Bundled test-unit again
再びtest-unitをバンドル
✓ Ruby's tests used forked
mintiest 4 and test/unit
Rubyのテストはフォークしたminitest 4とtest/unitを使う
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 62

Ruby 2.3 times
Ruby 2.3の時代
✓ 2015-
✓ No highly important things
特筆すべきことはない
✓ test-unit, minitest, test/lib/
test/unit and RSpec were actively
developed
test-unitもminitestもtest/lib/test/unitもRSpecも活
発に開発が進んでいた
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 63

Wrap up: History: 1
歴史のまとめ:1
✓ Ruby 1.4 and 1.6 didn't
bundle any testing framework
Ruby 1.4と1.6はテスティングフレームワークをバンドル
していなかった
✓ Test::Unit was born in Ruby
1.6 times
Ruby 1.6の時代にTest::Unitが生まれた
✓ The first /\Atest.+unit\z/i
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 64

Wrap up: History: 2
歴史のまとめ:2
✓ Ruby 1.8 bundled Test::Unit
Ruby 1.8はTest::Unitをバンドルした
✓ /\Atest.+unit\z/i in 1.8
✓ Ruby 1.9 dropped Test::Unit
and bundled minitest
Ruby 1.9はTest::Unitを捨ててminitestをバンドルした
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 65

Wrap up: History: 3
歴史のまとめ:3
✓ Ruby 1.9 provided test/unit
as a wrapper of minitest
Ruby 1.9はminitestのラッパーとしてtest/unitを提供した
✓ test/unit provided Test::Unit
compatible API
test/unitはTest::Unitの互換APIを提供した
✓ /\Atest.+unit\z/i in 1.9
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 66

Wrap up: History: 4
歴史のまとめ:4
✓ Ruby 2.0 is same as Ruby 1.9
Ruby 2.0の状況はRuby 1.9と変わらない
✓ test/unit is /\Atest.+unit\z/i in
2.0
つまり、2.0での/\Atest.+unit\z/iはtest/unit
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 67

Wrap up: History: 5
歴史のまとめ:5
✓ Ruby 2.1 didn't upgrade
minitest to 5
Ruby 2.1はminitestを5に更新しなかった
✓ minitest 5 has backward
incompatible changes
minitest 5には後方非互換の変更があった
✓ They break Ruby's tests
非互換を受け入れるとRubyのテストが動かなくなる
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 68

Wrap up: History: 6
歴史のまとめ:6
✓ Ruby 2.2 upgraded minitest
Ruby 2.2はminitestを5に更新した
✓ Dropped test/unit as minitest
wrapper
Ruby 2.2はminitestのラッパーのtest/unitを捨てた
✓ Used forked minitest 4 and test/
unit for its tests
Ruby 2.2はRubyのテスト用にminitest 4のフォークと
test/unitを使うことにした
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 69

Wrap up: History: 7
歴史のまとめ:7
✓ Ruby 2.2 bundled test-unit
gem again
Ruby 2.2はtest-unit gemを再びバンドルした
✓ /\Atest.+unit\z/i in 2.2
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 70

Wrap up: History: 8
歴史のまとめ:8
✓ test/lib/test/unit was
evolved for Ruby's tests
test/lib/test/unitはRubyのテスト用に進化した
✓ /\Atest.+unit\z/i in 2.2 too
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 71

Wrap up: History: 9
歴史のまとめ:9
✓ No highly important things
in Ruby 2.3
Ruby 2.3には特筆すべきことはない
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 72

What's /\Atest.+unit\z/i
/\Atest.+unit\z/iはなにか
Test::Unit
compatible API
Test::Unit互換API
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 73

Test::Unit compat API
Test::Unit互換API
class XXXTest < Test::Unit::TestCase
def test_xxx
assert_equal(xxx, yyy)
end
end
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 74

Test::Unit API spirit
Test::Unit APIの魂
Ruby-ish
Rubyらしさ
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 75

Ruby-ish in Test::Unit
Test::UnitでのRubyらしさ
✓ Write test as normal Ruby
script
普通のRubyスクリプトのようにテストを書ける
✓ It's important in minitest too
minitestもこれを大事にしている
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 76

By example: 1
実例:1
Grouping tests
テストのグループ化
↓
class
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 77

Group: 1
グループ化:1
class TestAdd < Test::Unit::TestCase
def test_positive_positive
assert_equal(3, 1 + 2)
end
def test_positive_negative
assert_equal(-2, 1 + -3)
end
end
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 78

Group: 2
グループ化:2
class TestSub < Test::Unit::TestCase
def test_positive_positive
assert_equal(-2, 1 - 3)
end
def test_positive_negative
assert_equal(4, 1 - -3)
end
end
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 79

Group: 3
グループ化:3
class TestCalc < Test::Unit::TestCase
class TestAdd < self # TestAdd < TestCalc
# def test_positive_positive
# def test_positive_negative
end
class TestSub < self # TestAdd < TestCalc
# def test_positive_positive
# def test_positive_negative
end
end
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 80

Wrap up: Group: 1
グループ化のまとめ:1
✓ Test case has tests
テストケースは複数のテストを持つ
✓ Test case is class
テストケースをクラスとして実装
✓ Test is method
テストをメソッドとして実装
✓ Class has methods
クラスは複数のメソッドを持つ
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 81

Wrap up: Group: 2
グループ化のまとめ:2
✓ Sub test case is sub class
サブテストケースはサブクラスとして実装
✓ Sub test case is-a parent test
case
TestAdd is a test case of TestCalc
サブテストケースは親テストケースとis-aの関係
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 82

FYI: Group
参考情報:グループ化
✓ Test::Unit and minitest
don't support sub test case
is a sub class
Test::Unitとminitestはサブクラスでサブテストケースを
作ることをサポートしていない
✓ test-unit only supports it
test-unitだけがサポートしている
✓ It's the only one incompatible
唯一の非互換
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 83

FYI: Group DSL
参考情報:グループ化DSL
class TestCalc < Test::Unit::TestCase
sub_test_case "+" do
test "positive + negative" {}
end
sub_test_case "-" do
test "positive - negative" {}
end
end
test-unit feature
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 84

By example: 2
実例:2
Share tests
テストの共有
↓
module
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 85

Share: 1
共有:1
module KVSTests
def test_read_write
@kvs[:key] = :value
assert_equal(:value, @kvs[:key])
end
end
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 86

Share: 2
共有:2
class TestKVSHash < Test::Unit::TestCase
include KVSTests
def setup; @kvs = {}; end
end
class TestKVSOpenStruct < Test::Unit::TestCase
include KVSTests
def setup; @kvs = OpenStruct.new; end
end
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 87

Wrap up: Share
共有のまとめ
✓ Tests can be shared by module
モジュールでテストを共有できる
✓ Module is used for sharing method
implementations in Ruby
Rubyではモジュールはメソッドの実装を共有するために
使われている
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 88

By example: 3
実例:3
Assertion
アサーション
↓
Write as-is
そのまま書く
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 89

Assert: Equal
アサート:等価
def test_add
assert_equal(3,
1 + 2)
# ↑↓ as-is
# RSpec: expect(1 + 2).to eq(3)
end
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 90

Assert: Predicate
アサート:述語
def test_exist_readme
assert(File.exist?("README"))
# ↑ as-is ↓ not as-is
# RSpec: expect(File).to exist("README")
end
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 91

Message from minitest
1) Failure:
TestFile#test_exist_readme [test-file-minitest.rb:5]:
Failed assertion, no message given.
Less information
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 92

Message from RSpec
1) File README should exist
Failure/Error: expect(File).to exist("README")
expected File to exist
# ./spec-file.rb:5:in `block (2 levels) in <top (required)>'
Colorized and snippet
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 93

Message from test-unit
Failure: <false> is not true.
test_exist_readme(TestFile)
test-file-test-unit.rb:5:in `test_exist_readme'
2:
3: class TestFile < Test::Unit::TestCase
4: def test_exist_readme
=> 5:
assert(File.exist?("README"))
6: end
7: end
Colorized and snippet
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 94

power-assert
def test_exist_readme
assert do # ↓ as-is
File.exist?("README")
end
end
Built-in in test-unit
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 95

Message: power-assert
Failure:
File.exist?("README")
|
|
|
false
File (NOTE: ← Receiver information)
test_exist_readme(TestFile)
/usr/lib/ruby/vendor_ruby/power_assert.rb:36:in `start'
test-file-power-assert.rb:5:in `test_exist_readme'
2:
3: class TestFile < Test::Unit::TestCase
4:
def test_exist_readme
=> 5:
assert do
6:
File.exist?("README")
7:
end
8:
end
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 96

FYI: test-unit and power-
assert
✓ Don't recommend
"all power-assert"
すべてpower-assertは非推奨
✓ Recommend "power-assert only for
predicate"
述語だけpower-assertを推奨
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 97

Assert: Equal
# @group.users should return
# sorted names of user
assert_equal(user_names.sort,
@group.users)
# ↑ Align-able
assert do
@group.users == user_names.sort
end
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 98

Align
縦に並べる
✓ Indicate compare targets
visually
視覚的に比較対象ということを示す
✓ Clarify differences visually
視覚的に違いを明確にする
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 99

Experiment: 1
実験:1
Find a difference!
違うところを探せ!
Hello | Heilo
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 100

Experiment: 2
実験:2
Find a difference!
違うところを探せ!
Hello
Heilo
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 101

Align in Ruby
Rubyで縦に並べる
# Arguments are natural
method(arg1,
arg2)
# Operands aren't natural
operand1 ==
operand2
引数だと自然だけどオペランドだと不自然
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 102

FYI: test-unit and power-
assert
✓ Don't recommend
"all power-assert"
すべてpower-assertは非推奨
✓ Recommend "power-assert only for
predicate"
述語だけpower-assertを推奨
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 103

FYI: Fixture
参考情報:フィクスチャー
Ensure
clean test
environment
キレイなテスト環境を用意する仕組み
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 104

Fixture: e.g.
フィクスチャー:例
def setup;
p :s;
def teardown; p :t;
def test_1;
p :t1;
def test_2;
p :t2;
# :s -> :t1 -> :t ->
# :s -> :t2 -> :t
The history of testing framework in Ruby
end
end
end
end
Powered by Rabbit 2.1.9

Page: 105

Fixture: Open file
フィクスチャー:ファイルを開く
def setup
@file = File.open("x")
end
def teardown
@file.close
end
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 106

Fixture: Open file
フィクスチャー:ファイルを開く
Not Ruby-ish
Rubyっぽくない
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 107

Fixture: Open File
フィクスチャー:ファイルを開く
def setup # Ruby-ish version
File.open("x") do |file|
@file = file
yield
end # Close file automatically
end
New feature in test-unit
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 108

Wrap up: Test::Unit API
まとめ:Test::Unit API
✓ Ruby-ish is important in
Test::Unit API
Test::Unit APIではRubyらしいことは重要
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 109

Wrap up: Test::Unit API
まとめ:Test::Unit API
✓ (Sub) test case by
class
(sub)
(サブ)テストケースには(サブ)クラスを使う
✓ Share tests by module
テストの共有にはモジュールを使う
✓ as-is in assert
アサートではそのままの使い方で書く
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 110

Wrap up: Test::Unit API
まとめ:Test::Unit API
✓ More Ruby-ish
さらにRubyっぽく
✓ Support block based fixture
ブロックを使ったフィクスチャーもサポート
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Page: 111

Goal
目標
You know about
/\Atest.+unit\z/i
/\Atest.+unit\z/iを知ること
The history of testing framework in Ruby
Powered by Rabbit 2.1.9

Other slides

Apache Arrow Apache Arrow
2018-12-08
Apache Arrow Apache Arrow
2018-11-17
Apache Arrow Apache Arrow
2017-06-13
Apache Arrow Apache Arrow
2017-05-28
Mroonga! Mroonga!
2015-10-30