0Pricing
Vibe Coding · Lektion

Tests per Prompt generieren

Lassen Sie die KI aussagekräftige Tests schreiben.

Tests per Prompt generieren ist eine kostenlose Vibe Coding-Lektion auf CoddyKit. Dies ist Lektion 2 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Vibe Coding-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Vibe Coding-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

Tests Are Your Safety Net

When AI writes most of your code, tests become the contract that keeps it honest. Each assertion is a promise the assistant cannot silently break.

The goal is not 100 percent coverage for its own sake. It is to pin the behaviors you care about so that future generations cannot regress them.

This lesson is about prompting your way to a test suite worth trusting.

Describe Behavior, Not Implementation

Weak prompts ask the model to "write tests for this function." The result mirrors the implementation and passes trivially, even when the code is wrong.

Strong prompts describe the expected behavior in your own words. The test then encodes intent, not the model's reading of the existing code.

Specify inputs, outputs, and invariants the way a product spec would.

Write tests for the checkout function based on these rules, not on the current implementation: total must equal sum of line items minus discount; discount can never exceed subtotal; an empty cart must throw. Cover the boundary at exactly zero and at the discount cap.

Start With the Failing Case

Tests that only confirm the happy path give false comfort. Ask for the cases most likely to break first: nulls, empties, limits, and malformed input.

A suite that exercises failure modes is the one that catches real regressions. The boring success case rarely surprises anyone.

Front-load the edges and you front-load the bugs.

Generate tests that focus on failure and boundary conditions for this parser: empty string, whitespace only, max length plus one, invalid unicode, and deeply nested input. For each, assert the exact error type and message the code should produce.

Beware Tests That Pin Bugs

If you ask a model to write tests against existing code, it may assert the current buggy behavior as if it were correct. The suite goes green while the bug stays.

This is the single biggest trap in AI test generation. The test documents the defect instead of catching it.

Always review whether each assertion reflects what you want, not merely what the code currently does.

For each test you generated, tell me explicitly whether the expected value is derived from my stated requirements or from observing the current code's output. Flag any assertion that simply mirrors existing behavior so I can verify it is actually correct.

The Arrange-Act-Assert Spine

Readable tests follow a clear shape: set up state, perform one action, assert one outcome. Models drift into multi-assertion mega-tests that are hard to debug when they fail.

Ask for focused tests with descriptive names that read like specifications.

A failing test should tell you exactly which behavior broke, in its name alone.

Refactor these tests so each one follows arrange-act-assert, tests a single behavior, and has a descriptive name that reads like a sentence describing the expected outcome. Split any test that contains unrelated assertions.

Mocking the Right Boundaries

AI often mocks too much, stubbing out the very logic under test until the test asserts nothing real. Or it mocks too little and hits a live database.

Mock at the system boundary: network, clock, filesystem, payment gateway. Keep your own business logic real.

State the boundary explicitly so the model does not guess.

Write these tests so that only external boundaries are mocked: the HTTP client, the system clock, and the payment provider. Do NOT mock our own pricing or validation logic; that logic must run for real so the test exercises it.

Property-Based Thinking

Example tests check specific inputs; property tests check invariants across many generated inputs. "Reversing a list twice returns the original" holds for every list.

Asking the model for property-based tests surfaces bugs that hand-picked examples miss, because the framework hunts for counterexamples.

Use them where invariants are clear: encoders, sorters, serializers, math.

Write property-based tests for the serializer using a generative testing library. Assert the round-trip invariant that decode(encode(x)) equals x for any valid input, and let the framework search for the smallest failing case.

Coverage Without Theater

Coverage percentage is a map, not the territory. You can hit every line while asserting nothing meaningful. Models love padding suites to chase a number.

Use coverage to find untested branches, then judge each by hand: is this path worth pinning?

Aim for tests that would fail if the behavior were wrong, not tests that merely execute the code.

Run coverage and list the uncovered branches in this module. For each one, tell me whether it represents a meaningful behavior worth testing or trivial code I can ignore, and propose a focused test only for the meaningful ones.

Mutation: Testing Your Tests

A green suite that survives any code change is worthless. Mutation testing introduces small bugs and checks whether your tests notice.

If a mutant survives, your tests do not actually constrain that behavior. The model can propose mutations and you verify your suite kills them.

This is how you measure test quality, not just quantity.

Propose five small mutations to this function, such as flipping a comparison or removing a guard, that would represent real bugs. For each mutation, tell me whether the current test suite would catch it, and write a new test for any mutation that survives.

Make Tests Deterministic

Flaky tests erode trust until people ignore failures entirely. The usual culprits are real time, random seeds, network calls, and test ordering.

Demand deterministic tests: inject the clock, fix the seed, isolate state between runs. A suite you cannot trust is worse than no suite.

Reliability is a feature of the tests themselves.

Make this test suite fully deterministic: inject a fixed clock instead of reading current time, seed all randomness, remove any reliance on test execution order, and ensure each test resets shared state in setup and teardown.

Tests As Living Spec

A good suite doubles as documentation. New contributors, human or AI, learn the system's rules by reading the assertions.

Keep test names and structure clear enough that the suite explains intended behavior on its own. The model reads them too, and writes better code as a result.

Your tests become the durable memory the model lacks.

Quick Check

Test your grasp of prompt-driven test generation.

Recap

Prompt tests from behavior and requirements, not from the implementation, so they catch bugs instead of pinning them. Front-load failure and boundary cases, mock only at boundaries, and use property and mutation testing to measure real strength.

Keep the suite deterministic and readable so it serves as a living spec. Next, you will hunt for security gaps the model left behind.

Häufig gestellte Fragen

Ist die Lektion „Tests per Prompt generieren“ kostenlos?

Ja — der vollständige Text von „Tests per Prompt generieren“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Vibe Coding-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Vibe Coding-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Tests per Prompt generieren“?

Lassen Sie die KI aussagekräftige Tests schreiben. Du übst Vibe Coding mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Vibe Coding zu starten?

Keine Vorkenntnisse erforderlich. Vibe Coding auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 4.

Wie lange dauert die Lektion „Tests per Prompt generieren“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Vibe Coding-Lektion Code schreiben und ausführen?

Ja. Jede Vibe Coding-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Warum KI-generierter Code geprüft werden muss
  2. Tests per Prompt generieren
  3. Sicherheitslücken finden
  4. Für den Produktivbetrieb absichern
← Zurück zu Vibe Coding