introduction to unit tests and tdd

22
Introduction to Unit Tests & TDD

Upload: betclic-everest-group-tech-team

Post on 10-May-2015

697 views

Category:

Technology


2 download

DESCRIPTION

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

TRANSCRIPT

Page 1: Introduction to Unit Tests and TDD

Introduction to Unit Tests & TDD

Page 2: Introduction to Unit Tests and TDD

2

UNIT TEST IN AN AGILE CONTEXT

Agile XP UT

Page 3: Introduction to Unit Tests and TDD

A unit test confirms functionality of a small unit of functionality or component

in a larger system

3

DEFINITION

• Written by developers

• isolate piece of code

• No use of database or external ressources

• Find problems early in dev cycle

Page 4: Introduction to Unit Tests and TDD

4

INITIAL REACTIONS

Page 5: Introduction to Unit Tests and TDD

• Higher quality (less bug)

• Living documentation

• Well-crafted code

• Easier refactoring

• Automatic regression harness

5

BENEFITS

Page 6: Introduction to Unit Tests and TDD

6

HOW UNIT TEST FRAMEWORKS WORK

My Code

My unit test code

Unit test Runner .exe

Unit Test Common Lib

Test Results

Code Coverage

Page 7: Introduction to Unit Tests and TDD

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

Page 8: Introduction to Unit Tests and TDD

8

THE TESTS ARE THE SPECS

*.doc files can’t prove software works !

Page 9: Introduction to Unit Tests and TDD

• 100 % code coverage impossible to reach

• Impossible to catch all errors

9

LIMITATION

Page 10: Introduction to Unit Tests and TDD

10

UNIT TEST OR INTEGRATION TEST ?

IT UT

UT

Too often we try to write unmaintainable integration tests

Page 11: Introduction to Unit Tests and TDD

• Isolate data access with an interface

11

UNIT TEST VS. DATA BASE

Page 12: Introduction to Unit Tests and TDD

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

UNIT TEST VS. PROVIDERS

Page 13: Introduction to Unit Tests and TDD

13

TOOLS

Page 14: Introduction to Unit Tests and TDD

14

.NET UNIT TESTING FRAMEWORKS

Page 15: Introduction to Unit Tests and TDD

15

MS TEST TOOLS • Visual studio default interface

• ReSharper

Page 16: Introduction to Unit Tests and TDD

16

MOCKING FRAMEWORK: MOQ

• Test

• Dynamically implement a interface

Page 17: Introduction to Unit Tests and TDD

• 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

BEST PRACTICES

Page 18: Introduction to Unit Tests and TDD

18

MORE TEST FIRST TECHNIQUES

• ATDD - Acceptance test driven development

Test written in a business language with a wiki

• BDD

Behavior Driven Development

Page 19: Introduction to Unit Tests and TDD

19

CONCLUSION

Everyone must be involved !

Page 20: Introduction to Unit Tests and TDD

20

REFERENCES

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

• http://googletesting.blogspot.fr/

• http://weblogs.asp.net/garrypilkington/archive/2010/02/21/setting-up-ioc-with-mvc-quickly.aspx

Page 21: Introduction to Unit Tests and TDD

FIND OUT MORE • On https://techblog.betclicgroup.com/

Page 22: Introduction to Unit Tests and TDD

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-at-home.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.