PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Sep 25, 2018 1:02 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Sat Dec 05, 2009 9:35 am 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida
Lets say you had a SUT (system under test)

For fun lets make it a Animal class.

So the Animal class has this interface:
Syntax: [ Download ] [ Hide ]
walkForwards()
walkBackwards()
makeNoise()


Let's say this Animal gets injected (for testability) a configuration object in it's constructor, the config option provides paramaters
Syntax: [ Download ] [ Hide ]
walkSpeed
canWalkBackwards
noiseStyle
 


Let's say you will need to cover these code paths
Syntax: [ Download ] [ Hide ]
A) walkForwards WILL walk the appropriate speed
B) walkBackwards WILL walk the appropriate speed
C) walkBackwards WILL throw an exception if this animal can not Walk Backwards
D) makeNoise should use the right noise style


I might create these test classes:
Syntax: [ Download ] [ Hide ]
 
AnimalWalkTest test class will test paths A & B & C
AnimcalNoiseTest will test path D


Now what if I need another configuration option, canWalk (controls forwards & backwards with 1 setting)

So there is a new path
Syntax: [ Download ] [ Hide ]
E) walkForwards WILL throw an exception if animal is NOT a Walker


The new test classes would be
Syntax: [ Download ] [ Hide ]
AnimalWalkTest test class will test paths A & B
AnimcalCanWalkTest will test paths C & D & E
AnimcalNoiseTest will test path D


Now what if I need to make yet another setting that was orthogonal with the existing settings, how do you keep from a test class explosion, without violating single responsibility principle in the test class (each test class should only declare the test utility methods it uses).

I guess this would be more of a functional test suite, so I want to be able to test each possible path, lets say I needed to test all these paths. How do you organize the tests?
Syntax: [ Download ] [ Hide ]
 
walkSpeed = happy path
canWalkBackwards = True
noiseStyle = happy path
canWalk = True
 
walkSpeed = boundary path
canWalkBackwards = True
noiseStyle = happy path
canWalk = True
 
walkSpeed = happy path
canWalkBackwards = False
noiseStyle = happy path
canWalk = True
 
walkSpeed = happy path
canWalkBackwards = True
noiseStyle = boundary path
canWalk = True
 
walkSpeed = boundary path
canWalkBackwards = True
noiseStyle = boundary path
canWalk = True
 
walkSpeed = boundary path
canWalkBackwards = False
noiseStyle = boundary path
canWalk = True
 
 
walkSpeed = happy path
canWalkBackwards = True
noiseStyle = happy path
canWalk = False
 
walkSpeed = boundary path
canWalkBackwards = True
noiseStyle = happy path
canWalk = False
 
walkSpeed = happy path
canWalkBackwards = False
noiseStyle = happy path
canWalk = False
 
walkSpeed = happy path
canWalkBackwards = True
noiseStyle = boundary path
canWalk = False
 
walkSpeed = boundary path
canWalkBackwards = True
noiseStyle = boundary path
canWalk = False
 
walkSpeed = boundary path
canWalkBackwards = False
noiseStyle = boundary path
canWalk = False


In a real example you could say get rid of the Noise path, its decoupled from walking, but lets make it a real example and say we also need to test a ton of behavior like the animal making noises every N steps it takes, etc... ( so suddenly you are multiplying the # of paths again and again)

Would you have
Syntax: [ Download ] [ Hide ]
AnimalWalkForwardsNoiseTestClass
AnimalWalkForwardsSpeedTestClass
AnimalWalkBackwardsNoiseTestClass
AnimalWalkSpeedNoiseTestClass

etc....

How do you keep from littering your namespace?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group