I wonder if this has the same downsides as golden and screenshot type tests, where you end up over-asserting resulting in tests that break for unrelated changes? Obviously that’s a risk for hand written tests too but it’s easier (today… who knows what copilot like systems will offer soon!) for a human to reason about what’s relevant.
“Expect tests” make test-writing feel like a REPL session
61–70 of 93 posts
Re: “Expect tests” make test-writing feel like a REPL session
#62Snapshot testing is great, and I wish more test frameworks included first-class support for them. This means that they can auto update with a flag, and can be stored either in the source inline or in an external file (both modes have different use cases). Note that doc tests can also be a form of this, e.g. in Python's. "Expect tests" seems like a bad name, since that covers all tests.
> update with a flag Yes this is right level of automation, not whatever this article is going on about with the editor integration. Yuck.
Re: “Expect tests” make test-writing feel like a REPL session
#63Re: “Expect tests” make test-writing feel like a REPL session
#64Earlier quoted context omitted.
Yeah, weird to see all these variations - Aha, an expect test! - Oh, you mean a snapshot test! - This here is akin to UI testing framework X where the test framework can compare an expected screenshot of the UI to a screenshot of the actual UI! The last one basically requires automation if you want anyone to make use of it. The regression testing automation described in the OP is a nice-to-have, not a so-good-that-it…
… And apparently also “change detector test” https://news.ycombinator.com/item?id=34379175
"Regression test" means something else, at least at the companies I've worked at: It means a test that was written after a defect was found in production, to ensure that the same defect doesn't happen again (that the fix doesn't "regress"). It can be a manual test or an automated test. https://en.wikipedia.org/wiki/Regression_testing
Re: “Expect tests” make test-writing feel like a REPL session
#65A good set of fixture/helper functions should let you write really short and expressive tests (or tabular parametrized tests, if you prefer) which seems to me to resolve most of the pain points the author is complaining about.
One big advantage I do see with this approach is it seems to be a very compact rendering of a table of outputs; in Python+pytest+PyCharm if I run a 10-example parametrized test, I have to click through to see each failure individually. Perhaps there is a UX learning here that just rendering the raw errors into the code beside the test matrix could help visualize results faster.
As an aside, I have recently been enjoying the “write an ascii representation as your test assert” mode of testing, it can give a different way of intuiting what is going on.
Re: “Expect tests” make test-writing feel like a REPL session
#66> But think: everything in those describe blocks had to be written by hand. It also had to be thought about by the developer. Someone had to say "I want the code to do this under these conditions". If your tests can be autogenerated then they aren't verifying expected behaviour , they're just locking in your implementation such that it can't change later. They are saying "hey look everyone, I got my coverage metric t…
Re: “Expect tests” make test-writing feel like a REPL session
#67Of course, you can say "I won't let myself do that", but working against human nature is not a formula for success. If my back hurts, I can tell myself I'm just going to go lie down on the bed for 10 minutes but not take a nap, but then 30 minutes later I wake up feeling groggy.
Re: “Expect tests” make test-writing feel like a REPL session
#68Is there anything like this in Python or C#? I have worked with OCaml extensively in coursework, but there’s no chance I’ll be using it in prod any time soon and I’d love toying with this approach in my working languages.
Re: “Expect tests” make test-writing feel like a REPL session
#69Earlier quoted context omitted.
… And apparently also “change detector test” https://news.ycombinator.com/item?id=34379175
...and my favourite term, "characterization test": https://en.wikipedia.org/wiki/Characterization_test "Regression test" means something else, at least at the companies I've worked at: It means a test that was written after a defect was found in production, to ensure that the same defect doesn't happen again (that the fix doesn't "regress"). It can be a manual test or an automated test. https://en.wikipedia.org/wiki/…
One reason to call bug fix tests for “regression tests” (and only those kinds of tests) is that someone might regress the code base through a merge conflict (maybe they effectively undo a commit?). So that’s one argument I suppose.