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

IMPLEMENTING THE FUNCTIONALITY

Even though it took a while to get there, it is important to see that the test fails. If the test had passed, this could have meant several things. A passing test might indicate that the code does not correctly exercise the requirement or feature that you are currently developing. A failing test is important because it helps confirm that the test correctly references functionality that does not yet exist in the application. A passing test could also show that the requirement you're working on is a duplicate of some sort, or that this particular feature of the current user story was already satisfied by a previous requirement, feature, or user story. In any of these cases, it's important to investigate any test that passes without any application code being written.

Writing the Simplest Thing That Could Possibly Work

Because the test failed, your goal now is to write just enough code to make the test pass. In some cases this is as easy and trivial as writing or changing a single line of code. This is fine. It's important to meet only the current business requirement and not try to guess what will be needed in the future. It's also important to keep your code as simple as possible. Simple code is less likely to have defects and is easier to maintain in the future.

In this example, the implementation of the feature will end up being a little more involved than just a single line of code. It is still important, even in situations where you know you need ...

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