Infovark Underground

  • news
    • infoblog
    • underground
  • product
  • download
  • buy
  • support
  • about
    • ← P/Invoke Hooray();
    • 256 Character Filenames Should be Enough for Anybody →

    Swapping NUnit for xUnit?

    14 Jul 2008 by Dean in .NET, Testing, Tools / 2 Comments

    In our previous programming jobs, neither Gordon nor I had to do much testing. We tended to focus on architecture and development issues. Just prior to forming Infovark, we were acting as consultants for an ECM vendor that has since been snapped up by HP. So while we were aware of things like unit testing and test-driven development, we’d never had to do much of it ourselves.

    We knew it was important, though. We’d seen too many things go wrong in software projects that didn’t make testing a core part of their standard operating procedures. So we incorporated testing into our product development and we’ve been learning about this testing stuff as we go. (It always happens that way, doesn’t it?)

    We began with NUnit, the gold standard for unit testing on the .NET Platform, and quickly discovered some things that everyone else already knew:

    1. Good unit tests are essential for refactoring. It’s the only way you can make big OO changes with confidence that you haven’t broken anything that used to work.
    2. Good unit tests are are essential for troubleshooting. It makes it much easier to pinpoint the source of the errors when things go wrong.
    3. Good unit tests are essential for making your product fail gracefully. Every program will fail at some point. It’s how a program reacts to a failure condition that counts.
    4. You can’t write good test suites without good specifications. You’ll forget to test key assumptions and dependencies. You won’t confirm error conditions. You’ll couple your tests to your current object model, rather than to program requirements.
    5. If you’re doing it right, you’ll write far more code for testing than for the product itself. It’s much harder to verify correctness than it is to write correct code.
    6. Unit testing is different from integration testing. Integration testing is different from system testing. All three are important.

    In addition to these common nuggets of TDD wisdom, we also discovered something else: It’s dreadfully easy to shoot yourself in the foot with NUnit tests. It’s easy to write tests that aren’t atomic, for example, or tests that expect errors to occur in one line of code that pass because another line of code throws a similar error.

    To address some of these quibbles, a splinter group has launched xUnit on CodePlex. It aims to simplify testing syntax, incorporate more .NET 3.5 constructs, and prevent some of the more common NUnit anti-patterns that testing neophytes (like us) regularly develop.

    We’ve messed around with XUnit a bit, and so far we like what we see. It’s not enough yet to make us abandon NUnit though, especially with NUnit 2.5 on the horizon. Besides, the NUnit framework is integrated with a variety of other development tools we’ve found indispensable. (I.e., everything made by JetBrains.)

    But that’s just our opinion. What do you think? How do these things stack up? And what about the testing framework built in to Visual Studio Team System? We’d love to hear your experiences with these tools.

    Related posts

    1. Writing to the Future Me
    2. The Curse of the Singleton
    3. Review: Working Effectively with Legacy Code
    4. Tools: Add In Express
    • Tweet
    • Tags:
    • NUnit
    • Test Driven Development
    • Unit Testing
    • XUnit

    2 Comments

    • Brad Wilson

      A splinter group? You make us sound like a paramilitary open source organization bent on a coup.

      Wait… :)

      14 Jul 2008 04:07 pm
      Reply
      • Alex Henderson

        I just swapped across to xUnit for a project (from NUnit) and I’m loving it, especially the IUseFixture stuff, combined with AAA style syntax using the latest RhinoMocks I find myself writing a lot less cruft in my unit tests. Also the running of tests in a random order, and the encouragement to abandon state between each test works really well.

        My only current annoyance is that I became accustomed to standard output / errors being displayed when running NUnit tests via TestDriven.Net – but running xUnit tests everything is conspicuously silent (I can see some logger output if I debug the test, but that’s pretty cumbersome).

        23 Jul 2008 01:07 am
        Reply

        Leave a Comment

        Posting your comment...

        Subscribe to these comments via email

        • Categories

          • .NET (41)
          • AJAX (3)
          • Books (7)
          • HTML (9)
          • Infovark (8)
          • Programming (48)
          • REST (11)
          • SQL (3)
          • Testing (3)
          • Tools (13)
          • UI (3)
          • WCF (11)
          • Web Services (8)
          • WPF (4)
          • XML (4)
        • Archives

        • Get future articles


           

        • Blogroll

          • Ajaxian
          • Anne Van Kesteren
          • Brain.Save()
          • Coding Horror
          • Eric Sink
          • Joel Spolsky
          • John Resig
          • Mark Pilgrim
          • Raymond Chen
          • Scott Hansleman
          • Secret Geek
          • Steve Yegge
          • The Daily WTF
          • The Database Programmer
        • Meta

          • Log in
          • Entries RSS
          • Comments RSS
          • WordPress.org
      • Site map

        • News
        • Product
        • Download
        • Buy
        • Support
        • About
      • Recent Posts

        • Review: Brownfield Application Development in .NET
        • Using Modal Dialogs with a Splash Screen in WPF
        • Highlighting query terms in a WPF TextBlock
        • Getting XAML Hyperlink text to wrap
        • How to format the XAML Hyperlink NavigateUri
      • Twitter

        Copyright 2011 Infovark, Inc. All rights reserved.