The New Customer Test


Hey! When I went to set this test up, I noticed that we don t have a customer test for the H2 capability. We haven t talked about the H2 feature, as it wasn t very interesting, but you may have noticed it in the code snippets. Basically when the user types Control-2, we change the tag containing the caret to H2, a heading tag that I use commonly. We ll have to work on that! Should I keep my head down on this task or move to writing the old test? Well, I ve got my programmer hat on now. I m going to keep my head down. Maybe Chet and I will work on the other test this afternoon if we can get together. OK, here s my first test:

 *controlS 
*output
<sect1><title></title>
</sect1>

Starting from a blank file, typing Ctrl+S will cause the file to contain the sect1 stuff shown above, with the cursor in the middle of the title tags. Of course this won t work. I ll run it to be sure. Right. Everything else works. The sect1 test fails, with no content. That s because the controlS command has no meaning to the testing framework. I think I ll push down this path a little bit. I need a new command. Here s the relevant existing code, from CustomerTest:

 private void InterpretCommands(String commands, String message) { 
StringReader reader = new StringReader(commands);
String line = reader.ReadLine();
CreateModel();
while ( line != null) {
if ( line == "*enter")
model.Enter();
if (line == "*display")
Console.WriteLine("display\r\n{0}\r\nend", model.TestText);
if (line == "*output")
CompareOutput(reader, message);
if (line == "*input")
SetInput(reader);
line = reader.ReadLine();
}
}

Clearly what I need here is to add a check for controlS and pass it on to the model. I notice that this command interpreter is getting a bit tricky and it might want to be improved. But not yet, I m on a mission. So we ll add this:

 if ( line == "*controlS") 
model.ControlS();

We could compile this to see that it doesn t work, but when typing the ControlS message send, I saw that it wasn t defined yet (and of course I knew it anyway), so let s go add it to the TextModel before we go any further. Now, I do have a failing test to drive this code, but I m feeling a bit guilty about the test being so far from the code. I know that I get the most benefit from test- driven development when the test and the code are conceptually close. I d better buckle down and add a programmer test.




Extreme Programming Adventures in C#
Javaв„ў EE 5 Tutorial, The (3rd Edition)
ISBN: 735619492
EAN: 2147483647
Year: 2006
Pages: 291

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net