Live data from Hacker News

What if writing tests was a joyful experience? (2023)

blog.janestreet.com

41–47 of 47 posts

Re: What if writing tests was a joyful experience? (2023)

#41

Earlier quoted context omitted.

TIL. That looks like a nice way to add tests to legacy code without having to re-create what TDD would have had the developers started that way.

It is indeed a good way to add regression testing to code with no tests. But it's no substitute for TDD. It can't tell you why something is the way it is, nor can it distinguish between intentional and incidental (although maybe some would argue you shouldn't, given Hyrum's law and all). But it will at least guide you as you try to figure that out and stop you breaking stuff constantly.

The problem is some stuff is a real pain to test with static assertions. Such as I was saying about compilers. It would be a real pain to maintain an expected AST in a unit test, then you'd have to go rework it all if you change the shape and or add/remove nodes etc.

You can mix the approaches, have some static assertions(as sanity checks) but make most snapshot tests. Like I said I wouldn't use snapshot testing for a fibonacci method, but there are problems out there that are a real pain to test via static assertions.

Re: What if writing tests was a joyful experience? (2023)

#43
post #21

I realize that the example is contrived, but what is the point of writing a test of a fibonacci function if your test harness is designed to just take whatever it tells you and updates the assert to verify that what it told you is indeed what it just told you. This assumes the code you wrote is already correct and giving the correct answer, so why bother writing tests? If, however you accept that you may have got it…

> This assumes the code you wrote is already correct and giving the correct answer, so why bother writing tests? It catches regressions. Which is the one thing where such semi-automated testing is most useful in my eyes. No clue though why they gave it that weird "expect" name. Basically, it's semi-automated regression testing.

Expect is a classic Unix testing utility. So naming it expect gives it a connection to that heritage.

https://en.wikipedia.org/wiki/Expect

Re: What if writing tests was a joyful experience? (2023)

#44
post #22

I was inspired by the jane street post and implemented exactly this in my Scala unit testing library uTest ( http://www.lihaoyi.com/post/GoldenLiteralTestinginuTest090.h... ). Can confirm that auto updating golden test assertions does make working with a test suite much more joyful than struggling with each assertion by hand

> make working with a test suite much more joyful than struggling with each assertion by hand

There is a time and place for golden tests, but this reads more like a case for property-based testing.

Re: What if writing tests was a joyful experience? (2023)

#46
When writing Janet, i enjoy the judge[0] style of testing because it's so interactive. I added emacs helpers, one for running existing tests and one for updating the tests. It made for a nice repl-like experience, especially nice when writing grammars[1].

[0] https://github.com/ianthehenry/judge

[1] https://github.com/minikomi/advent-of-code/blob/d73e0b622b26...

Re: What if writing tests was a joyful experience? (2023)

#47
post #43

Earlier quoted context omitted.

> This assumes the code you wrote is already correct and giving the correct answer, so why bother writing tests? It catches regressions. Which is the one thing where such semi-automated testing is most useful in my eyes. No clue though why they gave it that weird "expect" name. Basically, it's semi-automated regression testing.

Expect is a classic Unix testing utility. So naming it expect gives it a connection to that heritage. https://en.wikipedia.org/wiki/Expect

Hmm, yes, I know that one and one of the reasons why I considered the naming weird. Original Tcl expect is rather automation than testing in the slot in my mind it occupies, even if it maybe could be (badly) used as a testing tool.
Post reply on HN