Your SlideShare is downloading. ×
Test Infected Presentation
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Test Infected Presentation

640
views

Published on

TTD talk I did with Chris Roff

TTD talk I did with Chris Roff


0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
640
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Don't mention the tools since Chris will be talking about them...
  • Blame game,  Always blame the team further up the Waterfall  until we decided in the clients fault for not knowing what they want.
  • TDD gone wronghow many tests do i need What should i test Never test the database mock everything   Testing types Load User Interface Source code analysis Assembly analysis Code coverage etc...
  • Behaviour Driven Design. Test First Development, Acceptance Test Driven Design Domain Driven Design
  • I think we all know what we want from the requirements thare are being given...
  • Talk about the back story... Everyone know how to play snap. Who should go first? Does the Giant make mistakes? Who goes next after someone wins? How high is the beanstalk? How many cards should there be? Can we walk through a game before we write code? Can assumptions be documented for the development team??
  • Show the before and after view of the Fitnesse Show them failing Indicate that we don't want to go into too much detail since Gojko has a talk coming up soon.
  • Skip very quickly
  • Transcript

    • 1.  
      •  
    • 2. Test Driven Development Tools and techniques
      • Talk overview
        • From idea to requirements, to development, to deployment
      •  
      • Topics
        • Stories to Acceptance Tests
        • Unit Testing
        • Integration testing
        • Deployment testing
    • 3. What is testing...
      • Verification
      •  
        • Are we building the software right ?
      •  
      •   
      • Phases
        • Unit, Integration, System, User Acceptance, Deployment
      • Validation
      •  
        • Are we building the right software ?
      •  
      •   
      • Phases
        • User Acceptance Test or ALL?
    • 4. What is testing...
      • Verification
      •  
        • Are we building the software right ?  
      • Engineering focused
      •   
      • Tools
        • MbUnit, Watin, RhinoMocks, FXCop, NDepend, NCover...
      •  
      •  
      • Validation
      •  
        • Are we building the right software ?
      •   
      • Analysis focused
      •    
      • Tools
        • Fitnesse, Story Teller, xBehave...
    • 5. Classic development
      • Quality is a side effect of the process not the driver of the process.
      •  
        • Developers, Business Analysts, Testers throw requirements, code and bug reports over the wall
        • No shared quality/testing strategy
          • Different groups use different tools and techniques 
        • Often manual
        • Regression tests labour/time intensive
    • 6. Test Driven Development
      • The day to day philosophy Red ,  Green ,  Green
      • Red - Analysis/Design Hat
        • Create a test that defines the expected outcome
        • Asking "What I want is..."
      • Green - Creative Hat (Fun part)
        • Experiment/Prototype/Build until the test passes
      • Green - Engineering
        • Refactor, refactor, refactor
    • 7. Testing Dimensions
    • 8. Modern TDD
      • Verification and Validation performed continually, during all phases with everyone involved.  
        • xUnit/CI is only the start
        • TDD mindset is pushing the boundaries of where tests can become automated
        • New focus on down stream testing during Requirements gathering 
        • Breaking project into Stories promotes detailed requirements over classical analysis which promotes "sweeping open ended statements"
    • 9. Requirements
      • Precise and clear over verbose
      • We want requirements that
      •  
        • Can be tested!!!
        • Are attainable!!! 
        • Can be easily mapped to User Stories!!!
        • Are traceable into code!!!
    • 10. Acceptance Tests
      • Using Fitnesse to Verify & Validate
      • FitNesse  enables customers, testers, and programmers to  learn what their software should do , and to automatically compare that to  what it actually does do . It compares customers' expectations to actual results. 
      •  
      • http://fitnesse.org/FitNesse.OneMinuteDescription
      •  
    • 11. Fitnesse
      • What is it?
        • A wiki for writing acceptance tests
        • Allows Text, Images and Test case data to be intermingled on the same page
        • Promotes shared terminology between analysis and development (Ubiquitous language)
    • 12. Its almost Christmas...  
      • Midland Organic Foods are thinking about Easter - Jack Plays Snap
        • Jack climbs beanstalk when correctly snapping
        • Jack wins when he reaches the top of the Beanstalk
        • Giant snaps when Jack takes too long
    • 13.   Fitnesse Demo
    • 14. Fitnesse
      • Demo code was horrible...
        • No transactions
        • Not N-Tiered
        • Inadequate error handling
        • Prototype...
    • 15. Fitnesse
      • As code is productioised
        • Fixtures are updated
        • Wiki pages ARE NOT TOUCHED!!
        • Fixtures are a bridge between analysis and implementation
          • Complex fixture implies translation of ideas
          • Strive for Ubiquitious language...
          • Refactor, refactor, refactor...
    • 16. Unit Testing
    • 17. What is Unit Testing
        • Testing individual units of code
      •  
        • Take smallest piece of testable software in the application & isolate it from the remainder of the code
      •  
        • Simple, Repeatable, Fast
    • 18. Advantages Disadvantages
        •   Client & Developer confidence
      •  
        • Refactoring
      •  
        • Self documenting
        •   Have to write more code
          • But..is this REALLY a disadvantage?
    • 19. Tools
        •   Testing frameworks
          • MBUnit, NUnit, xUnit...many more
      •  
        • Test runners
          • Testdriven.Net, Resharper, Gallio, TeamCity
      •  
        • Mocking
          • RhinoMocks, NMock, Typemock
      •  
        • Code Coverage
          • NCover
    • 20. Unit Test Syntax
        •   Arrange
      •  
        • Act
      •  
        • Assert
    • 21. Example
      •         [ Test ]         public void FindByName_Returns_FarmyardAnimal_When_In_Collection()  {
      •             //Arrange
      •              string Animal_Name = "test" ;
      •              FarmYardAnimal testAnimal = new FarmYardAnimal 
      •                                                                   {Name = Animal_Name};             FarmYardAnimals farmYardAnimals = new FarmYardAnimals ();             farmYardAnimals.Add(testAnimal);
      •             //Act             FarmYardAnimal foundAnimal =  farmYardAnimals.FindByName(Animal_Name);   
      •             //Assert             Assert .AreEqual(testAnimal,foundAnimal);         }
    • 22. Mocking
        •   Simulating objects that mimic the behavior of real objects in controlled ways.
      •  
        •   Isolate dependancies
      •  
        •   Only used in UNIT testing
    • 23. Mocking cont...
        •   RhinoMocks
          •   currently version 3.5
          •   written by Ayende
          •   well maintained
          •   lots of examples
          •   can mock 
            • everything on interfaces or
            •   virtuals on classes
    • 24. Mocking cont...
        •   Stubs
          •   Supply the SUT with data
      •  
          •   No constraints
      •  
          •   Assert on SUT
      •  
        •   Mocks
          •   For interaction testing
      •  
          •   "Record" actions on the mock
      •  
          •   Assert on Mock using constraints
    • 25. Stubbing - What we’re testing
      • public bool GameFinished
      • {
      • get
      • {
      • return
      • (Beanstalk.AtTop ||
      • (Jack.Cards.Count == 0 && Giant.Cards.Count == 0));
      • }
      • }
    • 26. Example of Stubbing
      • [Test] public void GameFinished_True_When_BeanstalkAtTop_And_Neither_Jack_Or_Giant_HaveCards() {
      •   //Arrange
      • Queue < IPlayingCard > noCards = new Queue < IPlayingCard >();
      •  
      • IBeanstalk stubBeanstalk = MockRepository . GenerateStub < IBeanstalk >(); stubBeanstalk. Expect (sb => sb.AtTop).Return( true ); IPlayer stubJack = MockRepository . GenerateStub < IPlayer >(); IPlayer stubGiant = MockRepository . GenerateStub < IPlayer >(); stubJack. Expect (j => j.Cards).Return(noCards); stubGiant. Expect (j => j.Cards).Return(noCards); Game gameToTest = new Game (stubJack , stubGiant , stubBeanstalk );  
      • //Act bool isFinished = gameToTest.GameFinished; //Assert Assert .IsTrue(isFinished);
      • }
    • 27. Mocking - What we're testing
      • public void Save( IGame game){             var status = new GameStatus                              {                                  Giant = game.Giant.Name,                                  Jack = game.Jack.Name,                                  CanSnap = game.CanSnap,                                  IsFinished = game.GameFinished,                                  ActivePlayer = game.ActivePlayer.Name                              };             try             {                 _session.SaveOrUpdate(status);             }             catch ( Exception ex){                 throw new GameRepositoryException ( &quot;Game Save Error&quot; , ex);             } }
    • 28. Example of Mocking cont..
      • [Test] public void GameRepository_Should_Convert_GameToGameStatus_And_Use_Session_To_Save (){
      • //Arrange
      • GameStatus expectedStatus = new GameStatus {                         ActivePlayer = &quot;active&quot; ,CanSnap = true ,
      •                          Giant = &quot;giant&quot; ,Jack = &quot;jack&quot; ,IsFinished = false };
      •  
      •   //Dont use stubs if creating the object directly is easier
      • IPlayer jack = new Player (expectedStatus.Jack); IPlayer giant = new Player (expectedStatus.Giant); IPlayer activePlayer = new Player (expectedStatus.ActivePlayer);
      • //Create Game stub
      • IGame stubGame = MockRepository .GenerateStub< IGame >();
      • stubbedGame.Expect(g => g.Giant).Return(giant); stubbedGame.Expect(g => g.Jack).Return(jack); stubbedGame.Expect(g => g.ActivePlayer).Return(activePlayer); stubbedGame.Expect(g => g.CanSnap).Return(expectedStatus.CanSnap); stubbedGame.Expect(g => g.GameFinished).Return(expectedStatus.IsFinished);
    • 29. Example of Mocking....cont
      •   //create mock ISession mockedSession =
      • MockRepository . GenerateMock < ISession >();
      • GameRepository repository = new
      • GameRepository (mockedSession);  
      • //Act repository.Save(stubGame); //Assert mockedSession. AssertWasCalled (ms => ms.SaveOrUpdate( null ),                                           options =>
      • options.Constraints( Property . AllPropertiesMatch (expectedStatus));
      • }
    • 30. Constraints
        • Is
          •   Is .Null(), Is .NotNull(), Is .GreaterThan() etc
        • Property  
          • Value( “Status” , Status .Valid),
      •         IsNotNull( “User” ), IsNull( “User” ) etc
        • List  
          • constraints on lists e.g List .Count(2)
        • Text
          • constraints on text e.g Text .StartsWith( “foo” )
        • Many more...  
    • 31. Exception Path Testing
      • stubbedSession          .Expect(s => s.SaveOrUpdate( null ))          .IgnoreArguments()          . Throw ( new Exception ());
      • var gameRepository = new GameRepository (stubbedSession); //Act try {        gameRepository.Save(stubbedGame); }
      • catch ( GameRepositoryException exception)
      • {
      •      //Assert
      • }
    • 32. State vs Interaction Testing
        • Arrange and Act
      •  
        • Verify state of SUT
        • as expected
      •  
        •   Uses only Stubs
        • Arrange and Act
      •  
        • Verify SUT has interacted with dependancy correctly
      •  
        • Can use Stubs & Mocks
    • 33. MbUnit
      •  
        •   Testing framework
      •  
        • Currently at version 3
      •  
        • Bundled with Gallio
      •  
      •  
    • 34. Row Attribute
      • [Test] [ Row ( &quot;name1&quot; , &quot;name2&quot; )] [ Row ( &quot;name1&quot; , &quot;name1&quot; , ExpectedException = typeof ( ArgumentOutOfRangeException ))]
      • public void Can_Only_Add_Animals_With_Unique_Names_To_FarmyardAnimals
      • ( string firstAnimalName, string secondAnimalName) { //Arrange FarmYardAnimals animals = new FarmYardAnimals (); //Act animals.Add( new FarmYardAnimal {Name = firstAnimalName}); animals.Add( new FarmYardAnimal {Name = secondAnimalName}); }
    • 35. Integration Testing
    • 36. What is Integration Testing
        •   Testing components working together
      •  
        •   No Mocking
        •   Long running
        • Never sacrifice repeatability for speed
        • Large setup, multiple Asserts
      •  
      •  
    • 37.   Database Integration Testing
      • [Test] public void Using_The_DTC_To_Rollback_Transactions(){
      • using ( new TransactionScope ()){ using ( ISession session = _sessionFactory.OpenSession()) {    var status = new GameStatus     {         ActivePlayer = &quot;active&quot; ,         CanSnap = true ,         Giant = &quot;giant&quot; ,         IsFinished = true ,         Jack = &quot;jack&quot;      }; session.SaveOrUpdate(status); Assert .IsTrue(status.Id > 0);}}
    • 38. Database Integration Testing cont...
      • [Test, Rollback ] public void Using_MbUnit_To_Rollback_Transaction() {   using ( ISession session = _sessionFactory.OpenSession())
      • {    var status = new GameStatus     {         ActivePlayer = &quot;active&quot; ,         CanSnap = true ,         Giant = &quot;giant&quot; ,         IsFinished = true ,         Jack = &quot;jack&quot;      };  session.SaveOrUpdate(status);  Assert .IsTrue(status.Id > 0);
      • }
    • 39. Code Coverage - NCover
        •   Commercial & Free versions available
      •  
        •   Bundled as part of Testdriven.Net
      •  
        •   Good indication of code requiring tests
      •                              
      •                                  BUT
      •  
        •   High test coverage != Fully tested
    • 40. NCover cont...
      •  
    • 41. Production Testing
    • 42. Deployment Verification Tests
      • Automated tests in production
      • Is the deployment ok?
        • Verify resources have been installed
        • Verify software has permission to resources (file, databases, services, etc...)
        • Verify that manual software environment is correct (Windows version etc)
    • 43. Deployment Verification Tests
        • DVT  Hippocratic Oath
          • DO NO DAMAGE!
          • How much mess can you live with
            • Log changes?
            • Test data in production?
        • Not testing functionality that is done in lower environments
    • 44. Deployment Verification Tests
      •  
      • Steps
        • Create a mbUnit project specifically for DVT
        • Execute test runner console in production
        • Ensure that the Unit tests load the SAME configuration files as the SUT
        • Ensure test runner is executed using the same Windows credentials as the SUT
    • 45. Deployment Verification Tests
      • Create a library of common tests...
      •  
        • DatabaseAssert library
          • DatabaseExists();
          • StoredProcedureExists();
        • FileServerAssert library
          • CanOpen();
          • CanDelete();
    • 46. Monitoring and Alerting - Heartbeats
      • Continuous tests in production
        • If a server is down, how long does it take to find out?
          • Within 5 minutes or when the users complain
        • Create a service that can be remotely executed 
        • Ensure it touches all the systems it depends upon
    • 47. Merry Christmas
      • Thanks for listening 
      •   
      •  
        • http://www.fitnesse.org
        • http://www.mbunit.com/
        • http://ayende.com/projects/rhino-mocks.aspx
      •  
      •  
      •  
      •  
      • Code @ www.pebblesteps.com
    • 48. Back Story for Jack Plays Snap
    • 49. Its almost Christmas...  
      • Midland Organic Foods are thinking about Easter
      •  
        • Temporary product for Easter called Beanstalk Munchies
        • Organic biscuits coated in chocolate
        • Biscuits shaped like Farm Yard Animals based on Jack and Beanstalk fairy tail
        • Golden Gooses Egg in the middle of the box
    • 50. The Pitch - Vision
      • Increase sales by creating Buzz...
        • Client wants to create buzz around product launch
        • Want a Web game that they can advertise on TV and in retail stores
        • Ideas...  Puzzle game or Education game

    ×