Over to you on integration and unit tests
What kind of tests do you actually write? Have you ever asked yourself that? I’ve asked myself a few times. Maybe you’ve asked too, but in a different way. Why am I not writing tests at all? In my experience there are a few reasons developers skip tests.
- They’ve never heard of automated tests or seen one.
- They consider automated tests a waste of time because their code has no bugs.
- They understand the benefits of automated tests but don’t know where to start.
- Their conditions change so quickly that the effort to write a test
outweighs its useful life.
You might think of another reason, but at least the first three have something in common. I think the common denominator is a lack of education in this area. You might tap your forehead at that and swear there’s already plenty written about automated tests. You’re right. There’s one area people have written about at length, and that’s unit tests.
Integration and unit tests
Let’s suppose we understand the benefits of unit tests and that we have plenty of material showing how to write them using very simple examples. Better yet, the examples are contrived and cost practically nothing to test. That’s the problem.
How many such unit tests have you actually written? How many unit tests do you have compared with all your tests? If you’re wondering where I’m going, here’s a hint. A unit test tests an object in isolation. How many objects in your projects work independently of the rest of the system and can be tested in isolation? That’s a feature, by the way. Think again. What percentage of all your tests are unit tests? In my case it’s at most 10%.
Ladies and gentlemen, 90% of the tests I’ve written are of the non-unit variety. Those remaining tests are integration tests. I accept that integration tests, where you test how several objects or components work together, are harder to write than unit tests. I don’t accept the blanket claim that tests can’t be written. It’s only under certain conditions that you can’t write them.
I can think of a few particular areas where tests probably wouldn’t fit. The real problem is that developers try to fit unit tests to everything else, which can get awkward or even impossible. Let’s write tests, learn to write them and spread the word. Above all, let’s remember that the world of testing doesn’t begin and end with unit tests…
Over to you
- (14 January 2005) App server cache
- (26 January 2005) Documentation system
Related articles
Related CZ Podcast episodes
- #261 · Leadership
On leading people and teams. · Czech audio