返回术语表
测试Popular

Unit Testing

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

定义

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.

为什么重要

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.

示例

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.

相关术语

unit testingwhat is unit testingunit testunit testing definition

使用diffray自动化代码审查

多智能体AI代码审查系统。自动发现bug、安全漏洞和架构问题。