Step 4: The Initial Calculator Implementation

We want to make stuff simple. Let's assume we just want the simplest thing that could possible work (TSTTCPW), an XP principle. If that is the case we might get away with the following implementation:

using System;

using System.Collections.Generic;

using System.Text;


namespace Go48.Core {

   public class Calculator {

      public void Enter(int value) {



      public void Add() {



      public int Top {

         get {

            return 0;





Now, hang on! You might think this is crazy! No one would ever implement a calculator like this. I agree, but that is not the point here!

So far the only specification we have is the single test we created in the previous step. At this stage we mercilessly focus on making just that test pass. If we want to make the Calculator class smarter, then we would write more tests later. We look at a test as one representation of requirements, we only implement what the test requires, and we work on one test at a time. Sounds extreme and it actually is but if done properly this approach is highly efficient.

Also, you might argue that we already know that this test will fail. Yes, I agree with you in this simple case, but again that's not the point.

Often, you will write code that is much more complex than this one. Then it will be much less obvious whether or not the code will pass the test. Actually, as you keep adding tests, and as your implementation becomes much smarter, it will be the exception that you can predict with 100% certainty whether your test will pass when it is initially executed. In fact, if it would pass, you might have implemented too much already.

For the purposes of this tutorial we will therefore keep it simple and pretend that we have just written a tremendously complex function. It's implementation happens to be empty and we want to know whether it still works.

Just compile your entire project, which now includes both the Calculator class and the CalculatorTests class. We need the compiled version of the assembly in order to run the tests in the next step of this tutorial.

Goto Step 5 "Running Your Test And Fixing A Failure"

Back to Step 3 "Writing The First Test"

Back to Start







Suggest A Feature

Report A Bug




Extreme Simplicity Logo

Agile Utilities Logo

Blue Note Ventures Logo

Sources hosted by
Get csUnit - unit testing for .NET at Fast, secure and Free Open Source software downloads

Copyright © 2002-2008 by Agile Utilities NZ Ltd. All rights reserved. Site design by Andreas Weiss. This site is protected by bot traps.