▲ | vintagedave 4 days ago | |||||||||||||||||||
I've had to write some detailed prompts and examples to have AI generate the kind of unit tests I want in Python. I've seen the assertions on types alone too. I want assertions on values and more. Even more than that, AI tends to mock _everything_. Mocking is useful, but the more real code a unit test invokes, the better, because the risk is not only the code itself but its interactions, the interface. Yet AI in Python will mock so heavily it barely tests even the code itself, with tautological statements. I've prompted with heavy warnings against mocking and pointing directly at examples of thorough tests as examples. FWIW, Python does have excellent tools for injection and can write really nicely structured code. | ||||||||||||||||||||
▲ | redman25 4 days ago | parent | next [-] | |||||||||||||||||||
I wish I had 100 upvotes to give you. Weak, heavily mocked tests are my biggest pet peave. Test “quality” is important and not something a lot of devs pay attention to. I’ve found myself preferring integration tests or unit tests with a “real” database set up because the tests are much more effective. If you design them right, they don’t even need to be slower. | ||||||||||||||||||||
| ||||||||||||||||||||
▲ | bobbylarrybobby 3 days ago | parent | prev | next [-] | |||||||||||||||||||
When asked to write UI tests (playwright), I've seen Claude Code do essentially the following: const elem = document.querySelector(".foo"); // actual element that exists elem.innerHTML = '<div class="bar"></div>'; const child = elem.locator(".bar"); // child we actually want to test for expect(child).toExist() Gee thanks Claude, what a great test... | ||||||||||||||||||||
| ||||||||||||||||||||
▲ | andoando 3 days ago | parent | prev | next [-] | |||||||||||||||||||
Mocked tests also make refactoring a pain in the ass. This is why I heavily prefer integration tests | ||||||||||||||||||||
▲ | mike_hearn 4 days ago | parent | prev [-] | |||||||||||||||||||
I'm curious how you structure your Python to be well testable. I have to admit, my own use of Python has been limited to scripts and (a long time ago) a game engine, not large codebases. So unit testing for those hardly came up. It seems there's a couple of dependency injection frameworks but they're clones of what's found in Java, right down to the type names. One of them even calls injectable objects beans! (Rhazes) | ||||||||||||||||||||
|