DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. New Tools in My TDD Arsenal

New Tools in My TDD Arsenal

Alexander Beletsky user avatar by
Alexander Beletsky
·
Feb. 03, 12 · Interview
Like (0)
Save
Tweet
Share
8.06K Views

Join the DZone community and get the full member experience.

Join For Free

Recently 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.


ncrunch

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

unit test

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Spring Boot vs Eclipse MicroProfile: Resident Set Size (RSS) and Time to First Request (TFR) Comparative
  • Reliability Is Slowing You Down
  • Multi-Cloud Integration
  • gRPC on the Client Side

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: