Sunday , August 19 2018
Home / Books / Book Reviews / Book Review: Pragmatic Unit Testing in C# With NUnit by Andrew Hunt and David Thomas with Matt Hargett
Practical and to-the-point, Pragmatic Unit Testing doesn't waste your time mulling around in long-winded expose'.

Book Review: Pragmatic Unit Testing in C# With NUnit by Andrew Hunt and David Thomas with Matt Hargett

According to the authors, "You don't test a bridge by driving a single car over it on a clear, calm day. Yet many programmers approach testing that same way – one pass down the middle and they call it tested." Pragmatic Unit Testing in C# with NUnit wants to change all of that. In this book, Andrew Hunt and David Thomas with Matt Hargett want to show you how to use real unit testing to make your life easier, and your software more reliable.

Pragmatic Unit Testing is 227 pages that divided into 10 chapters and four appendixes. To work with this book you will need a copy of NUnit that is available for free download. While this book features a .NET version of NUnit, there are many other languages that support a version of NUnit as well.

Chapter 1, "Introduction," begins by describing what Unit Testing is, and why one should bother with it. The basis for unit testing is that when you write a unit of code, you should test that the unit does what it is supposed to do. That is, does the code fulfill our intent? Does it do it all of the time? And can we depend on it?

Chapter 2, "Your First Unit Test," shows how you should begin to plan your test, how to test a simple method, and how to run it with NUnit. Several methods are explained such as from the command line or with the GUI. Chapter 3, "Writing Tests in NUnit," explains how to structure a unit test by first looking at the classic "Assert," which is the fundamental building block to NUnit. Also examined is the difference between test code and production code.

Chapter 4, "What to Test: The Right BICEP," looks at how to tell if the results are right. Here you will look at what kinds of things might need testing. You will examine boundary conditions, inverse relationships, cross checking and force error conditions. Chapter 5 is called "CORRECT Boundary Conditions." Because boundary conditions are such a common source of bugs, a whole chapter is devoted to it. Topics such as Conformance, ordering, range, reference, cardinality, and time become of interest.

Chapter 6, "Using Mock Objects," is about using stand-in's when you cannot quite use a real world object to test with; something like a network error, database failure, or a failed internet request are hard to create. Here you will learn about stubs, fakes, and mock objects. Chapter 7, "Properties of Good Tests," explains that good tests are automatic, thorough, repeatable, independent, and professional. Unit tests should not waste your time. It is supposed to make your life easier, not to have production suffer.

Chapter 8, "Testing on a Project," expands the scope of testing from an individual on a project, to a team on a project. Here you will examine how to make unit testing in a group environment work, how to use it with legacy code, and how to use unit tests within the scope of code reviews. Chapter 9, "Design Issues," covers how to design for testability, refactoring, test-driven design, and how to test for invalid parameters. Chapter 10, "UI Testing," shows you how to do unit testing on WinForms, Web UIs, Programmer UIs and Command-line UIs.

The four Appendixes are "Gotchas" which covers the usual suspects such as "It works on My Machine" and "The tests take too long." Additionally, there are sections on resources, summaries, and answers to exercises that are provided in the book.

If you want to get up to speed with NUnit and up to speed fast, then Pragmatic Unit Testing in C# with NUnit is the way to go. You will be using the framework within hours of reading this book. It doesn't waste your time mulling around in long-winded expose'. Rather it gets straight to the point and explains things in familiar, pragmatic ways. You will find out how easy it is to unit test your .NET applications. This is highly recommended for learning and using NUnit to unit test your C# programs

About T. Michael Testi

Photographer, writer, software engineer, educator, and maker of fine images.

Check Also

Cover One Person No Vote

Book Review: ‘One Person, No Vote: How Voter Suppression Is Destroying Our Democracy’ by Carol Anderson

Everything you need to arm yourself and others against losing your Constitutionally protected right is in 'One Person, No Vote' by Carol Anders. Read it, read it again, then take action.