fredag 19 mars 2010

TDD Beyond Basics dag 2

5 minute rule for arguments, longer argument than that then let go à doesn’t matter!

Även denna dag började varje pass med teorier som
  • Maxwells theory – all is waves
  • Galileo - Speed is relavite to any frame of reference
  • Equivalence principle
  • Einsteins General relativity

Katas

TDD

Unit Tests must comply with FIRST:

FIRST

Fast
Isolated (Independent)
Repeatable
Self verifying
Timely

Fast

Tests need to be fast to be run.
Do not use production data, it contains too much clutter. Construct your data!
Discussion on Golden Copy vs Approval Testing.

Isolated

One fault should make only one test fail

Repeatable

Able to run anywhere repeatably with same result; plain, train, work, home, etc.

Self Verifying

Pass or Fail! Nothing in between or demanding human intervention (like reading logfiles)

Timely

Written first. The test is the specification.
1 code change = 1 test

Given when then

What about METHOD_WHEN_THEN, for a stack the test methods could be:
Push_empty_sizeIsOne
Pop_empty_throwUnderFlow
Push_full_throwOverFlow
Pop_sizeone_empty

Principles

#1                  Don’t test private or protected methods.
#2                  Testing trumps privacy
·        Make private methods package protected
·        Or extract into own class
#3                  Testing privates implies a design error

Put tests in same package

Preferably in same directory, but deploying without tests is tricky.

Fragile tests

xUnit Patterns à The fragile test “problem”

Interface Sensivity

Do not depend directly on UI-components
Open/Closed Principle (Bertrand Meyer), a class should be open for extension but closed for modification.
The best anticipation of change is change that already happened.

Behaviour Sensitivity

Avoid complex setup and tardown scenarios
Access the tested feature as directly as possibly

Data Sensitivity

Failure because of changed test data. Control your test data!

Context Sensitivity

-         Data/time
-         Available Memory
-         Network Services
-         Hardware
Mock out context dependencies. Mock out clock!

Overspecification

Failure because of change in system test should not care about. (The scope of test is too wide).

Sensitive Equality

Failure caused by an over-constrained comparison
-         Floating point, whitespace
-         Avoid it! J

Preserving tests

FIRST!
Failures are “stop the presses” events. Keep test code clean!

FitNesse

Put fixtures in same project as code under test. Test your fixtures.

Put under source control!

Check in all txt and xml-files under FitNesseRoot.

Same tests, different setup

Use symbolic links
Product
  Test One
  Test two
Dev
  Setup
  Symlink à Product
Prod
  Setup
  Symlink à Product

Special pages

PageHeader   Siblings gets page header
Setup            
TearDown

Variables

!define NAME {BOB}
The variable NAME is ${NAME}
Can define java definition and environment variables as well.

Old style (ColumnFixture)

  • Should be several small tests
  • States what to do, not what to test

New style

Misc

Inga kommentarer: