miercuri, 27 august 2008

Writing meaningfull tests

Recently I came across a post from Phil Haack ( http://haacked.com/archive/2008/08/24/introducing-subspec.aspx ) in wich he talked a bit about Behaviour Driven Development.
After that I reached Dan North's blog (http://dannorth.net/introducing-bdd) and I was sold.



Today I started playing ( instead of working ) with Ninject to see what it was capable of. I have to say I love the site it's really fun. The Docs are also very well thought. After playing with the example a bit and doing testing of course so that I may reach a better understanding of the framework here's what I have :






class NinjaSpec
{
IWarrior _warrior;
IKernel _kernel;
[Specification]
public void TheNinjaShouldBeGivenAShuriken()
{
"There once was a great master".Context(
()=>
{
_kernel = new StandardKernel(new BootstrapModule());
}
);
"Given that the Ninja is Ninject's best range warrior".Do(
() =>
{

_warrior = _kernel.Get<Ninja>();
}
);
"He gave to the Ninja a mighty weapon called shuriken".Assert(
() =>
{
Assert.IsType<Shuriken>(((Ninja)_warrior).Weapon);
}
);
}
}


You tell me now is that something or not. I mean even a child understands what's going on here :D.

Niciun comentariu: