NUnit pays off
in search of the perfect form
Today I created custom attributes for use in generating a dynamic entity class editor form using reflection. That sentance was hard to read, how about this...
Create an entity class to hold data.
Inspect this class type, or an instance of it, to create an editable field for each public property
generate a form with all the fields and polulate them with the values from the instance (if you have one)
The attributes are used to indicate what type of gui field and what the descriptive label of that filed should be. Now I can pass any class to this form generator, at runtime, and have a nice interface for it. If I append some attributes, I can control that form generator to some extent without touching it. Very nice, it should be fun to grow!
discovered misplaced attribute
In placing attributes on my entity class, I found I had an xml attribute placed on a private field when I meant it for its public accessor. This may or may not be correct, but I fixed it so that it is clear what my intent was with the XmlAttribute.
I was not sure if this change would break my existing serialized class data as it resides in the database. I could go find an old data record, explicitly instantiate that data into an object and make sure there are no errors or...
run my tests
I'd estimate I have invested four hours into writing NUnit tests for this project, including learning how to write NUnit tests. Up front, this is an expecsive investment on a small project. When I changed the location of my attribute, I merely had to call my tests and look for red. The tests take 20 seconds, maximum, to run. I ran them. All green!
As the project grows, these kind of changes are harder to regression test. Knowing the repercussions of a change is like predicting the weather: there is a science to it but it is not an exact science. By having automated tests that will execute every bit of code that I've written, I can feel confident that my software has no functional errors due to my change. I still have to perform user tests but I can catch 99% of my coding errors before a user test is performed. Conversely, I will not waste time performing manual tests when NUnit results show
- there is a failed test indicating some error in logic or result
- there are no errors at all and all tests were successful
I can wait until I have reached code completeness before returning to retest the integrated application
conclusion
Green is good! I like green dots alot