What is Unit Test?
Turkish: Unit Test
A unit test verifies a small code unit such as a function or class quickly and automatically while isolating external dependencies.
What is a Unit Test?
A unit test checks the expected behavior of a small, clearly bounded piece of code. The unit may be a function, class method, or domain service; external dependencies such as databases, file systems, or networks are usually isolated with mocks, stubs, or fakes.
How Is It Written?
A common structure is Arrange, Act, Assert:
- Arrange: Prepare test data and dependencies.
- Act: Run the function or method under test.
- Assert: Check the returned value, thrown error, or changed state.
A good unit test is fast, deterministic, and readable. If time, randomness, external services, or global state influence the result, the test becomes fragile.
Business Use
Unit tests protect business logic such as pricing, permissions, form validation, stock rules, and data transformations. In TDD, writing the unit test first gives design feedback.
A fast unit test suite inside CI/CD gives developers early warning before merge. Unit tests are not enough on their own; integration and end-to-end tests cover different risks.
Related Terms
API testing validates endpoint responses, error codes, performance, and authorization behavior through repeatable test scenarios.
CI/CD (Continuous Integration / Continuous Delivery)CI/CD makes software releases repeatable by moving code changes through automated build, test, and deployment pipelines.
Code CoverageCode coverage shows which lines, branches, or functions automated tests executed, helping reveal untested parts of a codebase.
End-to-End TestAn end-to-end test validates a user journey across the UI, API, database, and integrations in a flow close to real usage.
Integration TestIntegration testing verifies the expected data flow when multiple modules, services, or external systems work together.
JestJest is a popular testing framework developed by Facebook for JavaScript and TypeScript, known for its ease of use.
Shift Left TestingShift left testing moves automated checks into requirements, design, and coding stages so defects are found before production.
TDD (Test-Driven Development)TDD is a development practice where a failing test is written first, then the smallest passing implementation shapes the design.
Test AutomationTest automation runs selected test scenarios repeatedly with tools and sends the results into CI pipelines or reporting systems.