I recently read about Test Driven Development, and I thought I'd give it a try. I've had some trouble finding meaningful test examples, and I was hoping someone could point me in the right direction with two simple interfaces from my current project.
// This interface is used to convert string identifiers to faster string IDs.
typedef unsigned int StringId;
StringId hashString(const std::string& str);
I should probably create two tests for this using known string IDs - perhaps one for an empty string, and one non-zero length known value?
// This interface is used to load game assets asynchronously.
class AssetLoadJob;
class AssetLoadThread : private boost::noncopyable
{
public:
void submitJob(AssetLoadJob *loadJob);
};
I'm not sure about this one. It might be an idea to use three tests - a valid job, an invalid job and a null pointer (which should trigger an assertion)?Hopefully if I can get the feel for it using simpler interfaces, I'll have a chance of writing decent tests for the more complex ones. I know it takes enough time to write _your own_ tests, so any insight here would really be appreciated :)
Many thanks.