Voltar ao glossario
TestingPopular

Unit Testing

A software testing method where individual units or components of code are tested in isolation to verify they work correctly.

Definicao

Unit tests verify the smallest testable parts of an application — typically individual functions or methods. They mock external dependencies to isolate the code under test. Good unit tests are: fast (run in milliseconds), independent (no shared state), repeatable (same result every time), and self-validating (clear pass/fail). Popular frameworks include Jest (JavaScript), pytest (Python), JUnit (Java), and Go's testing package.

Por que e importante

Unit tests catch bugs at the source, provide documentation of expected behavior, and enable safe refactoring. Teams with high unit test coverage report 40-80% fewer production bugs. Unit tests also run fast enough to include in every CI pipeline.

Exemplo

A unit test verifies that a calculateDiscount() function returns 10% off when given a $100 order from a VIP customer, mocking the database calls to customer data.

Termos relacionados

unit testingwhat is unit testingunit testunit testing definition

Automatize Code Review com diffray

Sistema de IA multi-agente para code review. Encontra bugs, vulnerabilidades de seguranca e problemas de arquitetura automaticamente.