I had the privilege to speak at the SEVDNUG yesterday about Testing. When we typically think of “Testing”, we usually use the term “Unit Testing”, yet we usually mean “Integration Testing” or “Functional Testing”. This was definitely not a demo on how to use NUnit, but rather a specific look at the reasons for testing, the best practices for writing tests, and a look at popular and obscure tools to facilitate the task.
During the presentation, we looked at many tools: NUnit, TestDriven.NET, Resharper’s test runner, TypeMock, Selenium, Ivonna, NUnit’s RowTest TestCase (I still think ‘RowTest’ is more descriptive than ‘TestCase’, and I’m still annoyed I had to update all my code when I switched to NUnit 2.5. Find/Replace is a wonderful tool though.)
One of the coolest things is that the goal of writing tests is so you spend less time debugging. Quite honestly, I’d rather write code than debug code any day. The key though is knowing what to test. Testing the .net framework or your database connection string is probably not the wisest use of your time. Testing that your business logic works the way you think it does is definitely a good way to keep bugs out of your code. To the depth that you can make the testing process seamless in your development, it can become an invaluable tool. Testing is an up-front investment that yields a long-tail benefit in improved code quality. If you can afford the investment, it’s well worth it.
One of the coolest points that came out during the discussion was using your suite of tests as documentation, new developer training, etc. If your tests are run frequently and encompass the bulk of your code, that’s where the best definitions of your business logic reside. What an awesome idea.
The slides and code are available here. If you’re going to use the TypeMock and Ivonna content, you’ll need to download trial licenses from here. All the other tools we discussed are open-source or free.
** NOTE: For some strange reason, my server wants to gzip zip files when it downloads them, leading to a double-compressed file. If you’re downloading the zip files in IE, it’ll tell you the file is corrupt. The fault is totally mine, but the file is not corrupt. If you download the file with FireFox, it will come down just fine. If you’re an IIS guru and know how to disable gzipping zipped content while enabling gzipping for non-zipped content, please let me know. **