Presentation is loading. Please wait.

Presentation is loading. Please wait.

Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 1 Test-Driven Development An introduction for C# developers.

Similar presentations


Presentation on theme: "Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 1 Test-Driven Development An introduction for C# developers."— Presentation transcript:

1 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 1 Test-Driven Development An introduction for C# developers

2 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 2 Who I am »Mathias Brandewinder – Background in business and quantitative analysis methods – Develop in C#/.NET for the past 5 years – Started my own business since over a year »www.clear-lines.com/blog

3 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 3 My goal for today »I would like you to be able to start as you leave the room

4 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 4 Approach »Interactive: write code live »Focus on C# »Focus primarily on NUnit – Covering also Visual Studio 2008 tools »Assuming little or no background in TDD/unit testing

5 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 5 The plan »What is TDD? »TDD in action: the basics – Using Nunit – Using VS2008 »Less basic TDD »Mocks »Beyond TDD »Questions

6 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 6 What is TDD?

7 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 7 Test-Driven Development »Is a development methodology – Not a testing methodology »Aims for “clean code that works, now” »Write the test first, then the code which satisfies the test

8 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 8 Source »Test-Driven Development By Example, Kent Beck (Addison Wesley)

9 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 9 The rules »Write new code only if an automated test has failed »Eliminate duplication

10 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 10 Red/Green/Refactor »Red: write a little test that doesn’t work, and perhaps doesn’t even compile at first »Green: make the test work quickly, committing whatever sins necessary in the process »Refactor: eliminate all of the duplication created in merely getting the test to work

11 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 11 Benefits: the obvious »Simple and predictable »Small steps »Fully tested code from the get-go »Very reassuring

12 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 12 TDD in action

13 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 13 It’s Monday morning, and…

14 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 14 Your mission, if you accept it »Add a functionality to an existing application, to compute the distance between cities

15 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 15 A quick math reminder »We will assume that “the world is flat” »Distance between 2 points:

16 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 16 Let’s get started!

17 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 17 What have we seen so far? »[TestFixture], [Test], Assert »One test at a time »Write “as if” you had the feature done »Write tests as “sentences” »3 patterns – Fake it ‘til you make it – Obvious implementation – Triangulate

18 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 18 What have we seen so far? »Separate projects »Debugging a test

19 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 19 Less basic TDD

20 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 20 Some classic useful test techniques »TestRow »Testing for exceptions »Setup & Teardown

21 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 21 Mocks

22 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 22 Mocks »“Subject under test” vs. Collaborators »Mocks to simplify your life – “Classicists”: by default, use the real thing »Mocks, the dark side of design patterns – “Mockists”: use Mocks in interactions

23 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 23 What have we seen so far? »When testing the interaction of a class with another class, Mocks are a convenient way to “fake” the collaborator »Focus on behavior and not state

24 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 24 Mocks and patterns IStrategy StrategyB StrategyA MyClass Strategy: IStrategy

25 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 25 Beyond TDD

26 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 26 A few questions »What are the benefits of TDD? »Does TDD slow you down? »How much testing is enough? »Does TDD mean no upfront design? »What are good tests? »Are TDD people terrorists?

27 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 27 Questions?

28 Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 28 To contact me… mathias.brandewinder@clear-lines.com


Download ppt "Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 1 Test-Driven Development An introduction for C# developers."

Similar presentations


Ads by Google