SlideShare a Scribd company logo
TDD (TEST-DRIVEN DEVELOPMENT) HAS INCREASED IN
popularity both as a practice and as a term.
Although there is a strong association with eXtreme
Programming (XP), more generally there is a certain
set of practices that can be homed in on and applied
across various development models. Decoupling
TDD from XP, which specifically focuses on the
terms programmer tests and test-first program-
ming, and understanding it as a set of microprocess
practices in its own right makes it a more general and
useful tool for programmers, regardless of the devel-
opment macroprocess they are in.
Unit testing and more
The term TDD is often mistakenly used as a syn-
onym for “unit testing”. The relationship between the
two is that unit testing forms part of TDD, but there
is more to TDD than just unit testing. Both critics and
advocates often miss that metonymic distinction.
Unit testing is a general notion that can be
employed and practised in many ways, whether up-
front documentation of test plans associated with up-
front documentation of detailed designs in the classic
waterfall approach (think Niagara Falls and people
in barrels) or more informally by individual pro-
grammers seeking confidence in their own work
and applying the simple tool of an assertion in a
test case that exercises some code they have written.
TDD places unit testing in the context of agile
development by motivating it in a different way
from traditional testing approaches, which typi-
cally borrow from the classic V model of testing –
a smokily mirrored view of the waterfall develop-
ment lifecycle that emphasises testing but divorces
it from other activities making up the main flow of
development 1
.
Effective unit testing can be seen to rest on the
foundation of programmer testing responsibility,
automated tests and example-based tests. TDD
drives that through the design-focused activities of
active test writing, sufficient design and refactoring.
Programmer testing responsibility
Unit tests are sometimes called programmer tests
to differentiate them from system-level tests car-
ried out in a separate testing role or department. It
is important to remember that testing a unit is not
the same as testing a system. Testing a system
involves the software combination of the many code
units, whatever their granularity, and the elements
of the system external to the code, e.g. target software
environment, configuration and broad usage. Units
that are under test as units, rather than as inte-
grated parts, are isolated from the external envi-
ronment, hence “unit” as opposed to “system” or
“integration” testing.
Of course, there is a natural tension in any devel-
opment process between the responsibilities each
role can include and the control it can exercise. A
development role needs to be broad enough to con-
nect to the range of activities involved in software
development, but cohesive enough and appropriately
sized so that responsibilities are not overwhelming.
For the role of developer, the organisational pat-
tern Developer Controls Process defines such a
focus, and includes the following brief 2
:
“Responsibilities of developers include under-
standing requirements, reviewing the solution struc-
ture algorithm with peers, building the
implementation, and performing unit testing.”
However, this does not limit or define the whole
range of testing activities. The system-level per-
spective is explicitly covered in patterns such as
Engage Quality Assurance and Application Design
Is Bounded by Test Design. The inclusion of a code-
testing responsibility in the programmer’s canon
also receives strong support from more orthodox
testing perspectives 3
:
“I find the projects I work on usually go more
smoothly when programmers do some unit and
component testing of their own code. Through the
ascendance of approaches like Extreme Program-
ming, such a position is becoming less controversial…
So, a good practice is to adopt a development process
that provides for unit testing, where programmers
find bugs in their own software, and for component
testing, where programmers test each other’s soft-
ware. (This is sometimes called ‘code swapping.’)
Variations on this approach use concepts like pair
programming and peer reviews of automated com-
ponent test stubs or harnesses.”
However, sometimes responsibility can also trans-
late to burden. Just stating that unit testing is a pro-
grammer’s responsibility does not offer guidance
as to how the responsibility can be met in practical
terms, which is where the other practices fit in.
Automated tests
Automating test execution relieves much of the tedi-
um that fuels the common perception of testing as
a dull and menial task. Unit tests focus on things that
can be automated within a localised and code-cen-
tric view – therefore, by definition, usability tests and
system performance tests are excluded. Tests need
to be written in executable form rather than being
left in the abstract in a programmer’s head or in a
document. For unit tests, the most natural exe-
PROGRAMMERS’WORKSHOP
48 WWW.APPDEVADVISOR.CO.UK
At a glance
• Test-Driven Devel-
opment can be
understood in terms
of three core unit-
testing practices
(examined this time)
and three design-
focused practices
(examined next time).
• Programmer testing
responsibility ensures
that code-centric tests
are the responsibility
of those closest to the
code.
• Automated tests
ensure that unit tests
are executed as
code-on-code rather
than by programmer-
on-code.
• Example-based
test cases ensure
that test cases adopt
a sustainable black-
box testing
approach.
KEVLIN
HENNEY
Testing is one way of making the essentially invisible
act of software development more visible. Kevlin
Henney presents a practical view of unit testing
Driven to tests
cutable form is code in the same language as the unit being test-
ed. And how much more fun is that than the manual approach?
The programmer testing responsibility is realised as a coding
activity!
Automated unit tests are quite definite and repeatable in their
judgement and there is less of “it kinda looks OK, I think”, “I think
it’s OK, but I don’t have the time to check” or “it didn’t appear
to trip any of the debug assertions when I last ran it by hand, so
I guess it’s OK”.
Automation offers continuous and visible feedback: “All tests
passed, none failed”. Many people underestimate the value of such
feedback. It raises the safety net to a comfortable level and gives
a more concrete and local indication of status and progress than
many other measures: counting lines of code is simply not a
useful measure of progress at any level; end-user accessible
functionality is a system- and team-level indicator; test cases offer
a personal minute-to-minute, day-to-day progress indicator.
Unit test coverage is inevitably incomplete in practice, so by
definition one’s ability to trap defects is limited to the quality and
quantity of those tests. This is not a criticism of testing, just an
observation on practical limits. If one were to claim, “we will catch
all defects through unit testing” then that would be a flight of fancy
that should be shot down in flames by precisely the observa-
tion just made. However, I know of no one advocating any form
of unit testing who believes such a proposition. What is guar-
anteed is that when you have no unit tests, you will catch precisely
zero defects through unit testing! Defects represent a form of
waste that can brake – and even break – development if allowed
to accumulate.
It is worth remembering that perhaps one of the most waste-
ful code-related activities of all is debugging. Pretty much any
opportunity to prevent a situation where debugging becomes a
normal and necessary activity should be taken – tests, static
analysis, reviews, etc. Unlike debugging, all of these activities can
be estimated reasonably in terms of the time they take; debug-
ging lacks this basic property and is also labour intensive. Writ-
ing a test involves effort, but with a significantly smaller and
consistent schedule footprint. Writing a test is much more lin-
ear and far easier to estimate, and running an automated test is
not a labour-intensive activity. Debugging is not a sustainably
cost-effective development practice.
Example-based test cases
The goal of unit tests is to test functional behaviour, which can
be expressed using assertions, rather than operational behaviour,
e.g. performance. There are many different unit-testing styles.
A distinction often drawn is between black-box testing and
white-box testing (also known as structural testing or glass-
box testing). The premise of white-box testing is that tests are
based on the code as written and they explore the paths and
values based on the internal structure of the code. For classes this
means that the question of examining private data and using pri-
vate methods often raises its head.
And it is this question that highlights some of the shortcom-
ings of the white-box testing approach. White-box testing must
by necessity be carried out after the code is written: before it is
written there is no structure on which to perform structural
testing. Its emphasis on coverage and this sequencing in devel-
opment can expose it to the cutting edge of schedule pressure.
White-box testing is also coupled to the implementation of a
concept: private details are exposed, poked and prodded. Changes
to the implementation, even when functional behaviour is pre-
served, will likely break the tests. Thus, the set of test cases is brit-
tle in the face of change, which will discourage programmers
either from making internal changes that ought to be made or
from carrying out white-box testing in the first place.
The point of partitioning a system into encapsulated parts is
to reduce the coupling of one part of a system on another, allow-
ing more degrees of freedom in implementation behind an inter-
face. White-box testing can strip a system and its developers of
that freedom. It is interfaces that define the usage and the path
of dependencies within a partitioned system. Consequently, it is
interfaces that affect the lines of responsibilityand communication
in development. This suggests that other development activities
need both to respect and to support these boundaries and inten-
tions; working against them can introduce unnecessary friction
and distortion 4
.
Many previous articles have emphasised the contract metaphor
as one of the richer ways of reasoning about an interface 5, 6, 7
. Con-
tracts take a black-box view, focusing on interfaces and con-
straints on – but not details of – implementation. A black-box
test is based on asserting expected effects based on testing given
inputs in a given situation.
An example-based style of black-box testing focuses on pre-
senting tests of an implementation through specific examples that
use its interface. The contract can be formulated, framed and test-
ed through representative samples 8
, as opposed to exhaustive-
ly and exhaustingly running through all possible combinations
of inputs for their outputs.
Next time...
The combination of programmer testing responsibility, auto-
mated tests and example-based test cases offers motivation
and a platform for practical unit testing. Test-Driven Develop-
ment stands on this base, employing the combination of active
testing, sufficient design and refactoring, to take the role of
testing more solidly into design, and vice versa. s
References
1. Kevlin Henney, “Learning Curve”, Application
Development Advisor, March 2005
2. James O Coplien and Neil B Harrison, Organizational
Patterns of Agile Software Development, Pearson Prentice
Hall, 2005
3. Rex Black, Critical Testing Processes, Addison-Wesley, 2004
4. Melvin E Conway, “How Do Committees Invent”,
Datamation, April 1968, available from
www.melconway.com/research/committees.html
5. Kevlin Henney, “Sorted”, Application Development
Advisor, July 2003, available from www.curbralan.com
6. Kevlin Henney, “No Memory for Contracts”, Application
Development Advisor, September 2004, available from
www.curbralan.com
7. Kevlin Henney, “First Among Equals”, Application
Development Advisor, November 2004, available from
www.curbralan.com
8. Kevlin Henney, “Put to the Test”, Application
Development Advisor, November 2002, available from
www.curbralan.com
Kevlin Henney is an independent software development con-
sultant and trainer. He can be reached at www.curbralan.com
PROGRAMMERS’WORKSHOP
MAY-JUNE 2005 49

More Related Content

What's hot

Exceptional Naming
Exceptional NamingExceptional Naming
Exceptional Naming
Kevlin Henney
 
What's in a Name?
What's in a Name?What's in a Name?
What's in a Name?
Kevlin Henney
 
09 grasp
09 grasp09 grasp
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
Ian Cooper webinar for DDD Iran: Kent beck style tdd   seven years afterIan Cooper webinar for DDD Iran: Kent beck style tdd   seven years after
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
Iranian Domain-Driven Design Community
 
Put to the Test
Put to the TestPut to the Test
Put to the Test
Kevlin Henney
 
Final grasp ASE
Final grasp ASEFinal grasp ASE
Final grasp ASE
babak danyal
 
Test Driven Development:Unit Testing, Dependency Injection, Mocking
Test Driven Development:Unit Testing, Dependency Injection, MockingTest Driven Development:Unit Testing, Dependency Injection, Mocking
Test Driven Development:Unit Testing, Dependency Injection, Mocking
mrjawright
 
Tdd and-design-draft
Tdd and-design-draftTdd and-design-draft
Tdd and-design-draft
PrabudhGupta1
 
Getting Started With Testing
Getting Started With TestingGetting Started With Testing
Getting Started With Testing
Giovanni Scerra ☃
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)
nedirtv
 
Responsibility Driven Design
Responsibility Driven DesignResponsibility Driven Design
Responsibility Driven DesignHarsh Jegadeesan
 
How I Learned To Apply Design Patterns
How I Learned To Apply Design PatternsHow I Learned To Apply Design Patterns
How I Learned To Apply Design Patterns
Andy Maleh
 
SAD10 - Refactoring
SAD10 - RefactoringSAD10 - Refactoring
SAD10 - Refactoring
Michael Heron
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Sachithra Gayan
 
Refactoring for Design Smells - ICSE 2014 Tutorial
Refactoring for Design Smells - ICSE 2014 TutorialRefactoring for Design Smells - ICSE 2014 Tutorial
Refactoring for Design Smells - ICSE 2014 Tutorial
Tushar Sharma
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven Development
Ferdous Mahmud Shaon
 
How To Navigate And Extend The Flex Infrastructure
How To Navigate And Extend The Flex InfrastructureHow To Navigate And Extend The Flex Infrastructure
How To Navigate And Extend The Flex Infrastructuremichael.labriola
 
Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010
guest5639fa9
 
Systematic error management - we ported rudder to zio
Systematic error management - we ported rudder to zioSystematic error management - we ported rudder to zio
Systematic error management - we ported rudder to zio
fanf42
 

What's hot (20)

TestDrivenDeveloment
TestDrivenDevelomentTestDrivenDeveloment
TestDrivenDeveloment
 
Exceptional Naming
Exceptional NamingExceptional Naming
Exceptional Naming
 
What's in a Name?
What's in a Name?What's in a Name?
What's in a Name?
 
09 grasp
09 grasp09 grasp
09 grasp
 
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
Ian Cooper webinar for DDD Iran: Kent beck style tdd   seven years afterIan Cooper webinar for DDD Iran: Kent beck style tdd   seven years after
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
 
Put to the Test
Put to the TestPut to the Test
Put to the Test
 
Final grasp ASE
Final grasp ASEFinal grasp ASE
Final grasp ASE
 
Test Driven Development:Unit Testing, Dependency Injection, Mocking
Test Driven Development:Unit Testing, Dependency Injection, MockingTest Driven Development:Unit Testing, Dependency Injection, Mocking
Test Driven Development:Unit Testing, Dependency Injection, Mocking
 
Tdd and-design-draft
Tdd and-design-draftTdd and-design-draft
Tdd and-design-draft
 
Getting Started With Testing
Getting Started With TestingGetting Started With Testing
Getting Started With Testing
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)
 
Responsibility Driven Design
Responsibility Driven DesignResponsibility Driven Design
Responsibility Driven Design
 
How I Learned To Apply Design Patterns
How I Learned To Apply Design PatternsHow I Learned To Apply Design Patterns
How I Learned To Apply Design Patterns
 
SAD10 - Refactoring
SAD10 - RefactoringSAD10 - Refactoring
SAD10 - Refactoring
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Refactoring for Design Smells - ICSE 2014 Tutorial
Refactoring for Design Smells - ICSE 2014 TutorialRefactoring for Design Smells - ICSE 2014 Tutorial
Refactoring for Design Smells - ICSE 2014 Tutorial
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven Development
 
How To Navigate And Extend The Flex Infrastructure
How To Navigate And Extend The Flex InfrastructureHow To Navigate And Extend The Flex Infrastructure
How To Navigate And Extend The Flex Infrastructure
 
Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010
 
Systematic error management - we ported rudder to zio
Systematic error management - we ported rudder to zioSystematic error management - we ported rudder to zio
Systematic error management - we ported rudder to zio
 

Viewers also liked

Modulo quimica 2
Modulo quimica 2Modulo quimica 2
Modulo quimica 2
angie paola parra mosos
 
Ubicacion
UbicacionUbicacion
101 home business_success_quotes
101 home business_success_quotes101 home business_success_quotes
101 home business_success_quotes
danbeldowicz
 
模組化合成器介紹@NCTU, 2013.10.15
模組化合成器介紹@NCTU, 2013.10.15模組化合成器介紹@NCTU, 2013.10.15
模組化合成器介紹@NCTU, 2013.10.15
analoguemotions
 
Subir tic
Subir ticSubir tic
Subir tic
Cindy Giorgi
 
República Popular do Corinthians - Semiótica Perceiana
República Popular do Corinthians - Semiótica PerceianaRepública Popular do Corinthians - Semiótica Perceiana
República Popular do Corinthians - Semiótica PerceianaCaroline Arice
 
Vagas 01-05-2016
Vagas 01-05-2016Vagas 01-05-2016
Vagas 01-05-2016
Empregos Manaus
 
Legendy Laochtir
Legendy LaochtirLegendy Laochtir
Legendy Laochtir
Maciej Kurek
 
We are ludwig
We are ludwigWe are ludwig
We are ludwig
Charles Nadler
 
崩壊地名APIを作ってみた
崩壊地名APIを作ってみた崩壊地名APIを作ってみた
崩壊地名APIを作ってみた
青島 英和
 
Puppet Camp Chicago 2014: Running Multiple Puppet Masters (Beginner)
Puppet Camp Chicago 2014: Running Multiple Puppet Masters (Beginner) Puppet Camp Chicago 2014: Running Multiple Puppet Masters (Beginner)
Puppet Camp Chicago 2014: Running Multiple Puppet Masters (Beginner)
Puppet
 
Cuatro Estaciones
Cuatro EstacionesCuatro Estaciones
Cuatro Estaciones
Tefyta Jiménez
 
Microsoft Office 2007 PL. Rady i wskazówki. Rozwiązania w biznesie
Microsoft Office 2007 PL. Rady i wskazówki. Rozwiązania w biznesieMicrosoft Office 2007 PL. Rady i wskazówki. Rozwiązania w biznesie
Microsoft Office 2007 PL. Rady i wskazówki. Rozwiązania w biznesie
Wydawnictwo Helion
 
Hardware/Software Integration Testing
Hardware/Software Integration TestingHardware/Software Integration Testing
Hardware/Software Integration Testing
Johan Hoberg
 
15 Trends for 2015
15 Trends for 201515 Trends for 2015
15 Trends for 2015
Steve Williamson
 
Socialbakers Harvard Presentation
Socialbakers Harvard PresentationSocialbakers Harvard Presentation
Socialbakers Harvard Presentation
Jan Rezab
 
Strategic Decision Support Systems Design: Integration Approach Between Exper...
Strategic Decision Support Systems Design: Integration Approach Between Exper...Strategic Decision Support Systems Design: Integration Approach Between Exper...
Strategic Decision Support Systems Design: Integration Approach Between Exper...Ghomari Réda
 
BuzzSumo Content Marketing Masterclass - ROI
BuzzSumo Content Marketing Masterclass - ROIBuzzSumo Content Marketing Masterclass - ROI
BuzzSumo Content Marketing Masterclass - ROI
Michael Brenner
 

Viewers also liked (20)

Modulo quimica 2
Modulo quimica 2Modulo quimica 2
Modulo quimica 2
 
Ubicacion
UbicacionUbicacion
Ubicacion
 
101 home business_success_quotes
101 home business_success_quotes101 home business_success_quotes
101 home business_success_quotes
 
模組化合成器介紹@NCTU, 2013.10.15
模組化合成器介紹@NCTU, 2013.10.15模組化合成器介紹@NCTU, 2013.10.15
模組化合成器介紹@NCTU, 2013.10.15
 
Subir tic
Subir ticSubir tic
Subir tic
 
República Popular do Corinthians - Semiótica Perceiana
República Popular do Corinthians - Semiótica PerceianaRepública Popular do Corinthians - Semiótica Perceiana
República Popular do Corinthians - Semiótica Perceiana
 
Vagas 01-05-2016
Vagas 01-05-2016Vagas 01-05-2016
Vagas 01-05-2016
 
Legendy Laochtir
Legendy LaochtirLegendy Laochtir
Legendy Laochtir
 
We are ludwig
We are ludwigWe are ludwig
We are ludwig
 
1.ders
1.ders1.ders
1.ders
 
崩壊地名APIを作ってみた
崩壊地名APIを作ってみた崩壊地名APIを作ってみた
崩壊地名APIを作ってみた
 
Puppet Camp Chicago 2014: Running Multiple Puppet Masters (Beginner)
Puppet Camp Chicago 2014: Running Multiple Puppet Masters (Beginner) Puppet Camp Chicago 2014: Running Multiple Puppet Masters (Beginner)
Puppet Camp Chicago 2014: Running Multiple Puppet Masters (Beginner)
 
Cuatro Estaciones
Cuatro EstacionesCuatro Estaciones
Cuatro Estaciones
 
Microsoft Office 2007 PL. Rady i wskazówki. Rozwiązania w biznesie
Microsoft Office 2007 PL. Rady i wskazówki. Rozwiązania w biznesieMicrosoft Office 2007 PL. Rady i wskazówki. Rozwiązania w biznesie
Microsoft Office 2007 PL. Rady i wskazówki. Rozwiązania w biznesie
 
Hardware/Software Integration Testing
Hardware/Software Integration TestingHardware/Software Integration Testing
Hardware/Software Integration Testing
 
15 Trends for 2015
15 Trends for 201515 Trends for 2015
15 Trends for 2015
 
Physic P2 F5
Physic P2 F5Physic P2 F5
Physic P2 F5
 
Socialbakers Harvard Presentation
Socialbakers Harvard PresentationSocialbakers Harvard Presentation
Socialbakers Harvard Presentation
 
Strategic Decision Support Systems Design: Integration Approach Between Exper...
Strategic Decision Support Systems Design: Integration Approach Between Exper...Strategic Decision Support Systems Design: Integration Approach Between Exper...
Strategic Decision Support Systems Design: Integration Approach Between Exper...
 
BuzzSumo Content Marketing Masterclass - ROI
BuzzSumo Content Marketing Masterclass - ROIBuzzSumo Content Marketing Masterclass - ROI
BuzzSumo Content Marketing Masterclass - ROI
 

Similar to Driven to Tests

Software testing q as collection by ravi
Software testing q as   collection by raviSoftware testing q as   collection by ravi
Software testing q as collection by raviRavindranath Tagore
 
Software testing
Software testingSoftware testing
Software testing
Rico-j Laurente
 
Implementing a testing strategy
Implementing a testing strategyImplementing a testing strategy
Implementing a testing strategy
Daniel Giraldo
 
Automated testing-whitepaper
Automated testing-whitepaperAutomated testing-whitepaper
Automated testing-whitepaper
imdurgesh
 
Lesson 7...Question Part 1
Lesson 7...Question Part 1Lesson 7...Question Part 1
Lesson 7...Question Part 1
bhushan Nehete
 
Assignment 1 Week 2.docx1Assignment 1 Topic Selection.docx
Assignment 1 Week 2.docx1Assignment 1 Topic Selection.docxAssignment 1 Week 2.docx1Assignment 1 Topic Selection.docx
Assignment 1 Week 2.docx1Assignment 1 Topic Selection.docx
sherni1
 
Testing in an agile environment
Testing in an agile environmentTesting in an agile environment
Testing in an agile environmentCristiano Caetano
 
Exploratory Testing, A Guide Towards Better Test Coverage.pdf
Exploratory Testing, A Guide Towards Better Test Coverage.pdfExploratory Testing, A Guide Towards Better Test Coverage.pdf
Exploratory Testing, A Guide Towards Better Test Coverage.pdf
pCloudy
 
Testing throughout the software life cycle (test types)
Testing throughout the software life cycle (test types)Testing throughout the software life cycle (test types)
Testing throughout the software life cycle (test types)
tyas setyo
 
Software testing & Quality Assurance
Software testing & Quality Assurance Software testing & Quality Assurance
Software testing & Quality Assurance
Webtech Learning
 
Object Oriented Testing
Object Oriented TestingObject Oriented Testing
Object Oriented Testing
AMITJain879
 
Testing 3 test design techniques
Testing 3 test design techniquesTesting 3 test design techniques
Testing 3 test design techniques
Mini Marsiah
 
Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++
Hong Le Van
 
Increasing Quality with DevOps
Increasing Quality with DevOpsIncreasing Quality with DevOps
Increasing Quality with DevOps
Coveros, Inc.
 
Software_testing Unit 1 bca V.pdf
Software_testing Unit 1 bca V.pdfSoftware_testing Unit 1 bca V.pdf
Software_testing Unit 1 bca V.pdf
AnupmaMunshi
 
Testing throughout the software life cycle
Testing throughout the software life cycleTesting throughout the software life cycle
Testing throughout the software life cycle
muhamad iqbal
 
Software Testing
Software TestingSoftware Testing
Software Testing
Faisal Hussain
 
Software testing
Software testingSoftware testing
Software testing
Sengu Msc
 

Similar to Driven to Tests (20)

Qa Faqs
Qa FaqsQa Faqs
Qa Faqs
 
Software testing q as collection by ravi
Software testing q as   collection by raviSoftware testing q as   collection by ravi
Software testing q as collection by ravi
 
Software testing
Software testingSoftware testing
Software testing
 
Implementing a testing strategy
Implementing a testing strategyImplementing a testing strategy
Implementing a testing strategy
 
Automated testing-whitepaper
Automated testing-whitepaperAutomated testing-whitepaper
Automated testing-whitepaper
 
Lesson 7...Question Part 1
Lesson 7...Question Part 1Lesson 7...Question Part 1
Lesson 7...Question Part 1
 
Assignment 1 Week 2.docx1Assignment 1 Topic Selection.docx
Assignment 1 Week 2.docx1Assignment 1 Topic Selection.docxAssignment 1 Week 2.docx1Assignment 1 Topic Selection.docx
Assignment 1 Week 2.docx1Assignment 1 Topic Selection.docx
 
Testing in an agile environment
Testing in an agile environmentTesting in an agile environment
Testing in an agile environment
 
Exploratory Testing, A Guide Towards Better Test Coverage.pdf
Exploratory Testing, A Guide Towards Better Test Coverage.pdfExploratory Testing, A Guide Towards Better Test Coverage.pdf
Exploratory Testing, A Guide Towards Better Test Coverage.pdf
 
Testing throughout the software life cycle (test types)
Testing throughout the software life cycle (test types)Testing throughout the software life cycle (test types)
Testing throughout the software life cycle (test types)
 
Software testing & Quality Assurance
Software testing & Quality Assurance Software testing & Quality Assurance
Software testing & Quality Assurance
 
Testing
Testing Testing
Testing
 
Object Oriented Testing
Object Oriented TestingObject Oriented Testing
Object Oriented Testing
 
Testing 3 test design techniques
Testing 3 test design techniquesTesting 3 test design techniques
Testing 3 test design techniques
 
Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++
 
Increasing Quality with DevOps
Increasing Quality with DevOpsIncreasing Quality with DevOps
Increasing Quality with DevOps
 
Software_testing Unit 1 bca V.pdf
Software_testing Unit 1 bca V.pdfSoftware_testing Unit 1 bca V.pdf
Software_testing Unit 1 bca V.pdf
 
Testing throughout the software life cycle
Testing throughout the software life cycleTesting throughout the software life cycle
Testing throughout the software life cycle
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Software testing
Software testingSoftware testing
Software testing
 

More from Kevlin Henney

Program with GUTs
Program with GUTsProgram with GUTs
Program with GUTs
Kevlin Henney
 
The Case for Technical Excellence
The Case for Technical ExcellenceThe Case for Technical Excellence
The Case for Technical Excellence
Kevlin Henney
 
Empirical Development
Empirical DevelopmentEmpirical Development
Empirical Development
Kevlin Henney
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
Kevlin Henney
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
Kevlin Henney
 
Solid Deconstruction
Solid DeconstructionSolid Deconstruction
Solid Deconstruction
Kevlin Henney
 
Get Kata
Get KataGet Kata
Get Kata
Kevlin Henney
 
Procedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayProcedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went Away
Kevlin Henney
 
Structure and Interpretation of Test Cases
Structure and Interpretation of Test CasesStructure and Interpretation of Test Cases
Structure and Interpretation of Test Cases
Kevlin Henney
 
Agility ≠ Speed
Agility ≠ SpeedAgility ≠ Speed
Agility ≠ Speed
Kevlin Henney
 
Refactoring to Immutability
Refactoring to ImmutabilityRefactoring to Immutability
Refactoring to Immutability
Kevlin Henney
 
Old Is the New New
Old Is the New NewOld Is the New New
Old Is the New New
Kevlin Henney
 
Turning Development Outside-In
Turning Development Outside-InTurning Development Outside-In
Turning Development Outside-In
Kevlin Henney
 
Giving Code a Good Name
Giving Code a Good NameGiving Code a Good Name
Giving Code a Good Name
Kevlin Henney
 
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Kevlin Henney
 
Thinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation QuadrantThinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation Quadrant
Kevlin Henney
 
Code as Risk
Code as RiskCode as Risk
Code as Risk
Kevlin Henney
 
Software Is Details
Software Is DetailsSoftware Is Details
Software Is Details
Kevlin Henney
 
Game of Sprints
Game of SprintsGame of Sprints
Game of Sprints
Kevlin Henney
 
Good Code
Good CodeGood Code
Good Code
Kevlin Henney
 

More from Kevlin Henney (20)

Program with GUTs
Program with GUTsProgram with GUTs
Program with GUTs
 
The Case for Technical Excellence
The Case for Technical ExcellenceThe Case for Technical Excellence
The Case for Technical Excellence
 
Empirical Development
Empirical DevelopmentEmpirical Development
Empirical Development
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
Solid Deconstruction
Solid DeconstructionSolid Deconstruction
Solid Deconstruction
 
Get Kata
Get KataGet Kata
Get Kata
 
Procedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayProcedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went Away
 
Structure and Interpretation of Test Cases
Structure and Interpretation of Test CasesStructure and Interpretation of Test Cases
Structure and Interpretation of Test Cases
 
Agility ≠ Speed
Agility ≠ SpeedAgility ≠ Speed
Agility ≠ Speed
 
Refactoring to Immutability
Refactoring to ImmutabilityRefactoring to Immutability
Refactoring to Immutability
 
Old Is the New New
Old Is the New NewOld Is the New New
Old Is the New New
 
Turning Development Outside-In
Turning Development Outside-InTurning Development Outside-In
Turning Development Outside-In
 
Giving Code a Good Name
Giving Code a Good NameGiving Code a Good Name
Giving Code a Good Name
 
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
 
Thinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation QuadrantThinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation Quadrant
 
Code as Risk
Code as RiskCode as Risk
Code as Risk
 
Software Is Details
Software Is DetailsSoftware Is Details
Software Is Details
 
Game of Sprints
Game of SprintsGame of Sprints
Game of Sprints
 
Good Code
Good CodeGood Code
Good Code
 

Recently uploaded

Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
abdulrafaychaudhry
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
abdulrafaychaudhry
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 

Recently uploaded (20)

Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 

Driven to Tests

  • 1. TDD (TEST-DRIVEN DEVELOPMENT) HAS INCREASED IN popularity both as a practice and as a term. Although there is a strong association with eXtreme Programming (XP), more generally there is a certain set of practices that can be homed in on and applied across various development models. Decoupling TDD from XP, which specifically focuses on the terms programmer tests and test-first program- ming, and understanding it as a set of microprocess practices in its own right makes it a more general and useful tool for programmers, regardless of the devel- opment macroprocess they are in. Unit testing and more The term TDD is often mistakenly used as a syn- onym for “unit testing”. The relationship between the two is that unit testing forms part of TDD, but there is more to TDD than just unit testing. Both critics and advocates often miss that metonymic distinction. Unit testing is a general notion that can be employed and practised in many ways, whether up- front documentation of test plans associated with up- front documentation of detailed designs in the classic waterfall approach (think Niagara Falls and people in barrels) or more informally by individual pro- grammers seeking confidence in their own work and applying the simple tool of an assertion in a test case that exercises some code they have written. TDD places unit testing in the context of agile development by motivating it in a different way from traditional testing approaches, which typi- cally borrow from the classic V model of testing – a smokily mirrored view of the waterfall develop- ment lifecycle that emphasises testing but divorces it from other activities making up the main flow of development 1 . Effective unit testing can be seen to rest on the foundation of programmer testing responsibility, automated tests and example-based tests. TDD drives that through the design-focused activities of active test writing, sufficient design and refactoring. Programmer testing responsibility Unit tests are sometimes called programmer tests to differentiate them from system-level tests car- ried out in a separate testing role or department. It is important to remember that testing a unit is not the same as testing a system. Testing a system involves the software combination of the many code units, whatever their granularity, and the elements of the system external to the code, e.g. target software environment, configuration and broad usage. Units that are under test as units, rather than as inte- grated parts, are isolated from the external envi- ronment, hence “unit” as opposed to “system” or “integration” testing. Of course, there is a natural tension in any devel- opment process between the responsibilities each role can include and the control it can exercise. A development role needs to be broad enough to con- nect to the range of activities involved in software development, but cohesive enough and appropriately sized so that responsibilities are not overwhelming. For the role of developer, the organisational pat- tern Developer Controls Process defines such a focus, and includes the following brief 2 : “Responsibilities of developers include under- standing requirements, reviewing the solution struc- ture algorithm with peers, building the implementation, and performing unit testing.” However, this does not limit or define the whole range of testing activities. The system-level per- spective is explicitly covered in patterns such as Engage Quality Assurance and Application Design Is Bounded by Test Design. The inclusion of a code- testing responsibility in the programmer’s canon also receives strong support from more orthodox testing perspectives 3 : “I find the projects I work on usually go more smoothly when programmers do some unit and component testing of their own code. Through the ascendance of approaches like Extreme Program- ming, such a position is becoming less controversial… So, a good practice is to adopt a development process that provides for unit testing, where programmers find bugs in their own software, and for component testing, where programmers test each other’s soft- ware. (This is sometimes called ‘code swapping.’) Variations on this approach use concepts like pair programming and peer reviews of automated com- ponent test stubs or harnesses.” However, sometimes responsibility can also trans- late to burden. Just stating that unit testing is a pro- grammer’s responsibility does not offer guidance as to how the responsibility can be met in practical terms, which is where the other practices fit in. Automated tests Automating test execution relieves much of the tedi- um that fuels the common perception of testing as a dull and menial task. Unit tests focus on things that can be automated within a localised and code-cen- tric view – therefore, by definition, usability tests and system performance tests are excluded. Tests need to be written in executable form rather than being left in the abstract in a programmer’s head or in a document. For unit tests, the most natural exe- PROGRAMMERS’WORKSHOP 48 WWW.APPDEVADVISOR.CO.UK At a glance • Test-Driven Devel- opment can be understood in terms of three core unit- testing practices (examined this time) and three design- focused practices (examined next time). • Programmer testing responsibility ensures that code-centric tests are the responsibility of those closest to the code. • Automated tests ensure that unit tests are executed as code-on-code rather than by programmer- on-code. • Example-based test cases ensure that test cases adopt a sustainable black- box testing approach. KEVLIN HENNEY Testing is one way of making the essentially invisible act of software development more visible. Kevlin Henney presents a practical view of unit testing Driven to tests
  • 2. cutable form is code in the same language as the unit being test- ed. And how much more fun is that than the manual approach? The programmer testing responsibility is realised as a coding activity! Automated unit tests are quite definite and repeatable in their judgement and there is less of “it kinda looks OK, I think”, “I think it’s OK, but I don’t have the time to check” or “it didn’t appear to trip any of the debug assertions when I last ran it by hand, so I guess it’s OK”. Automation offers continuous and visible feedback: “All tests passed, none failed”. Many people underestimate the value of such feedback. It raises the safety net to a comfortable level and gives a more concrete and local indication of status and progress than many other measures: counting lines of code is simply not a useful measure of progress at any level; end-user accessible functionality is a system- and team-level indicator; test cases offer a personal minute-to-minute, day-to-day progress indicator. Unit test coverage is inevitably incomplete in practice, so by definition one’s ability to trap defects is limited to the quality and quantity of those tests. This is not a criticism of testing, just an observation on practical limits. If one were to claim, “we will catch all defects through unit testing” then that would be a flight of fancy that should be shot down in flames by precisely the observa- tion just made. However, I know of no one advocating any form of unit testing who believes such a proposition. What is guar- anteed is that when you have no unit tests, you will catch precisely zero defects through unit testing! Defects represent a form of waste that can brake – and even break – development if allowed to accumulate. It is worth remembering that perhaps one of the most waste- ful code-related activities of all is debugging. Pretty much any opportunity to prevent a situation where debugging becomes a normal and necessary activity should be taken – tests, static analysis, reviews, etc. Unlike debugging, all of these activities can be estimated reasonably in terms of the time they take; debug- ging lacks this basic property and is also labour intensive. Writ- ing a test involves effort, but with a significantly smaller and consistent schedule footprint. Writing a test is much more lin- ear and far easier to estimate, and running an automated test is not a labour-intensive activity. Debugging is not a sustainably cost-effective development practice. Example-based test cases The goal of unit tests is to test functional behaviour, which can be expressed using assertions, rather than operational behaviour, e.g. performance. There are many different unit-testing styles. A distinction often drawn is between black-box testing and white-box testing (also known as structural testing or glass- box testing). The premise of white-box testing is that tests are based on the code as written and they explore the paths and values based on the internal structure of the code. For classes this means that the question of examining private data and using pri- vate methods often raises its head. And it is this question that highlights some of the shortcom- ings of the white-box testing approach. White-box testing must by necessity be carried out after the code is written: before it is written there is no structure on which to perform structural testing. Its emphasis on coverage and this sequencing in devel- opment can expose it to the cutting edge of schedule pressure. White-box testing is also coupled to the implementation of a concept: private details are exposed, poked and prodded. Changes to the implementation, even when functional behaviour is pre- served, will likely break the tests. Thus, the set of test cases is brit- tle in the face of change, which will discourage programmers either from making internal changes that ought to be made or from carrying out white-box testing in the first place. The point of partitioning a system into encapsulated parts is to reduce the coupling of one part of a system on another, allow- ing more degrees of freedom in implementation behind an inter- face. White-box testing can strip a system and its developers of that freedom. It is interfaces that define the usage and the path of dependencies within a partitioned system. Consequently, it is interfaces that affect the lines of responsibilityand communication in development. This suggests that other development activities need both to respect and to support these boundaries and inten- tions; working against them can introduce unnecessary friction and distortion 4 . Many previous articles have emphasised the contract metaphor as one of the richer ways of reasoning about an interface 5, 6, 7 . Con- tracts take a black-box view, focusing on interfaces and con- straints on – but not details of – implementation. A black-box test is based on asserting expected effects based on testing given inputs in a given situation. An example-based style of black-box testing focuses on pre- senting tests of an implementation through specific examples that use its interface. The contract can be formulated, framed and test- ed through representative samples 8 , as opposed to exhaustive- ly and exhaustingly running through all possible combinations of inputs for their outputs. Next time... The combination of programmer testing responsibility, auto- mated tests and example-based test cases offers motivation and a platform for practical unit testing. Test-Driven Develop- ment stands on this base, employing the combination of active testing, sufficient design and refactoring, to take the role of testing more solidly into design, and vice versa. s References 1. Kevlin Henney, “Learning Curve”, Application Development Advisor, March 2005 2. James O Coplien and Neil B Harrison, Organizational Patterns of Agile Software Development, Pearson Prentice Hall, 2005 3. Rex Black, Critical Testing Processes, Addison-Wesley, 2004 4. Melvin E Conway, “How Do Committees Invent”, Datamation, April 1968, available from www.melconway.com/research/committees.html 5. Kevlin Henney, “Sorted”, Application Development Advisor, July 2003, available from www.curbralan.com 6. Kevlin Henney, “No Memory for Contracts”, Application Development Advisor, September 2004, available from www.curbralan.com 7. Kevlin Henney, “First Among Equals”, Application Development Advisor, November 2004, available from www.curbralan.com 8. Kevlin Henney, “Put to the Test”, Application Development Advisor, November 2002, available from www.curbralan.com Kevlin Henney is an independent software development con- sultant and trainer. He can be reached at www.curbralan.com PROGRAMMERS’WORKSHOP MAY-JUNE 2005 49