Live data from Hacker News

Semantic unit testing: test code without executing it

alexmolas.com

11–20 of 73 posts

Re: Semantic unit testing: test code without executing it

#11
post #7

Did the author do any analysis of the effectiveness of their tool on something beyond multiplication? Did they look to see if it caught any bugs in any codebases? What's the false positive rate? False negative? As is it's neat that they wrote some code to generate some prompts for an LLM but there's no idea if it actually works.

> Did the author do any analysis of the effectiveness of their tool on something beyond multiplication? Did they look to see if it caught any bugs in any codebases? What's the false positive rate? False negative?

I would also add the concern on whether the tests are actually deterministic.

The premise is also dubious, as docstring comments typically hold only very high-level descriptions of the implementation and often aren't even maintained. Writing a specification of what a function is expected to do is what writing tests is all about, and with LLMs these are a terse prompt away.

Re: Semantic unit testing: test code without executing it

#14
I don't think this is particularly terrible.

Broadly speaking, linters are good, and if you have a way of linting implementation errors it's probably helpful.

I would say it's probably more helpful while you're coding than at test/CI time because it will be, indubitably, flakey.

However, for a local developer workflow I can see a reasonable value in being able to go:

Take every function in my code and scan it to figure out if you think it's implemented correctly, and let me know if you spot anything that looks weird / wrong / broken. Ideally only functions that I've touched in my branch.

So... you know. Cool idea. I think it's overselling how useful it is, but hey, smash your AI into every possible thing and eventually you'll find a few modestly interesting uses for it.

This is probably a modestly interesting use case.

> suite allows you to run the tests asynchronously, and since the main bottleneck is IO (all the computations happen in a GPU in the cloud) it means that you can run your tests very fast. This is a huge advantage in comparison to standard tests, which need to be run sequentially.

uh... that said, saying that it's fast to run your functions through an LLM compared to, you know, just running tests, is a little bit strange.

I'm certain your laptop will melt if you run 500 functions in parallel through ollama gemma-3.

Running it over a network is, obviously, similarly insane.

This would also be enormously and time consuming and expensive to use with a hosted LLM api.

The 'happy path' is probably having a plugin in your IDE that scans the files you touch and then runs this in the background when you make a commit somehow using a local LLM of sufficient complexity it can be useful (gemma3 would probably work).

Kind of like having your tests in 'watch mode'; you don't expect instant feedback, but some-time-after you've done something you get a popup saying 'oh hey, are you sure you meant to return a string here..?'

Maybe it would just be annoying. You'd have to build it out properly and see. /shrug

I think it's not implausible though, that you could see something vaguely like this that was generally useful.

Probably what you see in this specific implementation is only the precursory contemplations of something actually useful though. Not really useful on its own, in its current form, imo.

Re: Semantic unit testing: test code without executing it

#15
I'm skeptical. Most of us maintaining medium sized codebases or larger are constantly fighting nondeterminism in the form of flaky tests. I can't imagine choosing a design that starts with nondeterminism baked in.

And if you're really dead-set on paying nondeterminism to get more coverage, property-based testing has existed for a long time and has a comparatively solid track record.

Re: Semantic unit testing: test code without executing it

#16

I'm skeptical. Most of us maintaining medium sized codebases or larger are constantly fighting nondeterminism in the form of flaky tests. I can't imagine choosing a design that starts with nondeterminism baked in. And if you're really dead-set on paying nondeterminism to get more coverage, property-based testing has existed for a long time and has a comparatively solid track record.

Couldn't put it better myself.

I have the toughest time trying to communicate why f(x) should equal f(x) in the general case.

Re: Semantic unit testing: test code without executing it

#17

If you’re stuck with dynamically typed languages, then tests like this can make a lot of sense. On statically typed languages this happens for free at compile time. I’ve often heard proponents of dynamically typed languages say how all the typing and boiler plate required by statically typed languages feels like such a waste of time, and on a small enough system maybe they are right. But on any significant sized code…

> But on any significant sized code bases, they pay dividends over and over by saving you from having to make tests like this. I firmly believe that the group of people who laud dynamically typed languages as efficient time-savers, that help shed drudge work involving typing, is tightly correlated with the group of people who fail to establish any form of quality assurance or testing, often using the same arguments t…

[dead]

Re: Semantic unit testing: test code without executing it

#18
post #2

Much better solution: don't write useless docstrings.

> Much better solution: don't write useless docstrings. Actually writing the tests is far more effective, and doesn't require fancy frameworks tightly coupled with external services.

Importantly there's all sorts of tests beyond trivial single-value unit tests. Property testing (via hypothesis, in python) for instance.

Re: Semantic unit testing: test code without executing it

#19
> But here’s the catch: you’re missing some edge cases. What about negative inputs?

The docstring literally says it only works with positive integers, and the LLM is supposed to follow the docstring (per previous assertions).

> The problem is that traditional tests can only cover a narrow slice of your function’s behavior.

Property tests? Fuzzers? Symbolic execution?

> Just because a high percentage of tests pass doesn’t mean your code is bug-free.

Neither does this thing. If you want your code to be bug-free what you're looking for is a proof assistant not vibe-reviewing.

Also

> One of the reasons to use suite is its seamless integration with pytest.

Exposing a predicate is not "seamless integration with pytest", it's just exposing a predicate.

Re: Semantic unit testing: test code without executing it

#20

I'm skeptical. Most of us maintaining medium sized codebases or larger are constantly fighting nondeterminism in the form of flaky tests. I can't imagine choosing a design that starts with nondeterminism baked in. And if you're really dead-set on paying nondeterminism to get more coverage, property-based testing has existed for a long time and has a comparatively solid track record.

Hm... I think you have a good point.

Maybe the non-determinism can be reduced by caching: Just reevaluate the spec if the code actually changes?

I think there are also other problems (inlining a verbal description makes the codebase verbose, writing a precise, non-ambiguous verbal description might be more work than writing unit tests)

Post reply on HN