I saw what seems to me to be two approaches to BDD. The difference depends on the location of the "when":
In approach 1, when it is part of the specification:
AnEmptyStack.isNoLongerEmptyAfterPush
In pure "given when" terminology, this is:
"Given an empty stack, when it is pressed, it is no longer empty."
Thus, when is part of the specification method:
isNoLongerEmptyAfterPush(){ stack.push(anObject); Assert.notEmpty(stack); }
In approach 2, the value is determined at the class level. That is, when it is usually called in setup.
class WhenAnEmptyStackIsPushed(){ setup(){ stack.push(); } public void thenItIsNotEmpty(){ assert(stack.notEmpty()) } }
Is there a preferred method? As for pure behavior testing, the second option seems preferable to me, since the focus of the test device depends on its behavior.
However, for the convenience of testing, I am inclined to the first method. Most of the pain I find in testing is tuning. That is, I have to get the SUT in a certain state. Once in this state there is usually only one line of code to actually cause some kind of behavior on it. Thus, having multiple actions for each class (that is, for each setting context) uses a one-time class setting.
So I'm looking for thoughts. Is one approach preferable to another?