1 / 19

Advanced unit test in real world

Advanced unit test in real world. User Group Italiano ALT.NET – http://ugialt.net . Agenda. Using Stubs to Break Dependencies Interaction testing using Mock Objects Working with legacy code Test Hierarchies and organization

avari
Download Presentation

Advanced unit test in real world

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Advanced unit test in real world User Group Italiano ALT.NET – http://ugialt.net

  2. Agenda Using Stubs to Break Dependencies Interaction testing using Mock Objects Working with legacy code Test Hierarchies and organization The pillars of good unit tests Integrating unit testing into the organization Design and Testability Tools and frameworks The future of unit test

  3. Unit testing vs TDD • Title was: • Advanced tdd in real world • but now it’s • Advanced unit test in real world

  4. Unit Testing • It’s a methodologytoverify single portionsof source code • A Unitis the minimal testable part: • Proceduralcoding: • Single program • function • procedure • ObjectOrientedProgramming • method

  5. Test-Driven Development • It’s principally a design activity in which the tests are writtenbefore the code • For each iteration : • red: define the attendedbehaviourwhitassertions • green: alltestssucceded and the assertion are verified • refactor: improve the qualityof code (applying design patterns) keeping the testsgreen

  6. Test-Driven Development in Microsoft .NET • by James W. Newkirk and Alexei A. Vorontsov (April 14, 2004) • http://www.amazon.com/Test-Driven-Development-Microsoft-NET-Professional/dp/0735619484/ref=sr_1_14?ie=UTF8&s=books&qid=1232141037&sr=8-14

  7. Antibiotics & test driven developmentFonte: http://www.sviluppoagile.it/antibiotici-e-test-driven-development Uno sviluppatore con cui ho terminato oggi un’importante fase di un progetto web mi ha detto: [...] Io diffido di chi propone un rimedio come panacea di tutti i mali. Nei progetti open source che vedo utilizzare i test automatici io vedo ancora liste di bug lunghissime. Affermazione che equivale più o meno a dire: Ritengo gli antibiotici un immenso bluff. Sono decenni che vengono impiegati e ci sono ancora milioni di malati in ogni parte del mondo Ok, ci ammaliamo ancora tutti e ancora ovunque, ma rinuncereste agli antibiotici? Gli antibiotici non ci regalano l’immunità totale, ma hanno abbattuto l’impatto dei batteri sulle nostre vite. I test automatici non sono una panacea, ma abbattono il tempo speso a fare debugging - che è sempre tempo perso, poiché non è passato a creare valore ma a verificarlo

  8. Using Stubs to Break Dependencies Stub External Dependency  An external dependency is an object in your system which your code under test interacts with, and over which you have no control Examples: File System Threads Memory Time etc.. • A stub is a replacement for an existing dependency in the system, which your test can have control over. • A stub will help you test your code without dealing with the dependency directly.  

  9. Interaction testing using Mock Objects State-Based Testing Interaction Testing Interaction Testing is the act of testing how an object under test calls and receives input from other objects • Also called “State Verification”, we determine whether the exercised method worked correctly by examining the state of the system under test and its collaborators (dependencies) after the method was exercised.

  10. Working with legacy code • Experience taken from the field: • Once I left it was really easy to go back to the “old” mode of work   • There was too much pressure to do other things than to devote time to this learning task   • It was proving really hard to write tests against existing code   • It was next to impossible to refactor the existing code (or not enough time to do it)   • The learning curve was too high for most people   • Some people didn’t want to change their design   • People did not see clear and quick results from doing this   • Tooling was getting in the way (or lack thereof)   • We didn’t know where to begin.  

  11. Test Hierarchies and organization Unit tests are just an important part of the application as the production source code. Give careful thought to where the tests actually reside, both physically, and logically, in relation to the code under test.

  12. The pillars of good unit tests Trustworthy   Maintainable   Readable 

  13. Integrating unit testing into the organization Becoming the agent of change Ways to succeed Ways to fail

  14. Design and Testability Should I change the design of my code so that it is more easily testable ? How can Test-Driven Development help me ? What I want to test ?

  15. Developer, developer, developer Tools and frameworks

  16. Test Frameworks MS Test NUnit MbUnit Gallio XUnit Pex

  17. Mock Frameworks Moq Rhino Mocks Typemock Isolator Nmock NUnit.Mocks

  18. Dependency Injection and IoC Containers Common IServiceLocator Framework Managed Extensibility Framework StructureMap Microsoft Unity Castle Windsor Spring.NET Autofac Ninject      Complete list: http://www.artofunittesting.com/IOC_Containers_Resources

  19. Unit Test vNext ( maybe 2.0 ? ) DSL with dynamic languages Parametric Unit Test generation http://channel9.msdn.com/pdc2008/TL51/ Concurrency Unit Test http://channel9.msdn.com/pdc2008/TL58/

More Related