←back to thread

Unit tests as documentation

(www.thecoder.cafe)
174 points thunderbong | 2 comments | | HN request time: 0.436s | source
Show context
bunderbunder ◴[] No.41874483[source]
I share this ideal, but also have to gripe that "descriptive test name" is where this falls apart, every single time.

Getting all your teammates to quit giving all their tests names like "testTheThing" is darn near impossible. It's socially painful to be the one constantly nagging people about names, but it really does take constant nagging to keep the quality high. As soon as the nagging stops, someone invariably starts cutting corners on the test names, and after that everyone who isn't a pedantic weenie about these things will start to follow suit.

Which is honestly the sensible, well-adjusted decision. I'm the pedantic weenie on my team, and even I have to agree that I'd rather my team have a frustrating test suite than frustrating social dynamics.

Personally - and this absolutely echoes the article's last point - I've been increasingly moving toward Donald Knuth's literate style of programming. It helps me organize my thoughts even better than TDD does, and it's earned me far more compliments about the readability of my code than a squeaky-clean test suite ever does. So much so that I'm beginning to hold hope that if you can build enough team mass around working that way it might even develop into a stable equilibrium point as people start to see how it really does make the job more enjoyable.

replies(20): >>41874655 #>>41874662 #>>41874705 #>>41875392 #>>41875790 #>>41875904 #>>41875926 #>>41876835 #>>41876977 #>>41877265 #>>41877415 #>>41877434 #>>41877459 #>>41877538 #>>41878062 #>>41878426 #>>41878897 #>>41879455 #>>41879817 #>>41880385 #
wubrr ◴[] No.41874705[source]
> It's socially painful to be the one constantly nagging people about names, but it really does take constant nagging to keep the quality high.

What do test names have to do with quality? If you want to use it as some sort of name/key, just have a comment/annotation/parameter that succinctly defines that, along with any other metadata you want to add in readable English. Many testing frameworks support this. There's exactly zero benefit toTryToFitTheTestDescriptionIntoItsName.

replies(7): >>41874814 #>>41874867 #>>41875382 #>>41876013 #>>41876871 #>>41876888 #>>41877002 #
the_af ◴[] No.41876013[source]
> What do test names have to do with quality?

The quality of the tests.

If we go by the article, specifically their readability and quality as documentation.

It says nothing about the quality of the resulting software (though, presumably, this will also be indirectly affected).

replies(1): >>41881317 #
wubrr ◴[] No.41881317[source]
> The quality of the tests.

Very insightful, thanks.

replies(1): >>41882843 #
the_af ◴[] No.41882843[source]
Not sure if you felt I was being snarky, but I wasn't.

The article is discussing the quality of the tests, not quality in general and not the quality of the resulting software.

That was my point.

replies(1): >>41883558 #
wubrr ◴[] No.41883558[source]
Saying 'stuffing a test description into the function name improves test quality because it improves test quality' is a cyclical, useless statement.

> The article is discussing the quality of the tests, not quality in general and not the quality of the resulting software.

All of my comments in this thread are about unit tests and test quality, not general software quality.

> That was my point.

I still don't see any valid point being made.

replies(1): >>41883747 #
the_af ◴[] No.41883747[source]
Sorry, I replied to you because I thought you were asking how it affected the final product, and I clarified, in case you had missed it, that it was about the quality of the tests as documentation.

Sorry this whole thing seems to upset you so much. Chill!

replies(1): >>41888757 #
1. wubrr ◴[] No.41888757[source]
It's ok if you misunderstood my comment and the context of this comment chain.

No need to get snarky about it and project your own feelings onto others though.

replies(1): >>41889563 #
2. the_af ◴[] No.41889563[source]
Snarky?

I was actually surprised you reacted with sarcasm.

Why are you trying to pick a fight?