Upload
amir-barylko
View
568
Download
0
Tags:
Embed Size (px)
DESCRIPTION
PResentation done at
Citation preview
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
AMIR BARYLKO
TDD INTRO
ONLINE BUSINESS SYSTEMSAPRIL 2011
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
WHO AM I?
•Quality Expert
• Architect
•Developer
•Mentor
• Great cook
• The one who’s entertaining you for the next hour!
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
RESOURCES
• Email: [email protected]
• Twitter : @abarylko
• Blog: http://www.orthocoders.com
•Materials: http://www.orthocoders.com/presentations
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
TDD TRAINING
•When: May 26 & 27
•More info: http://www.maventhought.com
• Goal: Learn TDD with real hands on examples
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
INTROWhy projects fail?
Reality CheckNo more excuses
Why TDD?
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
WHY PROJECTS FAIL?
•Delivering late or over budget
•Delivering the wrong thing
•Unstable in production
•Costly to maintain
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
REALITY CHECK
• It is impossible to gather all the requirements at the beginning of a project.
•Whatever requirements you do gather are guaranteed to change.
•There will always be more to do than time and money will allow.
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
NO MORE EXCUSES
• It works on my computer!
• It was like that when I got here!
• The previous developer didn’t know XXXX!
• We need a satellite connection in order to run it!
• We can’t reproduce the error!
• We can’t test that!
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
WHY TDD?
•Prove that your code works
•Avoid waste (debugging)
• Increment code quality
•Better design
•Regression tests as byproduct
•Make changes with confidence
•Bring back the joy of coding!
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
APPLYING TDDIteration 0 .. N
Quality as a Driver Red - Green - Refactor
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
ITERATION 0
• Flush out architecture.
• Setup Testing harness for TDD and BDD.
• Setup continuous integration.
• Setup scripts to build, deploy, etc.
• Setup visual communication tools.
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
ITERATION 1.. N
• Start by Story Planning
• Pair programming (switching often)
•Daily Scrum
• End with Retrospective
Every day!
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
QUALITY AS A DRIVERRed
GreenRefactor
BDD
TDD
Red
GreenRefactor
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
RED
•Write a test that fails
•Relax, is ok if it compiles
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
GREEN
•Try to make the test pass
•Do a simple solution
•Use default values (not throwing exceptions)
•Don’t worry if the code “smells”
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
REFACTOR
•Avoid repeating code
•Avoid hardcoding dependencies
•Avoid “write only” code
•Refactor with confidence!
•Run all tests if possible
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
DEMOUnit Testing Frameworks
Given - When - ThenListing Contents
Reviews
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
TESTING FRAMEWORKS
•MsTest, xUnit, nUnit, MbUnit, MSpec
• Similar “hooks”
• Before and after test
• Before and after all test
• Arrange, Act, Assert
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
GIVEN WHEN THEN
• Test one “scenario” at a time
• Clear identification of functionality
• Easy to write, understand and maintain
• Repeatable, easy to learn
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
LISTING CONTENTS
• Controller “Movies” method “Index”
• Two scenarios
• Given I have no movies....
• Given I have the following movies....
•Where do I get the movies from?
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
GIVEN I HAVE NO MOVIES
[It]public void Should_not_return_any_movies(){ var result = (ViewResult)this.ActualResult;
var actual = (IEnumerable<IMovie>) result.ViewData.Model;
actual.Should().Be.Empty();}
[It]public void Should_render_the_index_view(){ this.ActualResult.AssertViewRendered();}
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
GIVEN I HAVE 10 MOVIES
[It]public void Should_return_all_the_movies(){ var result = (ViewResult)this.ActualResult;
var actual = (IEnumerable<IMovie>) result.ViewData.Model;
actual.Should().Have.SameValuesAs(this._movies);}
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
ARE WE DONE?
• Fail 1: IMovieLibrary is not registered in the container
• Fail 2: SimpleMovieLibrary needs the db name
• How can we make sure it works?
• Is TDD enough?
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
FIX THE CONTAINER
Component .For<IMovieLibrary>() .Instance(new SimpleMovieLibrary(dbFile))...
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
SAFETY NET
Scenario: Browse available movies
Given I have the following movies:
| title |
| Blazing Saddles |
| Space Balls |
When I go to "Movies"
Then I should see in the listing:
| title |
| Blazing Saddles |
| Space Balls |
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
SUMMARYBenefits
ChallengesAdoption
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
BENEFITS
•Let the methodology drive
• It will save your bacon!
•High quality the whole way!
•Very few bugs!
•Do your duty as developer!
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
CHALLENGES
• Very different from conventional testing
• Many developers find it complex to learn at first
• Hard to start without a Mentor
• Management buy in
• Difficult to keep under deadline pressure
• Beware of code coverage!
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
ADOPTION
• Find Mentor/Couch/Trainer
• Small iterations
• Have metrics ready (velocity, etc)
• Do whatever works for you
• Find out which tools will benefit you
• Automate, automate, automate!
Wednesday, April 27, 2011
Amir Barylko - .NET UG Mar ‘11 MavenThought Inc.
QUESTIONS?
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
RESOURCES
• Email: [email protected]
• Twitter : @abarylko
• Slides: http://www.orthocoders.com/presentations
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
RESOURCES II
Wednesday, April 27, 2011
Amir Barylko - OBS Apr ‘11 MavenThought Inc.
TDD TRAINING
•When: May 26 & 27
•More info: http://www.maventhought.com
• Goal: Learn TDD with real hands on examples
Wednesday, April 27, 2011