Friday, April 24, 2009

Spring.NET with NUnit, and a Shout Out for Resharper

Mm, okay, so I finally got around to adding unit tests to my project. I was right about ReSharper; it rocks. The license is good, too. They call it a "named license", where the person named can be running one instance at a time, anywhere. So, you can install it on several machines, and as long as you are only using one of them at a time, you are adhering to the license.

I like it.

I had to make some decisions regarding the unit testing. Spring.NET has some built-in NUnit thing, but I chose to go with the latest and greatest, so I'd know what I was getting. I don't like to look for old docs.

As usual, adding test meant re-working a bunch of the code to accommodate it. The code is better for it, of course, and I am once again reminded why you add tests from the beginning. I won't learn, though.

There were special considerations where Spring.NET is concerned. Should I use it to wire everything together for the tests, too? It would be appropriate, at least at an integration level. Did that make sense at the unit level?

I decided, after some experimentation, that no, that "manually" wiring things together in the test suites was the way to go, with some separate tests including Spring.NET to be sure that part is working okay.

The configuration flexibility that IoC brings is inappropriate for testing, I think, because the tests should always reflect what needs to be tested, in isolation. External factors, such as what is in a config file, shouldn't be part of the tests.

Many of the changes I had to make in response to this decision dealt with writing getters and setters for private variables. Spring.net may be able to set private variables, but I'm not going to jump through the hoops to do it from a test. Once I was forced to make a decision, going with "anything that can be configured should be configurable to whatever creates it" strategy, and adding some extra checks so things don't get broken seems best, at least for now.

I'm sure I'll get pissed off about it at some point.

No comments:

Post a Comment