Was ist Unit Testing in der Softwareentwicklung

Bo WesdorpMitgründer und CTO, Miyagami Praxis3 Min. Lesezeit

Unit Testing ist die Praxis, die kleinsten testbaren Einheiten eines Programms – in der Regel einzelne Funktionen oder Klassen – isoliert zu prüfen. Ein Unit Test ruft den Code mit bekannten Eingaben auf und vergleicht das Ergebnis mit der erwarteten Ausgabe. Da er auf Datenbanken und Netzwerke verzichtet, läuft er in Millisekunden und zeigt bei einem Fehler genau eine Ursache an.

Was als Einheit gilt

Eine Einheit ist das kleinste Stück Verhalten, das sich eigenständig prüfen lässt. In den meisten Codebasen ist das eine Funktion, eine Methode oder eine kleine Klasse. Der Begriff ist weniger entscheidend als die Abgrenzung: Ein Unit Test sollte für sein Ergebnis weder eine laufende Datenbank noch einen Netzwerkaufruf noch einen anderen Dienst benötigen.

Wie sieht ein Unit Test aus

Ein typischer Unit Test besteht aus drei Teilen. Sie bereiten die Eingabe vor, rufen den Code auf und prüfen das Ergebnis. Ein Test für eine Preisberechnung könnte einen Warenkorb und einen Rabattcode übergeben und die Gesamtsumme prüfen. Ist die Summe falsch, nennt der fehlgeschlagene Test die Funktion, die untersucht werden muss.

Wie unterscheiden sich Unit Tests von Integrationstests

Unit Tests prüfen eine einzelne Einheit isoliert. Integrationstests prüfen, ob mehrere Einheiten zusammenarbeiten – zum Beispiel Ihr Code und eine echte Datenbank. End-to-End-Tests steuern das gesamte Produkt so, wie es ein Nutzer tun würde.

Unit Test Integrationstest End-to-End-Test
Umfang Eine Funktion oder Klasse Mehrere Komponenten Gesamtes Produkt
Geschwindigkeit Millisekunden Sekunden Seconds to minutes
Dependencies Replaced or avoided Real or close to real Real
Failure tells you Exactly where Which boundary That something broke
Typical share of a suite Largest Middle Smallest

This shape is often called the test pyramid: many fast unit tests at the bottom, fewer slower tests above.

What should you unit test

Test logic that can go wrong: calculations, validation rules, parsing, state changes and edge cases such as empty input, very large values and unexpected types. Skip code that only passes data through, and skip tests that restate the implementation line by line. A test that breaks every time you refactor, without catching a real bug, costs time and protects nothing.

What about mocks

A mock or stub replaces a dependency, such as a payment provider, so the unit can be tested alone. Use them at real boundaries and keep them simple. Heavy mocking often means the code is tangled, and the test then checks the mocks instead of the behaviour. When a dependency is cheap and deterministic, use the real one.

How do unit tests help with AI-written code

Coding agents write code faster than anyone can read it closely, so a fast, trustworthy test suite becomes the specification the agent has to meet. Good unit tests tell an agent what correct means for each function, and they tell a reviewer quickly when a change broke something. They do not replace judgement: an agent can write tests that pass while checking the wrong thing, which is why test coverage and confidence are different. Pair unit tests with careful review of AI-generated code, and use regression testing to protect behaviour over time.

Was das für Ihre Einstellung bedeutet

Engineers who write tests alongside the feature ship code you can change safely. In our vetting, candidates work in a real codebase for two sixty-minute sessions, one with AI tools off and one with their own agents on, and both scorecards show how they verify their own changes. If you need engineers who build test discipline into delivery, see backend engineers, from €5.600 a month for a full-time engineer.

Kurze Antworten

What is the difference between unit testing and integration testing?

Unit tests check one function or class in isolation. Integration tests check that several components work together, such as your code and a database.

How many unit tests are enough?

Enough to cover logic that can fail, including edge cases. Chasing a coverage percentage matters less than testing behaviour you rely on.

Should AI-generated code have unit tests?

Yes. Tests give the agent a definition of correct and give reviewers a fast signal that a change did not break anything.

Do unit tests replace manual testing?

No. They catch logic errors quickly, while exploratory and visual checks still need a person.

Kontakt aufnehmen

Shortlist in drei Tagen erhalten

Sie schicken uns die Rollen und den Stack, in einem kurzen Formular oder in einem 30-minütigen Gespräch. Innerhalb von drei Werktagen erhalten Sie Senior Engineers mit Namen zur Prüfung, jeweils mit beiden Scorecards, und Sie können innerhalb von fünf Werktagen einstellen.

Bewertet aufClutch39 Bewertungen
ISO 27001
Zertifiziert

Dreißig Minuten mit Dale buchen

Der Kalender wird von HubSpot bereitgestellt und setzt eigene Cookies. Laden Sie ihn hier, oder buchen Sie direkt auf der HubSpot-Seite.

Buchungsseite öffnen