introduction to unit tests and tdd

Post on 10-May-2015

700 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

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

Introduction to Unit Tests & TDD

2

UNIT TEST IN AN AGILE CONTEXT

Agile XP UT

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

4

INITIAL REACTIONS

• Higher quality (less bug)

• Living documentation

• Well-crafted code

• Easier refactoring

• Automatic regression harness

5

BENEFITS

6

HOW UNIT TEST FRAMEWORKS WORK

My Code

My unit test code

Unit test Runner .exe

Unit Test Common Lib

Test Results

Code Coverage

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

8

THE TESTS ARE THE SPECS

*.doc files can’t prove software works !

• 100 % code coverage impossible to reach

• Impossible to catch all errors

9

LIMITATION

10

UNIT TEST OR INTEGRATION TEST ?

IT UT

UT

Too often we try to write unmaintainable integration tests

• Isolate data access with an interface

11

UNIT TEST VS. DATA BASE

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

13

TOOLS

14

.NET UNIT TESTING FRAMEWORKS

15

MS TEST TOOLS • Visual studio default interface

• ReSharper

16

MOCKING FRAMEWORK: MOQ

• Test

• Dynamically implement a interface

• 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

18

MORE TEST FIRST TECHNIQUES

• ATDD - Acceptance test driven development

Test written in a business language with a wiki

• BDD

Behavior Driven Development

19

CONCLUSION

Everyone must be involved !

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

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

top related