Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How much of your code do you unit test? Do you try to get 100% coverage of every

ID: 642313 • Letter: H

Question

How much of your code do you unit test? Do you try to get 100% coverage of everything or do you skip some classes?

Background

We've made a lightweight ORM layer which we have written plenty of tests for. On top of that we use Code Contracts to specify what each method in every interface should accept and return.

Classes to test or not to test

We create repository classes to fetch items or collections. These classes are basically SQL queries and calls to the ORM layer. We also have entity mapping classes similar to those in fluent nhibernate.

Why I ask

The reason I'm asking is that I don't really see the point in writing unit tests for these classes. Well, there is a point if we could use a test database to see that no exceptions are thrown. Our test databases are a bit messy and are never reseted, hence it's impossible to validate any data (and that is out of my control). We could use a fake/mock ORM layer to try the repositories, but I do not see the point in it.

Explanation / Answer

I agree with Peter. It sounds like your getting the gut feeling as to something you don't think is worth testing but you know from a text book, that the more testing the better.

Firstly, 100% test coverage is impossible and not worth the effort in trying to achieve. 85% or over, and you're doing well.

As for your ORM framework, again, it's up to you. Will you allow developers to extend/change behaviour of anything generated, if so, it might be viable to wrap those up in some generated tests. If it's a closed book, then what's the point?

Generated tests to hit the proc's in the database, where they could be modified by developers/DBA's (and usually are), again, it might be nice to have a generated test for that if it's not too difficult to do.

It's always a trade off - is it worth the effort? This also usually comes up when people consider writing tests over entity classes with just get/setters on them...

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote