Writing a Test
To begin, I open up the solution and locate the unit test project. It should look like this:
Since I will be writing a json controller eventually, I will start by creating a new item in the JsonControllerTests folder, called TransactionJsonControllerTests.cs. This class will hold all of my tests for transactions. To start with, the test class is minimal, so it looks like this:
One of the basic tenants of Test Driven Design is that the test should always fail first. Write the test, make it fail, make it pass, repeat. This example is a little silly in its extreme, but it makes the point – this test will fail when it is run. The reason for doing this is to avoid the subtle bugs that creep in when tests pass because the test is not written correctly. It helps to avoid the error of false positives.
Now, when I run the test, I get:
I see that indeed, my test did fail. Ordinarily, this process would have taken less than two minutes, and I am setup on a solid path with the knowledge that my code will be thoroughly tested in a repeatable manner. My thought process has been very focused, and I’ve not wasted any time on ancillary issues that may or may not come up during the rest of the development of this feature. The key is to focus on the simplest aspect of the feature, write the test, make it fail, make it pass. Now I move on to initializing the test conditions.



