views:

525

answers:

17

What is the one most common mistake you make while writing unit tests? Coupling? Lack of cohesion? Try to test too much functionality at once? Not testing enough functionality?

Post some example code if you have an example of that mistake

+6  A: 

Writing tests that are too coupled to the code they are testing. This is especially true where I am relying on semantic coupling and things that I just assume to work for the class.

smaclell
+4  A: 

Relying on some implementation detail which is not part of the tested functionality and that might change later on in the development.
Sometimes these assumptions are just too hard to factor out or too prohibitive to take into consideration and being variable.

shoosh
+4  A: 

Lack of coverage -- I rarely test all the cases I should on my first pass.

ARKBAN
+9  A: 

Testing too much in one test. My unit tests often take on more of the character of integration tests by not confining themselves to the method under test.

tvanfosson
A: 

Leaving out some small detail (e.g. a hex to dec function where the unit test didn't have any letters in it...)

Greg
A: 

Well, I sometimes miss out putting out the [Test] C# attribute, and the test doesn't even get run :)

Rohit
+1  A: 

Testing using just some random values instead of including testing with equivalence partitioning and boundary value analysis.

blizpasta
+3  A: 

Forgetting to put in the rounding error allowance in double comparison is probably my biggest and most annoying mistake.

jjnguy
+8  A: 

Testing code that is present, rather than code that should be present.

I tend to test code that is present when writing unit tests. That is, I'll write a series of tests that have exceptionally high coverage and test the majority of the code that's present, but misses out on basic error conditions not covered by the code.

Gabriel Isenberg
+12  A: 

Not writing them at all.

shoosh
A: 

Not writing them first (ie. not going the Test Driven route)

casademora
+1  A: 

Making two integration points tightly coupled by not using a mock object or framework.

casademora
A: 

Hey, you know what? http://msdn.microsoft.com/en-us/magazine/cc163665.aspx

Irwin
Nice pointer. But what is the mistake _you_ do the most while doing Unit Tests. Marketing is good, but "not real". Link up or post code. that helps us learn.
Vasco Duarte
+1  A: 

Not getting the test fixtures neat and tidy enough - so writing the tests is harder than it should be.

Jonathan Leffler
+1  A: 

Writing tests that are neither unit tests( testing only the specific method) nor acceptance tests( testing from user's perspective).

I find that tests that testing 3-4 layers of code in one test that is not grounded at concepts that biz people understand, usually lead to tests that are a burden to maintain and make people get disappointed and turned off by automated testing.

Kozyarchuk
A: 

Unit tests with only partial code coverage.

The tests succeed, so I'm feeling good. Things are working. I move on to something else. Turns out there's an untested corner case.

I'm not sure I would count this as so much of a mistake -- I am just trying to learn unit testing now, but from what I can see -- it's not just that you know that there can never be any errors -- but there is a large comfort in knowing that many would-be bugs will be caught, when you make changes.
pc1oad1etter
A: 

Tests that depend on a quirk of the OS you happen to be on, or an unintentional side effect of a previous test.