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

SUMMARY

Unit tests should be designed to isolate and verify small parts of code. If your test strays into calls across multiple methods, you should think about your test and class design. Integration tests are important, but they serve a different purpose than unit tests. Don't confuse the purpose of unit tests with these other types of tests. Keep your unit tests small and simple and reflective of the business needs. Only write unit tests against your class's public interface, and use interfaces liberally.

NUnit and Moq are crucial tools for effectively practicing TDD. NUnit is an easy-to-use and widely popular unit testing framework for .NET. It provides facilities to write unit tests that can be executed by a test running, quickly giving you results of your test run. Moq lets you create mocks and stubs of external resources and intra-application dependencies so that you know you're focusing on only the specific code under test. Moq lets you create objects that stand in for these resources and provide some limited functionality for the code under test to verify its functionality.

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