How Formal Should Unit Tests Be?
Forum » Code Guidelines / NUnit Testing » How Formal Should Unit Tests Be?
Started by: alexexmachinaalexexmachina
On: 1173120445|%e %b %Y, %H:%M %Z|agohover
Number of posts: 2
rss icon RSS: New posts
Summary:
A thread trying to generate a little discussion about how formalized NUnit testing should be. Is a sloppy test that proves the code acceptable, or should more time be spent creating very clean, detailed tests?
How Formal Should Unit Tests Be?
alexexmachinaalexexmachina 1173120445|%e %b %Y, %H:%M %Z|agohover

I thought I'd kick off a thread on a topic that (hopefully) there are a lot of good thoughts and opinions on: unit test design. Early on, testing certain areas of the framework will require somewhat elaborate objects to test all the functionality against. So just how much attention needs to be given to these objects? While they're not going into production, we'll still rely on them for regression testing and I'm sure many developers will check the NUnit tests to get an idea for how to use certain bits of functioanlity (especially if the documentation for the class isn't completed). So it can't get too sloppy, right? But what about general design of the objects? Is it ok to take shortcuts since, again, they're not really production business objects and they're only purpose is to give us a test bed. I actually haven't made up my mind either way, but it's sure tempting to take the easy way out as I try to juggle everything AND finish up the first round of NUnit tests for the first little bit of the Reflector class.
What do you think?

unfold How Formal Should Unit Tests Be? by alexexmachinaalexexmachina, 1173120445|%e %b %Y, %H:%M %Z|agohover
Re: How Formal Should Unit Tests Be?
Bob GrommesBob Grommes 1173127888|%e %b %Y, %H:%M %Z|agohover

I have heard that if you have about as much code in unit tests as in the code being tested, you've got it about right. Personally I'm not so sure about that as a blanket statement. In the real world I've used formal unit testing almost exclusively in library / framework types of routines, and I can see testing code rivaling the volume of tested code in that scenario. I don't find unit testing *nearly* so useful in UI code and the like, though.

I'd say that if your tests work correctly, have good coverage and run reliably such that you're not spending a lot of time debugging your tests, then you've probably hit some kind of sweet spot. IMO, test code is allowed to be kind of ugly so long as it's not obtuse or difficult to work with.

unfold Re: How Formal Should Unit Tests Be? by Bob GrommesBob Grommes, 1173127888|%e %b %Y, %H:%M %Z|agohover
New post
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.