PHX - Session #2 Test Driven Development: Improving .NET Application Performance & Scalability

Post on 05-Dec-2014

1.314 views 1 download

description

 

Transcript of PHX - Session #2 Test Driven Development: Improving .NET Application Performance & Scalability

TEAM SYSTEM: IT’S BIG

Test Driven DevelopmentImproving .NET Application Performance & Scalability

Brendon Birdoes(brendon.birdoes@neudesic.c

om)

TEAM SYSTEM: IT’S BIG

Agenda• Challenges we deal with today• Be Agile - Test Driven Development• Code coverage• Database can be Unit Tested!• Benefits of TDD• Summary• Q&A

TEAM SYSTEM: IT’S BIG

Challenges we deal with today

• Does our code do what we intended?• Documentation – is it updated?• Debug – again?• Change Request – What did I break?

TEAM SYSTEM: IT’S BIG

Get Agile – Test Driven Development

Tools For Agility, Kent Beck

Practices

Tools

TEAM SYSTEM: IT’S BIG

Unit Test Defined• Code programmers write to exercise

each method in the design that run quickly and help localize errors – Isolates and tests a single operation– Run in any environment– Less time debugging– Side affect is documentation!

TEAM SYSTEM: IT’S BIG

Unit Tests Defined• Tests are NOT unit tests when

they…– Talk to a database– Communicate across the network– Touch the file system– Require human intervention (such as

modifying a *.config file, starting a console app, etc.) to run

TEAM SYSTEM: IT’S BIG

What is Test Driven Development?

• Despite the name, TDD focuses on “Design” first, “Test” second

• Basic tenants are:–Write a failing automated test before

you write any code• Focus on interface and use case or problem• Tests get written• Just enough code to pass the test

– Remove duplication (refactor)

TEAM SYSTEM: IT’S BIG

Test Driven DevelopmentThe motto "Red, Green,

Refactor ".

TEAM SYSTEM: IT’S BIG

demoDeveloper Unit Test

TEAM SYSTEM: IT’S BIG

Code Coverage Defined• Also known as “test coverage”• It measures how thoroughly the

automated tests exercise the production code, its source code statements, branches, and expressions

TEAM SYSTEM: IT’S BIG

What degree of code coverage should you aim for?

• Answer: It depends• Average code coverage is around

85%• Biggest blocker to attain 100% -

existing code, auto generated code• Aim for 100% while learning – you’ll

understand why 85% is nicer

TEAM SYSTEM: IT’S BIG

demoCode Coverage

TEAM SYSTEM: IT’S BIG

Database can be Unit Tested!

User Interface

ApplicationCode

UnitTestsData Access

Layer

Stored Procedures

TEAM SYSTEM: IT’S BIG

demoDatabase Unit Test

TEAM SYSTEM: IT’S BIG

TDD in Action: Active BugBug: Expired Credit Cards are being

Credited

TEAM SYSTEM: IT’S BIG

Quality Indicators

Iteration 1 Iteration 3 Iteration 4 Iteration 5Iteration 2

91

20

51

76

60

56

19

18

40

71

80

32.5

12

8

9

TEAM SYSTEM: IT’S BIG

Traditional testing

TEAM SYSTEM: IT’S BIG

Test Driven Development

TEAM SYSTEM: IT’S BIG

TDD - Application Lifecycle

Development Testing & Bug Fixing UATDevelopment

Testing & Bug

FixingUAT

Development and testing/bug fixing take about the same amount of time Development takes more time than testing, and testing time is reduced

Overall lifecycle is shortened

TEAM SYSTEM: IT’S BIG

Unit testing is a learned skill that can only be honed with

experience.

Interfaces

Mock Objects

Better Factored Code

TEAM SYSTEM: IT’S BIG

Starting Test Driven Development

Creating a cultural change is hard…

….. and it can be done.

TEAM SYSTEM: IT’S BIG

Summary• Development becomes more

challenging.• TDD is a great tool to overcome these

challenges• Database can be Unit Tested!• Development is Faster using TDD.• VSTS is a great tool for UT and TDD.

TEAM SYSTEM: IT’S BIG

Q & A

TEAM SYSTEM: IT’S BIG