Based on the proposed information and syntax from My Previous Post, I've created a basic Design By Contract unit testing framework. The intent of the code so far, is to provide a quick-and-dirty proof of concept. With that in mind, I give you
DBCUnit hosted on GoogleCode
You can get the source code via Subversion:
http://dbcunit.googlecode.com/svn/trunk/
Please note that the existing code only supports one assertion so far: Equals. Also, the execution engine is entirely made up of terrible code that assumes a lot of perfect-scenario input. I'm planning to flesh it out more and make the code more sustainable - actually adding Contract specifications for my execution engine, etc. Let me know what you think of the idea and the syntax. Also feel free to join the project and pitch in for syntax and implementation.
The one Contract I have specified so far, just to get rolling, is that a [PreCondition] should be executed once.
[Condition]
public class WhenPreConditionIsPresentInContractCondition
{
private int preConditionExecutionCount = 0;
[PreCondition]
public void PreCondition()
{ preConditionExecutionCount += 1;
}
[PostCondition]
public void ThePreConditionIsExecutedOnlyOnce()
{ Assert.That(preConditionExecutionCount).Equals(1);
}
}
To run the test, run build the solution and run the DBCUnit.Console pointing to the DBCUnit.Contracts.dll, like this:
C:\...\> DBCUnit.Console.exe DBCUnit.Contracts.dll
If the test succeeds, there is currently no message printed to the console window. If it fails, it will write out a message saying what value it expected and what the value was. It's all very simplistic at this point, just a proof of concept. I also set up the DBCUnit.Console project to automatically start with the "DBCUnit.Contracts.dll" as the startup parameter, so you can step into the code via debugger and see it in action.
Have fun, and don't laugh too much. This is my first attempt at hacking together a unit testing framework.