New Tools in My TDD Arsenal
Join the DZone community and get the full member experience.
Join For FreeRecently my TDD arsenal has been enhanced with 3 new cool tools,
which I'm about to share with you. More precisely -- one tool and two
frameworks. Let's go for it.
NCrunch
NCrunch is just an amazing extension for Visual Studio created by @remcomulder.
It automatically detects all your tests and re-runs those as soon as
source code changes happen. Forget about manual test re-running, it's
just a waste of time. You even do not need to press Ctrl + S, just
continue coding as you usually do.
Initially I had big doubts about such tools, but NCrunch
changed my mind. It supports major unit test frameworks NUnit, XUnit,
MSpec etc. Besides, it allows you to collect code coverage metrics
(and show them in VS editor), runs tests under debugger, supports
multi-core systems etc.
In short, NCruch is something that makes your TDD very smooth,
allowing you to focusing on important things and forgot about the routine.

NSubstitute
I stuck to Moq for quite awhile and saw no reason to switch it.. Till I saw NSubsitute. I could hardly imagine anyone considering "yet another mocking framework project" -- it looks like absolute non-sense. But those guys proved me wrong.
Well, what's so new here? First of all, it has very clean API. No more new Mock() or MockGenerator.GenerateMock(), creation of test doubles are nothing more than Substitute.For<IEntityToMock>(). This lets you mock properties, multiple return values, events etc. in very easy fashion. Check out their getting started materials for further info.
The best feature for me is that by using extension methods they got
rid of lambdas for setting up mocks. It makes test code more readable
and clean. See this small gist there I placed some Moq and NSubstitue tests together.
I would not say that Rhino or Moq is now much worse that NSubstitute.. No, I would just say NSubstitute is a little better. The same functionality, with less code, is already a strong argument for me.
[Test] public void should_send_an_email_if_users_signs_up_nsub() { // arrange var emailService = Substitute.For<IEMailService>(); var controller = new LoginController(emailService); // act controller.SignUp(new SignUpModel { Email = "a@a.com", Password = "xxx" }); // assert emailService.Received().SendEmail(Arg.Any<EmailMessage>(), "current"); }
FluentAssertions
Again, for years I followed classic NUnit's Assert.That() method. I also played a bit with SharpTestsEx, but FluentAssertions by @ddoomen is going to change that.
FluentAssertions are based on extension methods and allow you to get rid of Assert. They call and write your assertion directly to the object. Here are some example:
{ // NUnit.Assert style.. Assert.That(result, Is.EqualTo(3); // FluentAssert style.. result.Should().Be(3); }
This is a very simple example. The power of FluentAssertions arises when you need to have either multiple assertions or assertions on complex objects. Multiple assertion could be combined by And, like:
{ "somestring".Should().Contain("some").And.HaveLength(10); }
It also provides great support for working with Collections,
DateTimes, Guids, Exceptions, XML etc. The project is hosted on codeplex,
here is the documentation. Easy start, easy go.
Conclusions
Now, I'm sharpening my axe on those tools and enjoying very nice impressions so far. Special thanks to @skalinets who introduced me with those tools.
Source: http://www.beletsky.net/2012/02/new-tools-in-my-tdd-arsenal.html
Opinions expressed by DZone contributors are their own.
Comments