I am coming around with TDD/BDD.
I am a bit confused though, when it comes to initially writing my BDD tests and then adding more tests after the very broad tests.
For Example, lets say that I am giving requirements first:
- It should take in an array.
- It should print a list.
- It should look for this specific condition.
I then write my tests:
describe('myApp', function (){
it('should take in an array',function(){
//expect
});
it('should print a list',function(){
//expect
});
it('should look for this specific condition',function(){
//expect
});
});
Now I need to add some functionality to my app to pass these tests, so say I write a function that checks to see if the app is actually passed an array. Or do I just check the input in the app itself? Example:
myApp(anArray) {
checkArray(anArray) // returns true or false
}
So now my app has a new method.. checkArray()
. So I need to refactor my tests, but how do I modify them. Questions:
- Do I write a new
describe
block? - Can/should i put a
describe
block inside anit
block? Should that be in my
should be an array
test?describe('myApp', function (){ it('should take in an array',function(){ describe('myApp.checkArray, { it('should return true given an array', function(){ //assertORexpectORwhatever }); }); });
});
OR should add the describe block after the first describe block like I always see, but then my initial SHOULD
is no longer describing myApp
. For example:
describe('myApp', function (){
describe('myApp.checkArray, {
//Describes myApp, not the checkArray function... *my problem*
it('should take in an array',function(){
it('should return true given an array', function(){
//assertORexpectORwhatever
})
})
});
});
Am I doing something fundamentally wrong? Am i describing my problem well enough?