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:

  1. Arrange: Prepare test data and dependencies.
  2. Act: Run the function or method under test.
  3. 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.