Skip to main content

Timeline for What is the point of unit tests?

Current License: CC BY-SA 4.0

6 events
when toggle format what by license comment
Jun 16, 2023 at 3:17 comment added rooby That example is a legitimate use case for comments in code. Documenting why something unusual is being done due to external factors. Having unit tests on it is good, but I don't think is sufficient documentation in itself for that kind of thing. The unit test describes the behaviour but doesn't explain why it's like that.
Jun 14, 2023 at 19:25 comment added coppereyecat I worked on legacy applications in an environment where unit tests were not possible (it was an EMR's custom scripting language for which no unit test framework existed - or any way to run scripts or make assertions on the output other than displaying it on a user facing page). It was a nightmare of trying to ensure consistent results and bug fixes.
Jun 14, 2023 at 7:15 comment added Miral This also requires the test to be written clearly -- good tests themselves form part of the code documentation (and the best kind of documentation, since you can execute it to see if it's still true). If your "empty list returns ||" test is buried in a number of similar examples without comment then the future maintainer might think that this was just an example of previous behaviour and not an external requirement. If it's in its own clearly labelled test case, or at least is commented with why that particular output is expected, it's less likely to be misinterpreted later.
Jun 13, 2023 at 19:39 comment added Ben Cottrell @Edwardo The problem is that code only represents flow and structure of a program; but humans working in code generally need a lot more than that to be able to properly reason over it - ideally they need to know everything its original developer knew, which is usually impossible from code alone, so developers in unfamiliar code take guesses based on whatever seems most likely. Good tests can eliminate a lot of guesswork by enshrining real use-cases as a source of truth about its behaviour, giving developers confidence that their future changes aren't based on faulty guesswork.
Jun 13, 2023 at 14:40 comment added Edwardo Thank you! That is a real-life example with which I can identify. I don't think I'm going to be a convert any day soon (I'm 66 and looking at retirement rather than career progression) but I think that the next time I work on a new feature I might try TDD.
Jun 13, 2023 at 14:10 history answered Deacon CC BY-SA 4.0