Figuring out What to Test
Figuring out what to test can be hard to determine. I created this following test:
[Test()]
public void TestWriteXML()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<TestRoot><TestElement>Test Item</TestElement></TestRoot>");
//Save the document to the file path
doc.Save(this.GetPath());
Assert.IsTrue(File.Exists(this.GetPath()));
using (StreamReader reader = new StreamReader(this.GetPath()))
{
string line = reader.ReadToEnd();
Assert.AreEqual("<TestRoot><TestElement>Test Item</TestElement></TestRoot>", line);
}
doc = new XmlDocument();
try
{
doc.Load(this.GetPath());
Assert.IsTrue(doc.DocumentElement != null);
Assert.IsTrue(doc.DocumentElement.ChildNodes.Count == 1);
}
catch
{
Assert.Fail("The XML could not be validated against");
}
}
It failed because the XML was saved in a different format than I thought. But then I got thinking about it. Do I really care about the format? Do I really need to worry about what format the XML is in? Actually, the properly formatted XML would be better anyway. I would just like to see that the document element exists and the count is there... So, as you can see, it can sometimes be difficult whether to test or not to. However, it does benefit you to see how the implementation actually works.
I always struggle with what to test; should I test with the windows UI components, like the DataGridView and ListView? Unfortunately, you can't test features like the height/width of the control and GUI stuff, though that is where NUnitForms comes into play. This is a new testing framework for testing the GUI, as well as implementing a recorder that you can record your actions. Very cool.
At any rate, we got the IO down; let's implement the IO features.