Introduction to ATDD with Cucumber and RSpec

48
Introduction to ATDD with Cucumber and RSpec Cucumber RSpec による ATDD 入門 Kenta Murata 1 Monday, September 26, 11

description

Cucumber と RSpec による ATDD 入門

Transcript of Introduction to ATDD with Cucumber and RSpec

Page 1: Introduction to ATDD with Cucumber and RSpec

Introduction to ATDD with Cucumber and RSpecCucumber と RSpec による ATDD 入門Kenta Murata

1Monday, September 26, 11

Page 2: Introduction to ATDD with Cucumber and RSpec

http://www.flickr.com/photos/recompile_net/5951998279/

Kenta MurataCRuby committer

bigdecimal maintainer

OS X platform maintainer

Interested in number system

Ruby Sapporo

@mrkn

2Monday, September 26, 11

Page 3: Introduction to ATDD with Cucumber and RSpec

2010年3月1日月曜日 3Monday, September 26, 11

Page 4: Introduction to ATDD with Cucumber and RSpec

http://rubyconf.org/schedule

4Monday, September 26, 11

Page 5: Introduction to ATDD with Cucumber and RSpec

http://rubyconf.org/schedule

4Monday, September 26, 11

Page 6: Introduction to ATDD with Cucumber and RSpec

Introduction to ATDD with Cucumber and RSpecCucumber と RSpec による ATDD 入門Kenta Murata

5Monday, September 26, 11

Page 7: Introduction to ATDD with Cucumber and RSpec

ATDD?

6Monday, September 26, 11

Page 8: Introduction to ATDD with Cucumber and RSpec

Acceptance TestDriven Development受け入れテスト駆動開発

7Monday, September 26, 11

Page 9: Introduction to ATDD with Cucumber and RSpec

受け入れテストの自動化

8Monday, September 26, 11

Page 10: Introduction to ATDD with Cucumber and RSpec

“The idea of using an automated customer Acceptance Test was first proposed in April 2000 by Kent Beck. Instead of a stakeholder handing over a requirements document to the developers without much opportunity for feedback, the developer and stakeholder collaborate together to write a test that the computer can run.

9Monday, September 26, 11

Page 11: Introduction to ATDD with Cucumber and RSpec

“「自動化された顧客の受け入れテスト」というアイデアは2000年4月に Kent Beck によって初めて提案された。それは、要求仕様書の管理を開発者に委ねてしまい、フィードバックのための多くの機会を持たないステークホールダの代わりに、開発者とステークホールダが計算機で走らせることができるテストを書くために協調する。

10Monday, September 26, 11

Page 12: Introduction to ATDD with Cucumber and RSpec

“「自動化された顧客の受け入れテスト」というアイデアは2000年4月に Kent Beck によって初めて提案された。それは、要求仕様書の管理を開発者に委ねてしまい、フィードバックのための多くの機会を持たないステークホールダの代わりに、開発者とステークホールダが計算機で走らせることができるテストを書くために協調する。

11Monday, September 26, 11

Page 13: Introduction to ATDD with Cucumber and RSpec

“「自動化された顧客の受け入れテスト」というアイデアは2000年4月に Kent Beck によって初めて提案された。それは、要求仕様書の管理を開発者に委ねてしまい、フィードバックのための多くの機会を持たないステークホールダの代わりに、開発者とステークホールダが計算機で走らせることができるテストを書くために協調する。

12Monday, September 26, 11

Page 14: Introduction to ATDD with Cucumber and RSpec

“「自動化された顧客の受け入れテスト」というアイデアは2000年4月に Kent Beck によって初めて提案された。それは、要求仕様書の管理を開発者に委ねてしまい、フィードバックのための多くの機会を持たないステークホールダの代わりに、開発者とステークホールダが計算機で走らせることができるテストを書くために協調する。

13Monday, September 26, 11

Page 15: Introduction to ATDD with Cucumber and RSpec

“「自動化された顧客の受け入れテスト」というアイデアは2000年4月に Kent Beck によって初めて提案された。それは、要求仕様書の管理を開発者に委ねてしまい、フィードバックのための多くの機会を持たないステークホールダの代わりに、開発者とステークホールダが計算機で走らせることができるテストを書くために協調する。

14Monday, September 26, 11

Page 16: Introduction to ATDD with Cucumber and RSpec

http://pragprog.com/book/hwcuc/the-cucumber-book15Monday, September 26, 11

Page 17: Introduction to ATDD with Cucumber and RSpec

“The test fails at the time of writing, because no code has been written yet, but captures what the stakeholder cares about and gives everyone a clear signal as to what it will take to be done.

16Monday, September 26, 11

Page 18: Introduction to ATDD with Cucumber and RSpec

“テストを書いている時、コードはまだ書かれていない為、そのテストは失敗する。しかしそのテストは、ステークホールダが気にしている事を捕捉し、すべての人に何をやるべきであるかを示してくれる。

17Monday, September 26, 11

Page 19: Introduction to ATDD with Cucumber and RSpec

Unit tests v.s. Acceptance Test

18Monday, September 26, 11

Page 20: Introduction to ATDD with Cucumber and RSpec

開発者のためのもの

開発を駆動する

ソフトウェアの設計をテストする

Unit tests

19Monday, September 26, 11

Page 21: Introduction to ATDD with Cucumber and RSpec

Acceptance tests

「正しいものを作っている」事を確実にする

「正しいもの」を定めるもの

Feature (Usecase)

Scenario

20Monday, September 26, 11

Page 22: Introduction to ATDD with Cucumber and RSpec

動く Feature を書く

21Monday, September 26, 11

Page 23: Introduction to ATDD with Cucumber and RSpec

Feature の例会議室情報一覧を表示するシステムに登録されている全ての会議室情報を一覧表示する

前提条件システムのホームページが表示されている

主シナリオユーザは、「会議室一覧」のリンクをクリックするシステムは、会議室情報一覧を取得するシステムは、「会議室一覧」ページを表示する

22Monday, September 26, 11

Page 24: Introduction to ATDD with Cucumber and RSpec

これは動かない

23Monday, September 26, 11

Page 25: Introduction to ATDD with Cucumber and RSpec

http://pragprog.com/book/hwcuc/the-cucumber-book24Monday, September 26, 11

Page 26: Introduction to ATDD with Cucumber and RSpec

Cucumber で書くとこうなる

Feature: 会議室情報一覧を表示する

システムに登録されている全ての会議室情報を一覧表示する

Scenario: 会議室一覧ページの表示 Given システムの “ホームページ” が表示されている When ユーザは “会議室一覧” リンクをクリックする Then システムは会議室情報一覧を取得する And システムは “会議室一覧” ページを表示する

25Monday, September 26, 11

Page 27: Introduction to ATDD with Cucumber and RSpec

ステップ定義Given /システムの “([^”]*)” が表示されている/ do |arg| ...end

When /ユーザは “([^”]*)” リンクをクリックする/ do |arg| ...end

Then /システムは会議室情報一覧を取得する/ do ...end

Then /システムは “([^”]*)” ページを表示る/ do |arg| ...end

26Monday, September 26, 11

Page 28: Introduction to ATDD with Cucumber and RSpec

Cucumber の良いところ

開発者でなくても Feature と Scenario を読める

シナリオの検証を自動化できる

ステップ定義は任意のプログラミング言語で書ける

27Monday, September 26, 11

Page 29: Introduction to ATDD with Cucumber and RSpec

OUTSIDE-IN RAILS DEVELOPMENT 285

greenrefactor

red

green

red

refactor

1

2

3

4

5

67

Cucumber

RSpec

1

2

Focus on one scenario

Write failing step definition

(drop down to RSpec)

3

4

5

Implement view

Refactor view

Write failing view spec Repeat #3 –#5 fordiscovered controllers,controller actions,models, etc., untilstep is passing

7 Refactor

(when step is passing)

6

(start with Cucumber)

Repeat #2 –#7until scenario

is passing

Repeat #1 –#7when scenariois passing

Figure 19.1: The BDD cycle in Rails

Report erratum

this copy is (P2.0 printing, May 2011)Prepared exclusively for Kenta Murata

The RSpec Book, p.28528Monday, September 26, 11

Page 30: Introduction to ATDD with Cucumber and RSpec

OUTSIDE-IN RAILS DEVELOPMENT 285

greenrefactor

red

green

red

refactor

1

2

3

4

5

67

Cucumber

RSpec

1

2

Focus on one scenario

Write failing step definition

(drop down to RSpec)

3

4

5

Implement view

Refactor view

Write failing view spec Repeat #3 –#5 fordiscovered controllers,controller actions,models, etc., untilstep is passing

7 Refactor

(when step is passing)

6

(start with Cucumber)

Repeat #2 –#7until scenario

is passing

Repeat #1 –#7when scenariois passing

Figure 19.1: The BDD cycle in Rails

Report erratum

this copy is (P2.0 printing, May 2011)Prepared exclusively for Kenta Murata

The RSpec Book, p.285

ひとつのシナリオに注目

28Monday, September 26, 11

Page 31: Introduction to ATDD with Cucumber and RSpec

OUTSIDE-IN RAILS DEVELOPMENT 285

greenrefactor

red

green

red

refactor

1

2

3

4

5

67

Cucumber

RSpec

1

2

Focus on one scenario

Write failing step definition

(drop down to RSpec)

3

4

5

Implement view

Refactor view

Write failing view spec Repeat #3 –#5 fordiscovered controllers,controller actions,models, etc., untilstep is passing

7 Refactor

(when step is passing)

6

(start with Cucumber)

Repeat #2 –#7until scenario

is passing

Repeat #1 –#7when scenariois passing

Figure 19.1: The BDD cycle in Rails

Report erratum

this copy is (P2.0 printing, May 2011)Prepared exclusively for Kenta Murata

The RSpec Book, p.285

ひとつのシナリオに注目

失敗するステップ定義を書く

28Monday, September 26, 11

Page 32: Introduction to ATDD with Cucumber and RSpec

OUTSIDE-IN RAILS DEVELOPMENT 285

greenrefactor

red

green

red

refactor

1

2

3

4

5

67

Cucumber

RSpec

1

2

Focus on one scenario

Write failing step definition

(drop down to RSpec)

3

4

5

Implement view

Refactor view

Write failing view spec Repeat #3 –#5 fordiscovered controllers,controller actions,models, etc., untilstep is passing

7 Refactor

(when step is passing)

6

(start with Cucumber)

Repeat #2 –#7until scenario

is passing

Repeat #1 –#7when scenariois passing

Figure 19.1: The BDD cycle in Rails

Report erratum

this copy is (P2.0 printing, May 2011)Prepared exclusively for Kenta Murata

The RSpec Book, p.285

ひとつのシナリオに注目

失敗するステップ定義を書く

内側 (RSpec) に入る

28Monday, September 26, 11

Page 33: Introduction to ATDD with Cucumber and RSpec

OUTSIDE-IN RAILS DEVELOPMENT 285

greenrefactor

red

green

red

refactor

1

2

3

4

5

67

Cucumber

RSpec

1

2

Focus on one scenario

Write failing step definition

(drop down to RSpec)

3

4

5

Implement view

Refactor view

Write failing view spec Repeat #3 –#5 fordiscovered controllers,controller actions,models, etc., untilstep is passing

7 Refactor

(when step is passing)

6

(start with Cucumber)

Repeat #2 –#7until scenario

is passing

Repeat #1 –#7when scenariois passing

Figure 19.1: The BDD cycle in Rails

Report erratum

this copy is (P2.0 printing, May 2011)Prepared exclusively for Kenta Murata

The RSpec Book, p.285

ひとつのシナリオに注目

失敗するステップ定義を書く

失敗する view の spec を書く

内側 (RSpec) に入る

28Monday, September 26, 11

Page 34: Introduction to ATDD with Cucumber and RSpec

OUTSIDE-IN RAILS DEVELOPMENT 285

greenrefactor

red

green

red

refactor

1

2

3

4

5

67

Cucumber

RSpec

1

2

Focus on one scenario

Write failing step definition

(drop down to RSpec)

3

4

5

Implement view

Refactor view

Write failing view spec Repeat #3 –#5 fordiscovered controllers,controller actions,models, etc., untilstep is passing

7 Refactor

(when step is passing)

6

(start with Cucumber)

Repeat #2 –#7until scenario

is passing

Repeat #1 –#7when scenariois passing

Figure 19.1: The BDD cycle in Rails

Report erratum

this copy is (P2.0 printing, May 2011)Prepared exclusively for Kenta Murata

The RSpec Book, p.285

ひとつのシナリオに注目

失敗するステップ定義を書く

失敗する view の spec を書く

view を実装する

内側 (RSpec) に入る

28Monday, September 26, 11

Page 35: Introduction to ATDD with Cucumber and RSpec

OUTSIDE-IN RAILS DEVELOPMENT 285

greenrefactor

red

green

red

refactor

1

2

3

4

5

67

Cucumber

RSpec

1

2

Focus on one scenario

Write failing step definition

(drop down to RSpec)

3

4

5

Implement view

Refactor view

Write failing view spec Repeat #3 –#5 fordiscovered controllers,controller actions,models, etc., untilstep is passing

7 Refactor

(when step is passing)

6

(start with Cucumber)

Repeat #2 –#7until scenario

is passing

Repeat #1 –#7when scenariois passing

Figure 19.1: The BDD cycle in Rails

Report erratum

this copy is (P2.0 printing, May 2011)Prepared exclusively for Kenta Murata

The RSpec Book, p.285

ひとつのシナリオに注目

失敗するステップ定義を書く

失敗する view の spec を書く

view を実装する

view をリファクタリング

内側 (RSpec) に入る

28Monday, September 26, 11

Page 36: Introduction to ATDD with Cucumber and RSpec

OUTSIDE-IN RAILS DEVELOPMENT 285

greenrefactor

red

green

red

refactor

1

2

3

4

5

67

Cucumber

RSpec

1

2

Focus on one scenario

Write failing step definition

(drop down to RSpec)

3

4

5

Implement view

Refactor view

Write failing view spec Repeat #3 –#5 fordiscovered controllers,controller actions,models, etc., untilstep is passing

7 Refactor

(when step is passing)

6

(start with Cucumber)

Repeat #2 –#7until scenario

is passing

Repeat #1 –#7when scenariois passing

Figure 19.1: The BDD cycle in Rails

Report erratum

this copy is (P2.0 printing, May 2011)Prepared exclusively for Kenta Murata

The RSpec Book, p.285

ひとつのシナリオに注目

失敗するステップ定義を書く

失敗する view の spec を書く

view を実装する

view をリファクタリング

ステップがパスしたら外側 (cucumber) に出る

内側 (RSpec) に入る

28Monday, September 26, 11

Page 37: Introduction to ATDD with Cucumber and RSpec

OUTSIDE-IN RAILS DEVELOPMENT 285

greenrefactor

red

green

red

refactor

1

2

3

4

5

67

Cucumber

RSpec

1

2

Focus on one scenario

Write failing step definition

(drop down to RSpec)

3

4

5

Implement view

Refactor view

Write failing view spec Repeat #3 –#5 fordiscovered controllers,controller actions,models, etc., untilstep is passing

7 Refactor

(when step is passing)

6

(start with Cucumber)

Repeat #2 –#7until scenario

is passing

Repeat #1 –#7when scenariois passing

Figure 19.1: The BDD cycle in Rails

Report erratum

this copy is (P2.0 printing, May 2011)Prepared exclusively for Kenta Murata

The RSpec Book, p.285

ひとつのシナリオに注目

失敗するステップ定義を書く

失敗する view の spec を書く

view を実装する

view をリファクタリング

ステップがパスしたら外側 (cucumber) に出る

内側 (RSpec) に入る

全体をリファクタリング

28Monday, September 26, 11

Page 38: Introduction to ATDD with Cucumber and RSpec

OUTSIDE-IN RAILS DEVELOPMENT 285

greenrefactor

red

green

red

refactor

1

2

3

4

5

67

Cucumber

RSpec

1

2

Focus on one scenario

Write failing step definition

(drop down to RSpec)

3

4

5

Implement view

Refactor view

Write failing view spec Repeat #3 –#5 fordiscovered controllers,controller actions,models, etc., untilstep is passing

7 Refactor

(when step is passing)

6

(start with Cucumber)

Repeat #2 –#7until scenario

is passing

Repeat #1 –#7when scenariois passing

Figure 19.1: The BDD cycle in Rails

Report erratum

this copy is (P2.0 printing, May 2011)Prepared exclusively for Kenta Murata

The RSpec Book, p.285

ひとつのシナリオに注目

失敗するステップ定義を書く

失敗する view の spec を書く

view を実装する

view をリファクタリング

ステップがパスしたら外側 (cucumber) に出る

内側 (RSpec) に入る

全体をリファクタリング

注目しているシナリオがパスするまで繰り返し

28Monday, September 26, 11

Page 39: Introduction to ATDD with Cucumber and RSpec

Demonstration

29Monday, September 26, 11

Page 40: Introduction to ATDD with Cucumber and RSpec

http://tatsu-zine.com/books/cuke30Monday, September 26, 11

Page 41: Introduction to ATDD with Cucumber and RSpec

http://pragprog.com/book/achbd/the-rspec-book31Monday, September 26, 11

Page 42: Introduction to ATDD with Cucumber and RSpec

http://pragprog.com/book/hwcuc/the-cucumber-book32Monday, September 26, 11

Page 43: Introduction to ATDD with Cucumber and RSpec

http://pragprog.com/book/rcctr/continuous-testing33Monday, September 26, 11

Page 44: Introduction to ATDD with Cucumber and RSpec

http://pragprog.com/book/jgade/test-driven-development-for-embedded-c34Monday, September 26, 11

Page 45: Introduction to ATDD with Cucumber and RSpec

http://cuke4ninja.com/35Monday, September 26, 11

Page 46: Introduction to ATDD with Cucumber and RSpec

http://ssl.ohmsha.co.jp/cgi-bin/menu.cgi?ISBN=978-4-274-06856-036Monday, September 26, 11

Page 47: Introduction to ATDD with Cucumber and RSpec

http://www.informit.com/store/product.aspx?isbn=032150362737Monday, September 26, 11

Page 48: Introduction to ATDD with Cucumber and RSpec

http://www.informit.com/store/product.aspx?isbn=032160191238Monday, September 26, 11