Most active commenters
  • wubrr(16)
  • the_af(8)
  • bunderbunder(4)
  • sfn42(3)

←back to thread

Unit tests as documentation

(www.thecoder.cafe)
174 points thunderbong | 78 comments | | HN request time: 1.879s | source | bottom
1. 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 #
2. tpoacher ◴[] No.41874655[source]
Obviously this is slightly implementation dependent but if your tests are accompanied by programmatic documentation (that is output together with the test), doesn't that eliminate the need for a descriptive test name in the first place?

If anything, in this scenario, I wouldn't even bother printing the test names, and would just give them generated identifier names instead. Otherwise, isn't it a bit like expecting git hashes to be meaningful when there's a commit message right there?

replies(1): >>41878135 #
3. zoover2020 ◴[] No.41874662[source]
Have you considered a linter rule for test names? Both Checkstyle and ESLint did great work for our team
4. 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 #
5. 6r17 ◴[] No.41874814[source]
That's not the point of the article. The code should be readable no exception. The only reason we should be ysing x y z are for coordinates ; i should be left for index_what ; same goes for parameters ; they should also contain what unit they are on (not scale, but scale_float) only exception I see are typed languages ; and even then I'm occasionally asked a detail about some obscure parameter that we set up a year ago. I understand it can sound goofy, but the extra effort is made towards other people working on the project, or future self. There is no way I can remember keys or where I left the meaning of those, and there is no justification to just write it down.

Readability of the code makes a lot of it's quality. A working code that is not maintainable will be refactored. A non working cofe that is maintainable will be fixed.

replies(1): >>41881251 #
6. 8note ◴[] No.41874867[source]
It's important to this article because its claiming that the name is coupled functionally to what the code tests -- that the test will fail if the name is wrong.

I don't know if any test tools that work like that though.

replies(1): >>41875993 #
7. seadan83 ◴[] No.41875382[source]
What kinds of things would you say are best as annotation vs in the test method name? Would you mind giving a few examples?

Also, are you a fan of nesting test classes? Any opinions? Eg:

Class fibrulatatorTest {

  Class highVoltages{

      Void tooMuchWillNoOp() {}
      Void maxVoltage() {}
} }
replies(2): >>41876463 #>>41881313 #
8. yourapostasy ◴[] No.41875392[source]
> ...increasingly moving toward Donald Knuth's literate style of programming.

I've been wishing for a long time that the industry would move towards this, but it is tough to get developers to write more than performative documentation that checks an agile sprint box, much less get product owners to allocate time test the documentation (throw someone unfamiliar with the code to do something small with it armed with only its documentation, like code another few necessary tests and document them, and correct the bumps in the consumption of the documentation). Even tougher to move towards the kind of Knuth'ian TeX'ish-quality and -sophistication documentation, which I consider necessary (though perhaps not sufficient) for taming increasing software complexity.

I hoped the kind of deep technical writing at large scales supported by Adobe Framemaker would make its way into open source alternatives like Scribus, but instead we're stuck with Markdown and Mermaid, which have their place but are painful when maintaining content over a long time, sprawling audience roles, and broad scopes. Unfortunate, since LLM's could support a quite rich technical writing and editing delivery sitting on top of a Framemaker-feature'ish document processing system oriented towards supporting literal programming.

9. ronnier ◴[] No.41875790[source]
I’d rather leave a good comment instead of good test names. I mean do both, but a good comment is better imo. All I really care about is comments anymore. Just leave context, clues, and a general idea of what it’s trying to accomplish.
replies(1): >>41876142 #
10. hinkley ◴[] No.41875904[source]
It’s practically a sociology experiment at this point: half of the time when I suggest people force themselves to use a thesaurus whether they think they need it or not, I get upvoted. And half the time I get downvoted until I get hidden.

People grab the first word they think of. And subconsciously they know if they obsess about the name it’ll have an opportunity cost - dropping one or more of the implementation details they’re juggling in their short term memory.

But if “slow” is the first word you think of that’s not very good. And if you look at the synonyms and antonyms you can solidify your understanding of the purpose of the function in your head. Maybe you meant thorough, or conservative. And maybe you meant to do one but actually did another. So now you can not just chose a name but revisit the intent.

Plus you’re not polluting the namespace by recycling a jargon word that means something else in another part of the code, complicating refactoring and self discovery later on.

11. gorgoiler ◴[] No.41875926[source]
Hah, I swing the other way! If module foo had a function bar then my test is in module test_foo and the test is called test_bar.

Nine times out of ten this is the only test, which is mostly there to ensure the code gets exercised in a sensible way and returns a thing, and ideally to document and enforce the contract of the function.

What I absolutely agree with you on is that being able to describe this contract alongside the function itself is far more preferable. It’s not quite literate programming but tools like Python’s doctest offer a close approximation to interleaving discourse with machine readable implementation:

  def double(n: int) -> int:
    “””Increase by 100%

    >>> double(7)
    14
    “””
    return 2 * n
replies(1): >>41879740 #
12. the_af ◴[] No.41875993{3}[source]
That's not what the article claims at all.

It claims that, in order for tests to serve as documentation, they must follow a set of best practices, one of which is descriptive test names. It says nothing about failing tests when the name of the test doesn't match the actual test case.

Note I'm not saying whether I consider this to be good advice; I'm merely clarifying what the article states.

13. 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 #
14. lallysingh ◴[] No.41876142[source]
Four test failures in different systems, each named well, will more quickly and accurately point me to my introduced bug than comments in those systems.

Identifiers matter.

15. biggc ◴[] No.41876463{3}[source]
Table tests can enable useful test naming without a bunch of clunky named test functions. I use them most often in Go but I’m sure other languages have support

https://go.dev/wiki/TableDrivenTests

16. ◴[] No.41876835[source]
17. yen223 ◴[] No.41876871[source]
Kotlin has an interesting approach to solving this. You can name functions using backticks, and in those backticks you can put basically anything.

So it's common to see unit tests like

  @Test
  fun `this tests something very complicated`() {
    ...
  }
replies(1): >>41877009 #
18. serial_dev ◴[] No.41876888[source]
Some languages / test tools don’t enforce testNamesLikesThisThatLookStupidForTestDescriptions, and you can use proper strings, so you can just say meaningful requirements with a readable text, like “extracts task ID from legacy staging URLs”.

It looks, feels, and reads much better.

replies(2): >>41877015 #>>41881545 #
19. misja111 ◴[] No.41876977[source]
Thanks for the hint about Knuth's literate programming! I hadn't heard about it before but it immediately looks great. (For those of us who hadn't heard about it before either, here is a link: https://en.wikipedia.org/wiki/Literate_programming)

About your other point: I have experienced exactly the same. It just seems impossible to instill the belief into most developers that readable tests lead to faster solving of bugs. And by the way, it makes tests more maintainable as well, just like readable code makes the code more maintainable anywhere else.

20. misja111 ◴[] No.41877002[source]
It's funny, you are asking what test names have to do with quality, and you proceed with mentioning a really bad test name, 'toTryToFitTheTestDescriptionIntoItsName', and (correctly) stating that this has zero benefit.

Just like normal code, test methods should indicate what they are doing. This will help you colleague when he's trying to fix the failing test when you're not around. There are other ways of doing that of course which can be fine as well, such as describing the test case with some kind of meta data that the test framework supports.

But the problem that OP is talking about, is that many developers simply don't see the point of putting much effort into making tests readable. They won't give tests a readable name, they won't give it a readable description in metadata either.

replies(1): >>41881233 #
21. sfn42 ◴[] No.41877009{3}[source]
You can do that in Java as well. Can't remember if it's exactly the same syntax
replies(2): >>41879165 #>>41882303 #
22. lbreakjai ◴[] No.41877015{3}[source]
With jest (Amonsts others), you can nest the statements. I find it really useful to describe what the tests are doing:

    describe('The foo service', () => {

      describe('When called with an array of strings', () => {

        describe('And the bar API is down', () => {

          it('pushes the values to a DLQ' () => {
            // test here
          })

          it('logs the error somewhere' () => {
            // test here
          })

          it('Returns a proper error message`, () => {
            // test here
          })
        })
      })
    })

You could throw all those assertions into one test, but they’re probably cheap enough that performance won’t really take a hit. Even if there is a slight impact, I find the reduced cognitive load of not having to decipher the purpose of 'callbackSpyMock' to be a worthwhile trade-off.
replies(1): >>41877837 #
23. yesbabyyes ◴[] No.41877265[source]
As a fan of literate programming, I hope this could be a tool in the box for Node.js developers: Testy is basically doctests for Node.js, building off JSDoc's @examples stanza.

I would be honored by anyone checking it out: https://github.com/linus/testy

replies(1): >>41877481 #
24. ojkelly ◴[] No.41877415[source]
Test names are one of those things that are painful because it’s obvious to you as you write it, but there’s an extra hassle to switch gears in your head to describe what the contents of the test is doing.

It is really valuable when they are named well.

I’ve found this is where LLM can be quite useful, they’re pretty good at summarising.

Someday soon I think we’ll see a language server that checks if comments still match what they’re documenting. The same for tests being named accurately.

replies(1): >>41877822 #
25. gus_leonel ◴[] No.41877434[source]
Test names should be sentences: https://bitfieldconsulting.com/posts/test-names
replies(4): >>41880087 #>>41880687 #>>41881699 #>>41882785 #
26. macspoofing ◴[] No.41877538[source]
>Getting all your teammates to quit giving all their tests names like "testTheThing" is darn near impossible.

You can do better than "testTheThing".

Have your team (or a working group composed of your team, if your team is too big) put together a set of guidelines on naming conventions for unit test methods. Have your team agree to these conventions (assumption is that the working group would have consulted with rest of team and incorporated their feedback).

Then make that part of the code review checklist (so you aren't the one that is actually enforcing the policy). Do spot checks for the first little while, or empower some individuals to be responsible for that - if you really want to. Do a retrospective after a month or 2 months to see how everyone is doing and see how successful this initiative was.

27. pydry ◴[] No.41877822[source]
I've never seen this as a problem. If you're doing TDD and you have a scenario in mind, you describe that scenario in the name of the test.

If you're writing the test after then yeah, maybe it's hard, but that's one of the many reasons why it's probably better to write the test before and align it with the actual feature or bugfix you're intending to implement.

replies(1): >>41881022 #
28. chriswarbo ◴[] No.41877837{4}[source]
The `describe`/`it` nesting pattern is quite common (I currently use it in Jest and HSpec); but it doesn't solve the social problem. It's common to see tests like:

    describe("foo", () => {
      describe("called with true", () => {
        it("returns 1", () => {
          assert(foo(someComplicatedThing, true) === 1)
        })
      })
      describe("called with false", () => {
        it("returns 12", () => {
          assert(foo(someOtherIndecipherableThing, false) === 12)
        })
      })
    })
It's the same problem as comments that repeat what the code says, rather than what it means, why it's being done that way, etc. It's more annoying in tests, since useless comments can just be deleted, whilst changing those tests would require discovering better names (i.e. investigating what it means, why it's being done that way, etc.). The latter is especially annoying when a new change causes such tests to fail.

Tests with such names are essentially specifying the function's behaviour as "exactly what it did when first written", which is ignoring (a) that the code may have bugs and (b) that most codebases are in flux, as new features get added, things get refactored, etc. They elevate implementation details to the level of specification, which hinders progress and improvement.

replies(2): >>41878364 #>>41881597 #
29. crabbone ◴[] No.41878062[source]
Bad work practices create bad social dynamics. If someone on the team isn't pulling their weight by being lazy, I don't see a reason to like that person if I'm their team member.
30. crabbone ◴[] No.41878135[source]
The article addresses this: there's no systematic enforcement of documentation currency. It may accidentally and unbeknownst to its authors become outdated.

Anyways, as already mentioned earlier: unit tests are code and all quality criteria that apply to any other code apply to unit tests too. We expect identifiers used in code to help understand the code no matter if it's the name of a unit test or any other entity in our program.

NB. To me this argument seems as bizarre as disputing washing your hands after using the bathroom. Why would anyone think that they should get a pass on code quality standards when writing unit tests? This just doesn't make sense...

replies(1): >>41935431 #
31. yakshaving_jgt ◴[] No.41878364{5}[source]
At the end of the day, someone has to shoulder the burden of holding their colleagues to higher standards. I don’t think there’s a technical solution to this social problem.
replies(2): >>41878925 #>>41879458 #
32. nzach ◴[] No.41878426[source]
>Getting all your teammates to quit giving all their tests names like "testTheThing" is darn near impossible.

Sometimes people are pretty bad a coming up new names, but selecting a good name given some options generally isn't a big problem. So maybe we should create a kind o LLM linter for this situation ?

The prompt could be along the lines:

"Given this function: <FUNCTION>

This unit test: <UNIT TEST>

And these naming considerations: <NAMING GUIDE>

Is the current test name a good option?

What would be some better options?"

I did some quick testing and it seems work to reasonably well. It doesn't create anything mind-blowing but at least it seems to provide some consistent options.

replies(1): >>41879260 #
33. flerchin ◴[] No.41878897[source]
You know what they say:

Naming things is one of the 2 hardest problems in computer science. The other one being cache invalidation and off by one errors.

replies(1): >>41882902 #
34. chiph ◴[] No.41878925{6}[source]
This is part of the job of being a team lead or manager. You have a standard, you need to get people to follow it (or consequences..)
35. lmz ◴[] No.41879165{4}[source]
You can't put spaces in the function name, but you can set a display name for JUnit - https://junit.org/junit5/docs/5.0.3/api/org/junit/jupiter/ap...
replies(1): >>41887546 #
36. nzach ◴[] No.41879260[source]
Here is a really bad POC for golang tests, if anyone is interested: https://github.com/nzachow/lmlinter

Right now it just prints the prompt in the terminal.

37. TheSoftwareGuy ◴[] No.41879455[source]
This is one area where a BDD style framework like catch2[0] really shines, IMO. The way tests are written in this style naturally lends itself to self-documenting each branch

[0]: https://github.com/catchorg/Catch2

38. cle ◴[] No.41879458{6}[source]
It could also be a symptom of something else, like I’ve seen this happen when someone goes overboard on unit tests and they become so burdensome that other engineers just want to get it out of the way. They may not consciously realize it, but subconsciously they know that it’s BS and so they don’t mind BS names to just move on with actual productive work.

Not saying it’s always the case, but it could be. Higher standards are not always better, they have diminishing returns.

replies(1): >>41881073 #
39. hu3 ◴[] No.41879740[source]
> If module foo had a function bar then my test is in module test_foo and the test is called test_bar.

Same. This is a good 80/20 in my experience.

Testing the happy paths is already very rewarding.

40. nuancebydefault ◴[] No.41879817[source]
I used to be the weenie who always said we need to define nomenclature before things get silly names (hence very very early to prevent those to become the norm for legacy reasons) and use proper naming for everything, such that code would read like a novel (yes that is a stretch).

But indeed it tended to lead to frustrating social dynamics in stead of happy romcom scripts.

So I gave up on most of it.

That said, my opinion about test code is, it exists to find bugs or steer away from regression. API descriptions, together with a design with some graphs, should be formal and clear enough to understand code usage. I don't want to figure out the usage of fwrite() by going through its elaborate test suite.

41. nuancebydefault ◴[] No.41880087[source]
In fact that is not very hard to do and provides a great advantage!
42. wryoak ◴[] No.41880385[source]
I encourage my teams to include the project tracker ticket name of the requirement or bug fix in the name. Eg, “XYZ12” -> fn { … } // test for value always being positive

Of course some test libraries make this approach difficult.

43. wnmurphy ◴[] No.41880687[source]
100%. Test names should include the word "should" and "when". Then you get a description of the expected behavior.
44. mewpmewp2 ◴[] No.41881022{3}[source]
Maybe also why TDD is hard for me because I only truly start to think or visualize when I'm writing the actual code. I don't know if it's ADHD or what it is, but writing requirements, tests before hand, is just not my forte. It's like I only get dopamine from when I build something and everything else feels frustrating.
replies(1): >>41882618 #
45. mewpmewp2 ◴[] No.41881073{7}[source]
It's all a spectrum of trade-offs with different people having different opinions.

There could be some sort of formula to explain this better to determine how much effort to spend on tests vs features and product quality and importance of quality compared to that.

46. wubrr ◴[] No.41881233{3}[source]
> It's funny, you are asking what test names have to do with quality, and you proceed with mentioning a really bad test name, 'toTryToFitTheTestDescriptionIntoItsName', and (correctly) stating that this has zero benefit.

Not at all. Those kinds of names are like a de-facto standard for the people that try to push this kind of practice. Obviously the example I used is not related to any real test.

> This will help you colleague when he's trying to fix the failing test when you're not around.

Really? Encoding what a test function does in it's name is your recommendation for helping someone understand what the code is doing? There are far better ways of accomplishing this, especially when it comes to tests.

> There are other ways of doing that of course which can be fine as well

'Can be fine as well'? More like 'far superior in every possible way'.

> But the problem that OP is talking about, is that many developers simply don't see the point of putting much effort into making tests readable.

Not at all, making a test readable and trying to encode what it does into it's name are completely separate things.

47. wubrr ◴[] No.41881251{3}[source]
I'm obviously replying to GP's specific comment on test names. I fail to see how your reply relates to my comment at all.
48. wubrr ◴[] No.41881313{3}[source]
Like others have already stated/provided examples of[0] - the test function names are generally irrelevant. Many testing frameworks use a single/same test function name, or a completely unnamed function/lambda, while providing any needed context/documentation as params or annotations.

Realistically, many unit tests are far more complicated (in terms of business logic) than functions where names actually matter, like 'remove()', 'sort()', 'createCustomer()', etc. I've worked in several places where people aggressively pushed the 'encode test description in test name' BS, which invariably always leads to names like 'testThatCreatingACustomerFromSanctionedCountryFailsWithErrorX'. It's completely absurd.

> Also, are you a fan of nesting test classes? Any opinions?

It really depends on the framework you're using, but in general nesting of tests is a good thing, and helps with organizing your tests.

[0] https://news.ycombinator.com/item?id=41871629#41877015

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

Very insightful, thanks.

replies(1): >>41882843 #
50. wubrr ◴[] No.41881545{3}[source]
Yup, I've not actually seen any tool that enforces these kinds of test names. But yeah, trying to encode test description/documentation into it's name is like one of the worst common ways of documenting your tests.
51. wubrr ◴[] No.41881597{5}[source]
Yeah, it doesn't solve the problem of low quality code/laziness, but it's a better tool/approach for documenting your tests than encoding the description/documentation into it's name.

Encoding such information into the name makes about as much sense as encoding constraints into SQL column names.

52. wubrr ◴[] No.41881699[source]
Shallow/meh, article. Demonstrates complete lack of familiarity with many popular testing frameworks/approaches, and proposes a subpar solutions for problems that have already been solved in superior ways.

Your test description/documentation should be sentences, but there is absolutely zero reason to try to encode that into the name of your test function. Not to mention this article then suggests using another tool to decode this function name into a proper sentence for reporting... ok now you completely lost the ability to ctrl+f and jump to the function... terrible advice all around.

Why not just use a testing framework that actually supports free-form sentence descriptions/documentation for your tests?

replies(2): >>41882229 #>>41883316 #
53. bunderbunder ◴[] No.41882229{3}[source]
If my unit testing framework supports free-form sentence descriptions, I'll use it. But I won't use that feature as a wedge issue. It doesn't bother me all that much to have test functions with names like `test_transaction_fails_if_insufficient_funds_are_available()`. Other features of the test framework might have a much bigger impact on my developer experience.
replies(1): >>41883449 #
54. bunderbunder ◴[] No.41882303{4}[source]
I don't think you can do it in Java specifically. But once upon a time it was rather popular to write test fixtures for Java code in Groovy, which does let you do it.
replies(1): >>41887548 #
55. crazygringo ◴[] No.41882618{4}[source]
I used to be like that sometimes. Then I started realizing I'd get the function 90% complete and discover an edge case and have to start over in a way that could handle the edge case. Sometimes this could happen twice.

Documenting your requirements by writing the tests in advance is of course painful because it forces you to think more upfront about the edge cases in advance. But that's precisely why it saves time in the long run, because then it makes it a lot more likely you can write the function correctly from the start.

56. globnomulous ◴[] No.41882785[source]
Not just complete sentences, test names should describe in plain English, with no reference to code or variable names, exactly what's being tested and exactly the expected outcome: "when [something happens], [the result is x]"
57. the_af ◴[] No.41882843{4}[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 #
58. SAI_Peregrinus ◴[] No.41882902[source]
Or the async version

There are three hard problems in computer science:

1) Naming things

2) Cachoncurr3)e invalidation

ency

4) Off-by-one errors

replies(1): >>41883658 #
59. the_af ◴[] No.41883124{4}[source]
> Like others have already stated/provided examples of[0] - the test function names are generally irrelevant. Many testing frameworks use a single/same test function name, or a completely unnamed function/lambda, while providing any needed context/documentation as params or annotations.

I think what you're focusing on is just syntax sugar. Those examples with the 'describe'/'it' pattern are just another way to provide names to test cases, and their goal is exactly the same. If you didn't have this syntactic support, you'd write the function names representing this.

It's exactly the same thing: documenting the test case in the code (so not a separate document), with its name.

The distinction between "comment" and "function name" becomes less relevant once one realizes a function's name is just another comment.

replies(1): >>41883527 #
60. sksxihve ◴[] No.41883316{3}[source]
When a unit test fails in code I'm working on I don't read the name of the test, I jump to the line in the file for the test and read the code so I never really understood what people find advantageous for this naming convention.

I've worked at companies that required this style naming for tests and it was an unholy mess, and it only works if the unit test is small enough that the name is still a reasonable length which at that point the code should be clear enough to understand what is being tested anyway.

replies(1): >>41883469 #
61. wubrr ◴[] No.41883449{4}[source]
Pretty much every major language/framework now supports free-form test names/descriptions, including JUnit, which is referenced in the article ^ (again, highlighting the author's ignorance). Just because something doesn't bother you personally doesn't mean it's a good thing to follow, especially when its clearly inferior to other options.

> It doesn't bother me all that much to have test functions with names like `test_transaction_fails_if_insufficient_funds_are_available()

I mean, that's one example where you have one outcome based on one parameter/state. Expand this to a 2-field outcome based on 3 state conditions/parameters and now you have a 100-character long function name.

replies(1): >>41904621 #
62. wubrr ◴[] No.41883469{4}[source]
Names, descriptions for tests are useful for many purposes, I'll leave it at that.

The point I'm making (and I think you are agreeing with me) is that trying to stuff a test description into a test function name is cumbersome and pointless. There are far better ways of adding descriptions/documentation for unit tests and pretty much every major language/testing framework supports these, nowadays.

63. wubrr ◴[] No.41883527{5}[source]
> I think what you're focusing on is just syntax sugar. Those examples with the 'describe'/'it' pattern are just another way to provide names to test cases, and their goal is exactly the same.

The goal may be the same/similar, but one of the approaches is clearly superior to the other for multiple reasons (as stated by me and other many times in this comment tree). Also, I don't think you quite understand what 'syntactic sugar' means.

> If you didn't have this syntactic support, you'd write the function names representing this.

It's not any kind of 'syntactic support'. Pretty much every modern language/testing framework supports adding free-form test descriptions and names through various means.

> It's exactly the same thing: documenting the test case in the code (so not a separate document), with its name.

It's very clearly not the same at all lmao. And a test name, test description, other useful test documentation/metadata are also not the same.

> The distinction between "comment" and "function name" becomes less relevant once one realizes a function's name is just another comment.

Huge differences between a function name, a comment, and an annotation. HUGE. Read the other comments in this thread to understand why. If you actually worked in an environment where stuffing a test description into a test name is the preferred approach for a non-trivial amount of time, you'd know that once you get past a certain level of complexity your test names explode to 100+ character monsters, if only to differentiate them from the other tests, testing a different combination of states/inputs and outputs, etc.

replies(1): >>41883736 #
64. wubrr ◴[] No.41883558{5}[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 #
65. Jerrrrrrry ◴[] No.41883658{3}[source]
this is incredibly unnerving of a comment, thank you.
66. the_af ◴[] No.41883736{6}[source]
Sorry, I thought you were debating in good faith. I now see the tone of your responses to everyone here.

Good luck with that!

replies(1): >>41888710 #
67. the_af ◴[] No.41883747{6}[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 #
68. sfn42 ◴[] No.41887546{5}[source]
My bad, it seems I was misremembering
69. sfn42 ◴[] No.41887548{5}[source]
My bad, it seems I was misremembering
70. wubrr ◴[] No.41888710{7}[source]
Good faith debating is when you actually try to honestly consider and understand the other side's point. Not when you make dismissive blanket (and factually incorrect) statements while refusing to rationally engage with the counter-arguments.

Tone is generally completely independent of good faith.

Go heal that ego and try again.

replies(2): >>41889559 #>>41890705 #
71. wubrr ◴[] No.41888757{7}[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 #
72. the_af ◴[] No.41889559{8}[source]
Dismissive?
73. the_af ◴[] No.41889563{8}[source]
Snarky?

I was actually surprised you reacted with sarcasm.

Why are you trying to pick a fight?

74. seadan83 ◴[] No.41890705{8}[source]
Hate jumping in, though both of you...

The uninviting tone discourages further discussion. I really appreciated where this convo was going until..

> Read the other comments in this thread to understand why.

This could be restated in a non aggressive way. Eg: 'Other comments go into more details why'

> If you actually worked in an environment

Presumptive statements like this are unhelpful. We need to remember we do not know the context and experiences of others. Usually better to root discussion from ones own experience and not to presume the others perspective.

replies(1): >>41892814 #
75. wubrr ◴[] No.41892814{9}[source]
You're right, thanks.
76. bunderbunder ◴[] No.41904621{5}[source]
You seem to be focusing on the most obtuse possible way of structuring descriptive test names for rhetorical purposes. I don't know if that's intentional or not, but either way it's not terribly convincing? If you name tests according to business domain concepts rather than tying it to individual parameters through some formulaic rubric, it's often possible to come up with test names that are both more concise and easier to understand than the specific way of naming tests that you've been consistently steering the conversation back toward throughout this thread.
replies(1): >>41973081 #
77. tpoacher ◴[] No.41935431{3}[source]
Replying slightly late as I didn't see this on time ...

But I don't get the argument. Perhaps we're talking about different things (or have different mental anchors in mind)?

Giving python unittest syntax as an example, how does having a test called

  def test_myMethod_caseWhereZeroInputsAreGiven(): ...
provide better currency / documentation guarantees than

  def test_case000135():
      """
      Tests: myMethod
      Date: 2024-10-23
      Commit base: edb78go9
      Summary: Tests case where zero inputs are given.
      Details: ...
      """
As for quality criteria, I'm not necessarily claiming the naming scheme is overwhelmingly better, but except in the very limited and unrealistic scenario where you only need to write a single test per method, unwieldy test method names can cause more confusion than clarity, so I don't think index-based naming schemes complemented by documentation headers are 'worse' either. I don't think the standard good variable naming rules apply much here, because in general variable names largely rely on context to be meaningful, and should only be as minimally descriptive as required to understand their role in that context, whereas a test needs to be sufficiently descriptive to describe what is being tested AND provide the necessary context.

I don't think the bathroom analogy is good here either. I'm not arguing for sloppiness or bad code hygiene. A "better" analogy would be someone complaining about people not using the provided towels like people have always been doing, when the initial argument is that the towels in this particular room seem dirty and there's a perfectly fine airdryer "right there". Hence the answer "why does anyone think they get a pass washing their hands on a towel" just sounds bizzare to me, when the topic is appropriateness of sanitation method, not cleanliness itself.

(note: not being argumentative, I hope my tone does not come across as such; if you do bump onto this again and think I'm misinterpreting or missing some finer point entirely, I'd be interested to hear it)

78. wubrr ◴[] No.41973081{6}[source]
> You seem to be focusing on the most obtuse possible way of structuring descriptive test names for rhetorical purposes.

No, I'm focusing on the most realistic and common ways this kind of pattern actually exists (based on my experience).

> If you name tests according to business domain concepts rather than tying it to individual parameters through some formulaic rubric,

While you say I'm focusing on 'the most obtuse possible way...', this kind of comment makes it seem like you haven't focused on any actual way at all. You're speaking in very ambiguous and vague terms, which actually can't be applied and enforced in practice. If you're actually trying to write a suite of unit tests around, say a function, with 3 parameters and multiple possible outcome states - you can't name your function the same for the different combinations of inputs/outputs, and you can't just handwave a 'business domain concepts' name into existence to cover each case - that just turns into an exercise of finding synonyms, abbreviations, and vague generalizations - it doesn't solve the fact that you still need all of the same test cases and they all still need to have unique function names.

You haven't actually thought through what you're proposing here.