Developing a Vectorworks 2011 Plug-in, TDD-style – Episode 1

After Episode 0 – Introduction, let’s try to get some real coding done in this episode.

For a TDD newbie, the first questions are always along these lines: “How do I start? What’s the first test? How do I know what to test?”

Starting with a blank slate, let’s assume we have a class SimpleCabinet – we sure need something like that. Instantiating a SimpleCabinet object with a given width & height, we should be able to derive the width & height from the object. Not very elaborate or challenging, but it’s a start. Let’s see where this leads us.

#include "CppUnitLite2.h"

TEST_N(SimpleCabinetWidthAndHeight)
{
	SimpleCabinet simpleCabinet(600, 800);
	
	CHECK_EQUAL(600, simpleCabinet.GetWidth());
	CHECK_EQUAL(800, simpleCabinet.GetHeight());
}

Obviously, the code doesn’t compile. We need an implementation:


class SimpleCabinet {

public:
	
	SimpleCabinet(WorldCoord width, WorldCoord height)
		: fWidth(width), fHeight(height) {
	}

	WorldCoord GetWidth() const {
		return fWidth;
	}
	
	WorldCoord GetHeight() const {
		return fHeight;
	}
	
private:
	
	WorldCoord fWidth;
	WorldCoord fHeight;
};

Not an awful lot to see here, but at least we are able to compile & link successfully. Uh, and it runs and the test passes. Excellent. That’s a great start for a sunny sunday morning while the baby’s asleep.

You think this is way too trivial? Where’s the beef? With a small brain like mine, I prefer to take small steps at a time. Writing a small test, just a little bit of implementation and get feedback right away. As the old Japanese proverb says: “Even a thousand-mile journey begins with the first step.”. The point is not to stop with this first step. We will get to some actual Vectorworks SDK code.

Tune in next week when you’ll hear Dr. Bob say…

Previous Episode | Next Episode