Live data from Hacker News

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

blog.janestreet.com

11–20 of 47 posts

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

#11

> You start writing assert fibonacci(15) == ... and already you’re forced to think. What does fibonacci(15) equal? If you already know, terrific—but what are you meant to do if you don’t? Um …duh? Get out a calculator. Consult a reference, etc. Otherwise compute the result, and ensure you've done that correctly , ideally as independent of the code under test as possible. A lot of even mathematical stuff has "test vec…

[dead]

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

#12
Recently, I have given up on writing unit tests, instead prompting an LLM to write them for me. I just sit back and keep prompting it until it gets it right. Sometimes it goes a little haywire in our Monorepo, but I don't have to accept its changes.

It feels ... strangely empowering.

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

#13

I really like this style of testing -- code that can be tested this way is also the most fun kind of code to work with and the most likely to behave predictably. I love determinism and plain old data.

Could look at high-level constraint modelling languages:

https://www.minizinc.org/

It often bypasses the need to get bogged down in probabilistic markdown syntax =3

https://www.youtube.com/watch?v=X6WHBO_Qc-Q

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

#14

Amazing to see Jane Street uses Emacs. And property-based testing too. > you don’t just get a build failure telling you that you want 610 instead of a blank string So I had to scratch my head a bit because I was thinking: "Wait, the whole point is that you don't know whether what you're testing is correct or not, so how can you rely on that as input to your tests!?" . But even though I didn't understand everything th…

> And it happens to be a case where a lot of people see the benefits of test: before refactoring.

it's also very nice if you have a test-last working style, that is, develop the code first using some sort of ad hoc testing method, then when you're convinced it's working you add tests both as a final check that the output is what you expect across a lot of different corner cases, and to prevent regressions as you continue development.

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

#15
In my experience the lack of joy or difficulty with tests is almost always that the test environment is usually different enough from the real environment that you end up needing to kind of stretch your code to fit into the test env instead of actually testing what you are interested in.

This doesn't apply to very simple functions but tests on simple functions are the least interesting/ valuable.

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

#16

> You start writing assert fibonacci(15) == ... and already you’re forced to think. What does fibonacci(15) equal? If you already know, terrific—but what are you meant to do if you don’t? Um …duh? Get out a calculator. Consult a reference, etc. Otherwise compute the result, and ensure you've done that correctly , ideally as independent of the code under test as possible. A lot of even mathematical stuff has "test vec…

I think “test the function does what it does” is not necessarily the intent here, it’s being able to write tests that fill themselves in and assuming you’ll double check afterwards.

That said, I don’t see how it’s much different to TDD (write the test to fail, write the code to pass the test) aside from automating adding the expected test output.

So I guess it’s TDD that centres the code, not the test…

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

#17

> You start writing assert fibonacci(15) == ... and already you’re forced to think. What does fibonacci(15) equal? If you already know, terrific—but what are you meant to do if you don’t? Um …duh? Get out a calculator. Consult a reference, etc. Otherwise compute the result, and ensure you've done that correctly , ideally as independent of the code under test as possible. A lot of even mathematical stuff has "test vec…

It is called snapshot testing, very valid technique. Maybe not best suited to a mathematical function like they have here, but I have found it useful for stuff like compilers asserting on the AST, where it would be a pain to write out and assert on the output and may also change shape.

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.

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

#18

Recently, I have given up on writing unit tests, instead prompting an LLM to write them for me. I just sit back and keep prompting it until it gets it right. Sometimes it goes a little haywire in our Monorepo, but I don't have to accept its changes. It feels ... strangely empowering.

When I build unit tests around the right routines, I feel like all is right with the world. But some employers consider this gilding the lily.

But with LLMs in hand, I can generate entire suites of tests where they're most useful before management has the time to complain. All the little nice-to-have-but-hard-to-google environment tweaks are seconds away for the asking. It's finally cost effective to do things right.

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

#19

Recently, I have given up on writing unit tests, instead prompting an LLM to write them for me. I just sit back and keep prompting it until it gets it right. Sometimes it goes a little haywire in our Monorepo, but I don't have to accept its changes. It feels ... strangely empowering.

[deleted]

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

#20

> You start writing assert fibonacci(15) == ... and already you’re forced to think. What does fibonacci(15) equal? If you already know, terrific—but what are you meant to do if you don’t? Um …duh? Get out a calculator. Consult a reference, etc. Otherwise compute the result, and ensure you've done that correctly , ideally as independent of the code under test as possible. A lot of even mathematical stuff has "test vec…

> Um …duh? Get out a calculator. Consult a reference, etc. Otherwise compute the result

Article:

> This is a perfectly lovely test. But think: everything in those describe blocks had to be written by hand. The programmer first had to decide what properties they cared about... then also had to say explicitly what state they expected each field to be in. Then they had to type it all out.

The article is about not getting out the calculator.

Post reply on HN