TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

30
TDD & S.O.L.I.D. Two ingredients for high- quality software Dennis Doomen [email protected]

description

 

Transcript of TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

Page 1: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

TDD & S.O.L.I.D.Two ingredients for high-quality software

Dennis [email protected]

Page 2: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

About Me Principal Consultant

at Aviva Solutions 35 years 6-month daughter 12 years of

experience C++ origins On .NET since 2001

Page 3: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

Agenda About quality Test Driven Development & S.O.L.I.D Demos & examples Guidelines to get started

Page 4: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

What is quality? Or, how do you measure it?

“I don't care how good you think your design is. If I can't walk in and write a test for an arbitrary method of yours in five minutes, its not as good as you think it is, and whether you know it or not, you're paying a price for it.”

Michael Feathers, ObjectMentor

Page 5: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

How? Use coding guidelines Apply common design principles Test Driven Development Refactoring Use Design Patterns Pair Programming Socialize design & architecture

Page 6: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

Test Driven Development Is a design process Tests are your first users Tests can be your documentation If TDD hurts then you're doing it wrong

Page 7: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

S.O.L.I.D. Single Responsiblity Principle Open Closed Principle Liskov Substitution Principle Interface Seggregation Principle Dependency Inversion Principle

Page 8: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

Demo

Attendee registration

TDDSingle Reponsibility Principle

Dependency Inversion Principle

Page 9: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

What you have seen TDD

• Arrange-Act-Assert• Red-Green-Refactor• Mocking• Intention revealing tests

Single Responsibility Principle Dependency Inversion Principles

Page 10: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

Phases of unit testing1. Refusing2. Getting too excited3. Testing everything!4. Integration testing5. Discover mocking6. Mocking everything7. Becoming effective

Page 11: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

Example

Types of attendees

Open Closed PrincipleDependency Inversion Principle

Page 12: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

Naive Solution

Page 13: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

Better Solution

Page 14: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

Best Solution

Page 15: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

What you have seen Open Closed Principle Single Responsibility Principle Dependency Inversion Principle Chain of Responsibility Pattern Factory Method Pattern

Page 16: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

ExampleBilling

Liskov Substitution Principle

Page 17: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

Naive Solution

Page 18: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

Better Solution

new EmployeeBuilder().Build() ??

Page 19: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

Best Solution

Page 20: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

What you have seen Liskov Substition Principle Single Responsibility Principle

Page 21: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

Example

Event listening

Interface seggregation

Page 22: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

Naive Solution

Page 23: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

Better Solution

Page 24: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

Best Solution

Page 25: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

What you have seen Interface Seggregation

Page 26: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

Getting started guidelines Test should be• Small and focused• Intention revealing• Repeatable• Have no side-effects• Independent

Test what you know now (and assemble the rest from those pieces)

Page 27: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

Getting started guidelines Mocking• Don't mock chatty interfaces• Don't have more than 2-3 mocks per test• Only mock your nearest neigbors

Keep your tail short Isolate the ugly stuff Conform to SOLID (and other

principles)

Page 28: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

Resources xUnit Patterns

http://xunitpatterns.com/ Applying Domain Driven Design and Design Patterns

http://www.amazon.com/Applying-Domain-Driven-Design-Patterns-Examples/dp/0321268202

Jeremy D. Millerhttp://codebetter.com/blogs/jeremy.miller/default.aspxhttp://msdn.microsoft.com/en-us/magazine/cc720886.aspx

InfoQ Recommended TDD Tutorialshttp://www.infoq.com/news/2009/05/recommended-tdd-tutorials

Los Techies S.O.L.I.D. Principles E-Bookhttp://www.lostechies.com/content/pablo_ebook.aspx

C# 3.0 Coding Guidelineshttp://blog.avivasolutions.nl/archive/2009/03/06/new-coding-guidelines-for-c-3-0.aspx

Page 29: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software

Q&AEmail

[email protected]

Blogwww.dennisdoomen.net

Twitterwww.twitter.com/dennisdoomen

Page 30: TDD and S.O.L.I.D.; Two Ingredients For High Quality Software