O'Reilly logo

Professional Test-Driven Development with C#: Developing Real World Applications with TDD by Jeff McWherter, James Bender

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2

An Introduction to Unit Testing

WHAT'S IN THIS CHAPTER?

  • What a unit test is
  • How unit testing differs from other types of tests
  • How unit testing frameworks can help you write unit tests quickly and easily
  • Why mocking external resources in your test is important when practicing TDD
  • A brief overview of the NUnit unit testing framework and the Moq mocking framework, two very popular TDD tools in the .NET world

Unit testing (UT) is the cornerstone of test-driven development (TDD). When your unit tests are properly aligned with and correctly reflect your business requirements, they almost become a living design document — one that can validate the code you've written with the push of a button. Unit tests are not difficult to write, although they do require a minor change to how you usually approach writing software. They also represent a few new concepts to master, such as code isolation and the idea of having stand-in or mock objects to enable your tests to focus on only the code that is being tested. These new concepts are integral to TDD. The ability to write isolated, repeatable, and focused tests allows you to ensure that your code is meeting the business's needs and can continue to evolve without those changes disrupting the code's fidelity to the business's needs. To help you with these concepts, tools and frameworks such as NUnit and Moq can make your development process easier, faster, and more rewarding.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required