How I stopped writing unit tests manually using Aider CLI A developer reports that using Aider CLI, a terminal-based AI coding agent, reduced the time to reach 90% test coverage on a standard CRUD service from 45 minutes of manual typing to 6 minutes, with a very high bug detection rate. The workflow involves setting up Aider with an API key from Anthropic or OpenAI, using Claude 3.5 Sonnet for sharper edge-case reasoning, and prompting the tool with specific test requirements to generate Vitest tests directly into files. How I stopped writing unit tests manually using Aider CLI If you aren't using a terminal-based AI coding agent to handle your testing overhead, you're essentially working in slow motion. I recently shifted my entire workflow to Aider CLI, and the difference in velocity is staggering. Aider isn't just a chat interface; it's a pair programmer that lives in your git repo, understands your file tree, and actually applies changes instead of just spitting out code blocks you have to copy-paste. Setting up the Aider environment for rapid testing Before you can let an AI write your tests, you need the right environment. Don't just run pip install aider-chat and hope for the best. You need a model that actually understands context windows and edge cases. First, grab an API key from Anthropic or OpenAI. I personally swear by Claude /en/tags/claude/ 3.5 Sonnet for testing because its reasoning on edge cases—like null pointers or empty arrays—is significantly sharper than GPT-4o's current iteration. Create a dedicated virtual environment to avoid dependency hell python -m venv aider-env source aider-env/bin/activate Install aider with the necessary dependencies pip install aider-chat Set your API key don't hardcode this in your scripts export ANTHROPIC API KEY=your key here Once installed, launch it inside your project root. Aider will immediately index your files. This is the "magic" part. It doesn't just see the file you're working on; it sees the imports, the types, and the existing test patterns. This is where you can find high-quality AI Coding /en/category/ai-coding/ workflows that actually scale. The "Test-Driven" Command workflow The biggest mistake beginners make is asking "Write tests for this file." That's too vague. The AI will give you happy-path tests that pass in five seconds but fail the moment a user enters a weird string. Instead, I use a specific prompting pattern within the Aider CLI. I treat the CLI as a senior engineer who is reviewing my code. Let's say I have a file src/utils/math.ts with a function that calculates compound interest. I want to ensure it handles rounding errors and negative rates correctly. Start Aider and add the specific files to the chat context aider src/utils/math.ts tests/math.test.ts Once inside the Aider session, don't just ask for tests. Give it a persona and a strict requirement. Use this command: "Review math.ts. Identify three edge cases regarding floating point precision and negative input. Then, generate Vitest unit tests in math.test.ts that specifically target these edge cases. Ensure you use 'describe' blocks for organization." Aider will then: 1. Read math.ts . 2. Think about the logic. 3. Write the code directly into math.test.ts . 4. Automatically commit the change to your git history with a descriptive message. Benchmarking Aider vs. Manual Writing I ran a quick experiment on a standard CRUD service. I timed how long it took to reach 90% test coverage. | Method | Time to 90% Coverage | Bug Detection Rate Initial Run | Effort Level | | :--- | :--- | :--- | :--- | | Manual Typing | 45 minutes | High | Exhausting | | Copilot Autocomplete | 25 minutes | Medium | Moderate | | Aider CLI Agentic | 6 minutes | Very High | Low Reviewer only | The "bug detection" part is crucial. Because Aider can "see" the whole file, it often suggests tests for things I hadn't even considered, like a specific error thrown by a library deep in the call stack. If you want to keep up with this speed, you need to constantly update your Resources /en/category/resources/ list with the latest agentic patterns. Handling the "Hallucination" trap in testing AI-generated unit tests have a specific failure mode: they sometimes hallucinate that a test passed because they wrote the test to match the incorrect logic of the function. This is dangerous. If your function is return a / b and it doesn't check if b is zero, the AI might write a test that says expect divide 10, 0 .toBe Infinity . Technically, the test passes, but your code is broken. To solve this, I implement a "Verification Loop" in Aider. After it generates the tests, I run this command: "Run the tests using 'npm test'. If any fail, analyze the error, fix the implementation in math.ts, and re-run until they pass. If the tests pass but the logic is mathematically unsound, rewrite the tests to be more rigorous." This turns Aider from a code generator into an autonomous agent. It's no longer just writing text; it's executing a loop of Write - Run - Fix . This is the essence of why moving toward AI Models /en/category/ai-models/ that support tool-use and terminal execution is the only way forward for modern devs. Advanced: Using MCP /en/tags/mcp/ for even deeper context If you're working in a massive monorepo, even Aider might struggle with context. This is where the Model Context Protocol MCP comes in. By setting up MCP servers, you can allow your AI agents to query your database schema or your documentation directly to inform the unit tests they write. Imagine telling Aider: "Write a test for this user service, but look at the SQL schema in /docs/schema.sql to make sure the mocked data matches the actual database constraints." That level of precision is what separates a junior "prompt engineer" from a senior engineer who uses AI to multiply their output by 10x. It's about controlling the flow of information, not just asking for magic snippets. Stop writing the same it 'should work' blocks over and over. If you aren't using the terminal to orchestrate these agents, you're leaving hours of your life on the table every single week. Next LTX-2. → /en/threads/7345/ an AI side-hustle playbook https://tanyan888.com/ , with plenty of directly applicable cases. All Replies (0) No replies yet — be the first