Resharper 4.0 Live Template for BDD/TDD with NUnit
I'm no BDD Guru, but here is the way I currently specify my Behaviors/Tests with AAA Syntax.
I'm not convinced that my way of BDD is exactly the most appropriate way (I still have a notion of implementation in there, not just behaviors). But I still think it's much better than the old TDD approach.
Here's an example of it:
public class TwitterTimeLineServiceTest
{
public class BehaveLikeTwitterTimeLineService
{
public BehaveLikeTwitterTimeLineService()
{
TwitterTimeLineServiceUnderTest = new TwitterTimeLineService();
}
protected ITimeLineService TwitterTimeLineServiceUnderTest { get; set; }
}
[TestFixture]
public class WhenConnectedToRealDeal : BehaveLikeTwitterTimeLineService
{
protected IList<ITweet> ActualNewTweets;
[SetUp]
public void Context()
{
this.ActualNewTweets = TwitterTimeLineServiceUnderTest.FindNewTweets();
}
[Test]
public void ShouldReturnSomeTweets()
{
Assert.Greater(0, this.ActualNewTweets.Count, "no public tweets found. Doesn't sound right, does it?");
}
}
}
and the Resharper 4.0 Live Template for it, I named it ‘BehaviorTest’.
If you want to use them ctrl + alt + space + ‘BehaviorTest’ or ctrl + e, ctrl l + ‘BehaviorTest’ if you're using VS key layout.
namespace $NameSpace$
{
using NUnit.Framework;
public class $ClassName$Test
{
public class BehaveLike$ClassName$
{
protected I$ClassName$ $ClassName$UnderTest { get; set; }
public BehaveLike$ClassName$()
{
$ClassName$UnderTest = new $ClassName$();
}
}
[TestFixture]
public class When$Context$ : BehaveLike$ClassName$
{
[SetUp]
public void Context()
{
}
[Test]
public void Should$Expectation$()
{
}
}
}
}