←back to thread

Unit tests as documentation

(www.thecoder.cafe)
94 points thunderbong | 2 comments | | HN request time: 0.397s | source
Show context
tln ◴[] No.41871879[source]
Extracting unit tests from your docs: great!

Somehow extracting your docs from unit tests: might be ok!

Pointing people at unit tests instead of writing docs: not even remotely ok.

Is that really what this guy is advocating??

replies(3): >>41872139 #>>41872279 #>>41875354 #
bluefirebrand ◴[] No.41872139[source]
> Pointing people at unit tests instead of writing docs: not even remotely ok.

Couldn't agree more

I'm trying to integrate with a team at work that is doing this, and I'm finding it impossible to get a full picture of what their service can do.

I've brought it up with my boss, their boss, nothing happens

And then the person writing the service is angry that everyone is asking him questions about it all the time. "Just go read the tests! You'll see what it does if you read the tests!"

Incredibly frustrating to deal with when my questions are about the business rules for the service, not the functionality of the service

replies(1): >>41873496 #
alphanumeric0 ◴[] No.41873496[source]
The code, tests and comments convey what actual business rules are implemented.

While documentation is someone's non-precise natural language expression of what (to the best of their imperfect human capacity) expected the code to implement at the time of writing.

replies(2): >>41873994 #>>41875753 #
1. bluefirebrand ◴[] No.41873994[source]
Yes, it is absolutely more valuable to know what the code "should" be doing than to know what the code is doing

Otherwise there is no way to know what is expected behavior or just a mistake built into it by accident

replies(1): >>41875761 #
2. invaderzirp ◴[] No.41875761[source]
Especially on teams where deviance has been normalized, and broken things are just expected. I've been bitten both ways before: is this an obvious mistake? Or the lynchpin holding up the house of cards? Of course, if someone had just written some text explaining it, or perhaps a decent commit message instead of just "WIP", maybe we wouldn't have to do archaeology every single time.