test driven development tdd n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Test Driven Development (TDD) PowerPoint Presentation
Download Presentation
Test Driven Development (TDD)

Loading in 2 Seconds...

play fullscreen
1 / 21

Test Driven Development (TDD) - PowerPoint PPT Presentation


  • 275 Views
  • Uploaded on

Test Driven Development (TDD). Presented by Victor Goldberg, Ph.D. The Nature of our Problem. Then a miracle occurs. Good work, but I think we need more detail right here. What is Test Driven Development?. It’s a practice that adds reliability to the development process.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Test Driven Development (TDD)' - mary-kirkland


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
test driven development tdd

Test Driven Development (TDD)

Presented by

Victor Goldberg, Ph.D.

Smalltalk Connections vmgoldberg@earthlink.net

the nature of our problem
The Nature of our Problem

Then a miracle occurs

Good work, but I think we need more detail right here.

Smalltalk Connections vmgoldberg@earthlink.net

what is test driven development
What is Test Driven Development?
  • It’s a practice that adds reliability to the development process.

Smalltalk Connections vmgoldberg@earthlink.net

why is tdd important
Why is TDD important?
  •  Many projects fail because they lack a good testing methodology.
  • It’s common sense, but it isn’t common practice.
  • The sense of continuous reliability and success gives you a feeling of confidence in your code, which makes programming more fun.

Smalltalk Connections vmgoldberg@earthlink.net

how does it work
How does it work?
  • Have a requirement. Let’s say “create a new random card, as for a card game”.
  • Think about what could be a reasonable test to verify compliance with the requirement.
  • Write the test before writing the code. Of course, the test will fail, and that’s ok.
  • Keep things simple.
  • Then, write only the minimally necessary code to make the test pass.
  • This is a process of discovery; as you identify possible improvements, refactor your code relentlessly to implement them.
  • Build, keep, and frequently run your cumulative collection of tests.

Smalltalk Connections vmgoldberg@earthlink.net

there are different kinds of tests
There are different kinds of tests
  • Experiments (a.k.a. spikes),
  • Acceptance tests,
  • Code Behavior tests, and
  • Development code TDD’s main functional tests realm.

  We will also touch on experiments.

Smalltalk Connections vmgoldberg@earthlink.net

a possible initial tdd test in smalltalk st
A Possible Initial TDD Test(in Smalltalk [ST])

testCardDrawnIsWithinRange

| number |

number := card draw numericalValue .

self assert: ( number > 0 ) & ( number < 14 ) .

Method Name

Local variable

Getter – retrieves a result of the action

Action

Object

Smalltalk Connections vmgoldberg@earthlink.net

slide8
Fig 1. The same code in the ST browser.

card is in red because the system doesn’t recognize such an object.

self is an instance of the class TestCards.

assert: is a message sent to self; its argument is a Boolean.

TestCards is a child of TestCase, a class in the SUnit framework.

Smalltalk Connections vmgoldberg@earthlink.net

slide9
Fig 2. When run, the test identifies an error.

The assertion didn’t have the opportunity to fail, because an error was identified before the assertion was applied.

Smalltalk Connections vmgoldberg@earthlink.net

slide10

(The Card class)

Fig 3. The Card class and card instance are created.

The new instance of Card is assigned to the variable card.

(The card instance)

Smalltalk Connections vmgoldberg@earthlink.net

slide11
Fig 4. The test still identifies an error. 

The card instance doesn’t recognize the method #draw.

Designing #draw requires some skill.

We will develop the skill through an experiment.

Smalltalk Connections vmgoldberg@earthlink.net

experiment example in the smalltalk workspace
Experiment Example in the Smalltalk Workspace

r := Random new . frequency := Bag new. "Variables typing"

1 to: 1000000

do: [ :index | |result | 

result := (r next * 13) floor + 1.

result >0 & result < 14

ifTrue: [ frequency add: result]

ifFalse: [ ^ Dialog warn: 'Result out of range' ] .

] .

^ frequency contents.

Fig. 5 The ST Workspace is like scratch paper, a place to experiment.

The experiment here is to find whether our formula for random numbers is acceptable.

Smalltalk Connections vmgoldberg@earthlink.net

slide13
Fig 6. The results of running the code twice.

The distribution of values is in the same range for each outcome, but different for each run. All are within [1, 13]. So, we are confident that our coding of the math is correct.

slide14
Fig 7. After the experiment we feel comfortable writing #draw.

In #draw we assign the result of the calculation to the instance variable numericalValue

Smalltalk Connections vmgoldberg@earthlink.net

slide15
Fig 8. Now the test passes.
  • In this case numericalValue is a getter, a message sent to the card object to retrieve the contents of the instance variable numericalValue.

Smalltalk Connections vmgoldberg@earthlink.net

tdd is fun
TDD is fun!!!

Passing the test

(the green bar)

is the feedback

that makes it fun.

Smalltalk Connections vmgoldberg@earthlink.net

summary
Summary

Smalltalk Connections vmgoldberg@earthlink.net

summary 1
Summary (1)

In TDD:

  • Requirements drive the tests.
  • Tests drive the development of the application code.
  • No application code is written without writing a failing test first.
  • Tests are collected in a suite and the suite is run frequently, like every time after code is written.
  • Test and code are written in elementary increments.
  • Refactoring is a continuous operation, and is supported by a passing battery of tests.

Smalltalk Connections vmgoldberg@earthlink.net

summary 2
Summary (2)

TDD is good because it:

  • Reduces the number of bugs by orders of magnitude,
  • Increases development speed, because less time is spent chasing bugs.
  • Improves code quality because of the increased modularity, and continuous and relentless refactoring.
  • Decreases maintenance costs because the code is easier to follow.

Smalltalk Connections vmgoldberg@earthlink.net

summary 3
Summary (3)

In addition to all its technical contributions to a project,

Test Driven Development succeeds because …

Smalltalk Connections vmgoldberg@earthlink.net