Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Introduction to Unit Tests & TDD
UNIT TEST IN AN AGILE CONTEXT

Agile

XP

UT

2
DEFINITION
A unit test confirms functionality of a
small unit of functionality or component
in a larger system
•
•
•
•

Wr...
INITIAL REACTIONS

4
BENEFITS
• Higher quality (less bug)
• Living documentation
• Well-crafted code
• Easier refactoring
• Automatic regressio...
HOW UNIT TEST FRAMEWORKS WORK
Unit test Runner .exe

My Code

My unit test code

Unit Test Common Lib

Test Results
Code C...
TEST DRIVEN DEVELOPMENT
1. Create a falling test
 Red

2. Make the test pass
Green

3. Refactor
 Improve the internal

...
THE TESTS ARE THE SPECS
*.doc files can’t prove
software works !

8
LIMITATION
• 100 % code coverage impossible to reach
• Impossible to catch all errors

9
UNIT TEST OR INTEGRATION TEST ?
Too often we try to write unmaintainable
integration tests

UT

IT

UT
10
UNIT TEST VS. DATA BASE

• Isolate data access with an interface

11
UNIT TEST VS. PROVIDERS
Critical for teams using third-parties.
• Unit Test to simulate provider calls
• UnitTest unit to ...
TOOLS

13
.NET UNIT TESTING FRAMEWORKS

14
• Visual studio default interface

MS TEST TOOLS

• ReSharper

15
MOCKING FRAMEWORK: MOQ
• Dynamically implement a interface

• Test

16
BEST PRACTICES
• New projects have to include unit test
• Legacy code : when a bug is raised, write a UT that
fails, fix t...
MORE TEST FIRST TECHNIQUES
• ATDD - Acceptance test driven development
Test written in a business language with a wiki

• ...
CONCLUSION
Everyone must be involved !

19
REFERENCES
•

http://blog.octo.com/quels-sont-les-types-de-tests-quel%E2%80%99on-utilise-sur-un-projet-agile/

•

http://g...
FIND OUT MORE
• On https://techblog.betclicgroup.com/
ABOUT BETCLIC
•

•

•

Betclic Everest Group, one of the world leaders in online gaming, has a unique portfolio
comprising...
Upcoming SlideShare
Loading in …5
×

Introduction to Unit Tests and TDD

1,181 views

Published on

Discover why unit testing is such an important practice in software development and learn about Test Driven Development, mocking and other code testing practices in .Net

Published in: Technology, Education
  • Be the first to comment

Introduction to Unit Tests and TDD

  1. 1. Introduction to Unit Tests & TDD
  2. 2. UNIT TEST IN AN AGILE CONTEXT Agile XP UT 2
  3. 3. DEFINITION A unit test confirms functionality of a small unit of functionality or component in a larger system • • • • Written by developers isolate piece of code No use of database or external ressources Find problems early in dev cycle 3
  4. 4. INITIAL REACTIONS 4
  5. 5. BENEFITS • Higher quality (less bug) • Living documentation • Well-crafted code • Easier refactoring • Automatic regression harness 5
  6. 6. HOW UNIT TEST FRAMEWORKS WORK Unit test Runner .exe My Code My unit test code Unit Test Common Lib Test Results Code Coverage 6
  7. 7. TEST DRIVEN DEVELOPMENT 1. Create a falling test  Red 2. Make the test pass Green 3. Refactor  Improve the internal implementation without changing the external contract or behavior 7
  8. 8. THE TESTS ARE THE SPECS *.doc files can’t prove software works ! 8
  9. 9. LIMITATION • 100 % code coverage impossible to reach • Impossible to catch all errors 9
  10. 10. UNIT TEST OR INTEGRATION TEST ? Too often we try to write unmaintainable integration tests UT IT UT 10
  11. 11. UNIT TEST VS. DATA BASE • Isolate data access with an interface 11
  12. 12. UNIT TEST VS. PROVIDERS Critical for teams using third-parties. • Unit Test to simulate provider calls • UnitTest unit to send data to providers If the provider updates its interface  test fails 12
  13. 13. TOOLS 13
  14. 14. .NET UNIT TESTING FRAMEWORKS 14
  15. 15. • Visual studio default interface MS TEST TOOLS • ReSharper 15
  16. 16. MOCKING FRAMEWORK: MOQ • Dynamically implement a interface • Test 16
  17. 17. BEST PRACTICES • New projects have to include unit test • Legacy code : when a bug is raised, write a UT that fails, fix the bug and the UT is successful. 17
  18. 18. MORE TEST FIRST TECHNIQUES • ATDD - Acceptance test driven development Test written in a business language with a wiki • BDD Behavior Driven Development 18
  19. 19. CONCLUSION Everyone must be involved ! 19
  20. 20. REFERENCES • http://blog.octo.com/quels-sont-les-types-de-tests-quel%E2%80%99on-utilise-sur-un-projet-agile/ • http://googletesting.blogspot.fr/ • http://weblogs.asp.net/garrypilkington/archive/2010/02/21/setting-upioc-with-mvc-quickly.aspx 20
  21. 21. FIND OUT MORE • On https://techblog.betclicgroup.com/
  22. 22. ABOUT BETCLIC • • • Betclic Everest Group, one of the world leaders in online gaming, has a unique portfolio comprising various complementary international brands: Betclic, Everest Gaming, bet-athome.com, Expekt… Active in 100 countries with more than 12 million customers worldwide, the Group is committed to promoting secure and responsible gaming and is a member of several international professional associations including the EGBA (European Gaming and Betting Association) and the ESSA (European Sports Security Association). Through our brands, Betclic Everest Group places expertise, technological know-how and security at the heart of our strategy to deliver an on-line gaming offer attuned to the passion of our players.

×