Vibe Coding

Tests as Guardrails

Tests tell the agent what correct looks like. Write or generate tests, then make them pass.

Why tests matter more with AI

A model can produce code that looks right and fails on empty input. Tests are the contract. They also give the agent a target: "make pytest pass" is a better done condition than "looks good."

Write the test first when you can

# test_words.py
from words import unique_words

def test_unique_sorted_casefold():
    assert unique_words("Vibe vibe coding") == ["coding", "vibe"]

def test_empty():
    assert unique_words("") == []

Then prompt: "Implement unique_words in words.py so pytest -q passes. Do not change the tests."

Never let the model "fix" tests by weakening them

Watch for deleted assertions, pytest.mark.skip, or assert True. That is cheating. Revert and say: "Do not modify tests. Fix the implementation."

A solid done line

Done when:
- pytest -q exits 0
- python notes.py list still works
- no new dependencies

You run those commands. If the agent claims tests passed, believe the terminal, not the chat.

How you use tests while you work

  1. Prefer writing or generating tests before the implementation of a new behavior.
  2. Say “do not edit tests” when you ask for the implementation.
  3. You run pytest -q in the terminal. If the agent says it passed, look at your own output.
  4. A red test is a gift: paste it and ask for the smallest fix. A silently deleted test is a crime.

What to test in a vibe-coded slice

  • The happy path you asked for.
  • Empty input and missing files.
  • One obvious edge: duplicates, case, or bad index.

You do not need a hundred tests. You need enough that a silent rewrite would fail.

Try it yourself

The agent changed assert unique_words("") == [] to assert True. What is going on, and what do you type?

Show solution

It cheated to go green. Restore the test file. “Do not modify tests. Fix unique_words so the original assertions pass.” Run pytest yourself.

Key takeaways

  • Tests are the spec the model can execute.
  • Protect test files in the prompt.
  • Green tests plus a read diff is the release bar for a slice.
  • You run the suite. Chat is not a test report.

FAQ: Tests as Guardrails

Common questions about this page.

What is vibe coding?

Vibe coding is building software by directing an AI in natural language while you review, test, and own the result. The StudyGrid Vibe Coding course teaches the workflow, prompts, and habits that make it work.

Should I run tests for vibe coding examples locally for better learning?

Yes. Use the browser editor on StudyGrid for a quick check, then Download the example and run it on your computer. Local runs show real errors and the real toolchain, which is one of the fastest ways to learn tests for vibe coding in this Vibe Coding AI lesson (Tests as Guardrails).

How do I vibe code the right way?

Give one clear goal, attach the files that matter, ask for a plan first, review every diff, run tests, then commit a small slice. The How You Work lesson is the session guide. Best Practices is the full playbook.

How does a user actually work with vibe coding?

You open a real project in an agent editor or CLI agent (Cursor, VS Code + Copilot, Claude Code, and similar), write one goal, attach two or three files, ask the agent to plan then implement a small slice, read the diff, run tests yourself, and commit. You are the director. The model drafts. The How You Work lesson walks through a 30-minute session. The Tools lesson is the stack picker.

Is vibe coding only for experts?

No. Beginners can use it to learn faster if they read the generated code. Experts use it to move quicker on boilerplate while keeping architecture and review in their hands.

What tools do I need for vibe coding?

You need an agent that can read your project, edit files, and show a diff — for example Cursor, VS Code with GitHub Copilot, Claude Code, Codex CLI, Continue, or Windsurf — plus Git for undo and a language you can read (this course uses Python). A browser chatbot is not enough. The Tools lesson compares the stacks. Setup covers the checklist.

Which AI coding tool should I use for vibe coding?

Pick one stack and stay with it for a project. Cursor is a common agent editor. VS Code plus GitHub Copilot fits if you already work there. Claude Code and Codex CLI are terminal agents. Continue, Windsurf, Zed, and JetBrains AI Assistant also work if they can apply a diff. Do not hop tools on a dirty tree.

Is the Vibe Coding course free?

Yes. The full Vibe Coding course on StudyGrid (studygrid.in) is free. Open the header menu, start at What Is Vibe Coding, then How You Work and Tools, and follow Next through the project and cheatsheet.