Behavior Driven Development (BDD)

I have been developing lately using Behavior Driven Development, or BDD. I am not using a "true" BDD "product" like Behave# at the moment, so I am merely attempting to tailor my tests to focus on behavior. Thus far, I have focused more on business objects, so the tests are a bit less use case type of behavior, but I like what I see thus far.
I am not using VS 2010, which allows you to use a test first approach. This is not a major issue, overall, except that I am not being a true purist at the moment. I am stubbing in the classes prior to the test, in many cases. When I do, I stub in so the tests red light. I wish 2010 was already out, so I could be a better boy, but I am not going to install 2010 on a machine where i am doing productoin work. That is fine, as you cannot install it now anyway. 🙂
 DISCLAIMER: I am new to this.
Her eis how I see it with business objects. I will read some more prior to cementing this approach. If anyone is extremely BDD savvy, please critique. I would love to learn more.
Essentially, my unit test classes are set up to indicuate the condition, or behavior, being tested. For object instantiation, it ends up like so:
    public class when_creating_a_column_from_values
    public class when_creating_a_column_from_a_column_row
I then set up the expectations. For the constructor, the test is something like:
        public void should_create_column_object()
I then have some tests, using the same default data, for the different properties of the object. As these are business objects, the behavior is just instantiation of the objects and making sure the properties fill corretly, both from constructor and when set is called. I have worked out the tests for Column, ColumnCollection and DbTable. What is cool is I can create my test lists with the same name as the class, thus when I see a test fail, it will appear in the test runner like so )wioll get a pic later):
when_creating_a_column_from_values     scale_should_be_set_to_zero
I can then discern that the scale is not zero, which will more easily lead me to the actual problem without digging too far into the test code. Thus far, it seems to be saving a bit of time, but I will defer the final analysis until I have used it for some time. I do think this way of setting up tests is clearer than the Class for Class way, ie:
public class ColumnTests
   public void ScaleTest()
I know that setting the Scale property failed somehow, but I am not sure what the expected outcome is without digging into the test results. Not a big deal, but I like the BDD method a bit better.
As I am seeing BDD, I can see ending up with numerous test classes, unlike the "traditional" way TDD is taught in Visual Studio (which is not a purist approach). For example, if a single object has multiple behaviors, you will have a class for each one. This is not a real issue, but it is something to consider.
As I go forward, I am wondering how I should set up my test projects. Do I group the etsts the way I do now, which is a test library for each class library project? Or, do I group behavior? Or perhaps, a library for a library, with behavior grouped in folders. So many questions. I am sure I will figure out what is most comfortable as time goes on.
Tomorrow, I will get into the meat of the application and the placement of the tests should ferret out a bit. I am going to leave a library for a library right now, with a few folders, as needed, to organize the test code. Thus far I am enjoying the paradigm shift. I need to read a bit more tonight before I go to bed.
Peace and Grace,

2 Responses to Behavior Driven Development (BDD)

  1. Shane says:

    Your tests seem overly technical in nature for them to be considered BDD. There is a large gap between using BDD styled tests (where I am right now) vs true BDD tests (where I am trying to get but the literature is still a bit light and the differences in opinions large).

  2. Gregory says:

    I may be too used to TDD to completely grasp the BDD paradigm right now. Perhaps I should just consider it BDD styled unit tests. And, you are correct. There are far too few resources on BDD to get a full grasp. Those I have seen seem to use a lot of test classes, which is a bit of a paradigm shift for the TDD style. I guess I need to take a step back and rethink what to call this style of setting up the unit tests.Peace and Grace,Greg

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: