Tuesday, August 9, 2011

Tools: Unit Testing

I also started using Visual Studio 2010's Unit Testing. It is very similar to NUnit in structure and execution. The nice thing is that it is fully integrated so not compiling and configuration. It is basically just a combination of right-clicks and wizards/context-menus... very intuitive from a tiny experience with NUnit.

It was also nice to make use of some of the material I learned from my research in Unit Testing for a course I took for my graduate program: create a failed test then a working test. The number of test cases does get complicated when dealing with more subjective and unbounded cases (especially when it is the computer that limits the bound). For example, finding the number of digits in a number does not have any extreme bounds. It is limited by the size of the number type or if using string then the amount of memory, not by the criteria of the problem being solved. So except for the obvious 0, 1, -1, some positive value, and some negative value... testing the upper bounds although possible in some cases just seemed a bit awkward. To make it somewhat easier to catch people from actually breaking it, I put in limitations to the values that can be entered.

One of the things I enjoy doing (not good practice) is learning code through trial-and-error in the project. Unit testing makes this even easier in that I can just fidget with different parameters to see make sure that I get the same results back without having to re-enter data each time. Once the test is set up, it is just a matter of right-clicking and run the test. You could even write the code in the unit test but that requires more work later in that I have to then reincorporate it to the main code and write tests again.

Anyways, my quick two cents on this matter.

No comments:

Post a Comment