r/PiCodingAgent • u/firebat-66 • 1d ago
Question How to get AI to make a good test suite
I'm not entirely sure where to look, so this is a bit of a long shot, general inquiry I've had on my mind. I understand that more people are doing some form of verification to ensure that their agent produces working, bug-free code, but how do you actually go about building the tests, and what does the test building pipeline look like? I have this slight uneasy feeling that if I have the same agent/subagent working on a testing suite for a codebase, there might be ways for the agent to cheat around loopholes, or it simply may design weak tests. Designing tests by hand seems like a way to go, but it defeats the purpose of using the LLMs for automatic a complex workflow. Any ideas on this? Would love any reading material, papers, books that you have on this topic!
3
u/schnorf1988 1d ago
I send the code to three different llms for a review, let my llm combine the feedback and enhance the code based on the outcome.
So far, I have burned 4 USD in tokens by doing this twice with the UI I am using for Pi. It is written by "me" (aka I let Qwen do the job) and contains the features I like and need.
1
u/DiscountFit9224 1d ago
Ain't that your responsibility? since you don't code it anymore you guard it by listing important test cases and especially edge cases. Then you prevent brittle or padding coverage unit tests.
The problem with giving this to LLM, it would try to pass everything then skip or miss the important ones.
1
u/fell_ware_1990 1d ago
What i’f noticed is, ai is quite good at spotting issues in already written code. But it’s bad at thinking about what could be really expected and what could be a failure case.
So i started with pre-writing unit tests, small example:
> Ask ai to “make me a login screen”
Well you never specified the password should be hashed or any. Ai nowadays will mostly do so. But won’t test the whole chain.
So clean specs would mean that you first write out all of what is and is not expected of that login screen. Then in small batches, you make the AI think about the cases. Have it write tests to check for those.
Also give it a clean specs of what and what not functions do. You have unit tests for those. Also to check it does not add functionality where it should not. All pre-written.
Then in E2E testing with stuff like mutation testing.
Once in a while put it through your own, messy testing.
Save all dose ‘types’ of unit tests, cause i have about 50 written test cases only for passwords now. The one thats picking unit tests for a particular case has options. They have the tendency to mostly write tests that prove that it works. ( IMO way less important) if you do not prove that there are no failure cases and you then prove it works that’s useful.
1
u/jruz 1d ago
To get to the point where you can be mostly hands-free you have to invest a lot of time being hands-on building the guardrails.
If you want an agent to review is better to use a diferent agent, not necessarily a diferent model just someone with a fresh context and the narrower the instruction the better, so you can send one looking for useless tests, another for missed paths, another looking for optimizations.
You can also setup screenshot tests of every view combination and review those if you don't wnat to look at code.
But you can do a lot with code, I would use agents only for what you can't express with code.
1
u/beefswizzle 1d ago
TDD
1
u/Ambitious_Spare7914 1d ago
Tell your brain agent to adhere to TDD (test driven development) principles. It will then write tests first, then hand over tasks to builder agents. Writing tests first helps a lot because context is fresh and clean. Builders then have a clear, determinstic goal: pass the tests.
1
u/Rabe_Burns 1d ago
Coding constitution. It’s tough but worth it.
1
u/Future_AGI 1d ago
mutation testing is the check here, mutmut for Python or Stryker for JS, run on whatever the agent writes. It breaks your code on purpose and checks the tests fail, and most surviving mutants point straight at tests that pass without checking anything.
1
u/No-Blood2830 23h ago
you can lint in some cases for vacuous tests.
but yes at times they make useless tests or miss some cases. I mostly just let them try their best to pattern match the code base and then every so often ask a fable to spot and remote junk tests.
0
u/Limp_Classroom_2645 1d ago edited 1d ago
You add "make no mistakes" at the end of your prompts
Jokes aside i use this skill, it's designed to make tests as acceptance criteria via the implementation tasks, i've tried it on several large projects and it worked very well for me: https://github.com/avatsaev/av-swe-skill
0
u/ChCkN007_ 1d ago
Let me preface, I haven’t done anything yet, and I’ve only worked with small models.
I’ve been able to barely get reliable work out of the little stuff I’ve done with qwen3.5 9B, but what my plan to fix it is to setup some review feed back loop where the agent gets lsp checks either on every edit or every batch of edits, and then I want it to implement some temp smoke tests that catch basic mistakes. The tests could grow bigger in scope, but I think the limit is a tests that I can wrap my head around quickly and say, this is what it tests, this should be the output and then check the output. I dont want a testing suite that is incomprehensible because then I have no way to personally verify.
I suppose with a opus, you don’t have to care as much, but I’ve noticed Anthropic is always running smoke tests and checks after everything to double check its output
0
u/gbrennon 1d ago
usually agents(models are their brain) will write biased tests and this is really bad.
tests that arent testing anything.
agents should do the tdd so they start with a failing test