What is an appropriate level of coverage for unit tests? Are there any guidelines for deciding what unit tests are useful? via /r/learnprogramming


What is an appropriate level of coverage for unit tests? Are there any guidelines for deciding what unit tests are useful?

My friend and I have been working on a project and decided to try TDD to make our codebase cleaner and more maintainable. We are using python's unittest and mock modules (but my question is about testing in general). This is also my first time writing a test suite or using testing libraries.

We're doing a lot of pair programming to begin so that we're both on the same page (especially regarding testing) and as we're working I can't help but think that there's such a thing as writing too many unit tests. We have soooo many tests for things that seem completely trivial to me! Like tests that check every single external function is called the correct number of times for all valid inputs, tests checking that the correct exception is called for every possible input, tests checking for correct evaluation when we stubb different functions to return whatever objects they could concievably return.

Is this a normal level of coverage to have in a unit test suite?

I do see how there is value to having a test suite to make absolutely sure your code does what you want it to. It is a huge time sink to write all of these tests though, so I feel like their utility should at least make effort required to write them worth it. And it makes refactoring much more painful. I now have to modify a bunch of tests everytime I make even a minor change that may not even affect the integrated functionality of our codebase (or even the functionality of just that unit).

The thing that really gets me is all of the tests where I could just look at the code and tell in under 2 seconds whether the test is going to pass or not! Is function X called once in function Y?…… Ya, it's right there in the first line…

I just don't see the value in having a lot of these tests… It feels like I'm just duplicating the logic I also have in the actual unit. All of our actual bugs have been caught by integration tests (and weren't caught by the unit tests). It seems like a lot of additional time and effort to develop something that adds a marginal ammount of utility, and makes it harder to refactor the codebase (and is more code to maintain)

Am I writing unit tests incorrectly? Or missing something about the benefit of unit tests?

Submitted July 14, 2017 at 08:08PM by BillFuckinEvans
via reddit http://ift.tt/2v1vWbZ

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s