单元测试说明文档
Unit testing is a type of testing which is found at the bottom of the software testing pyramid. It involves breaking the codebase down into smaller parts (or units) and testing those in isolation.
单元测试是一种测试类型,位于软件测试金字塔的底部。 它涉及将代码库分解为较小的部分(或单元),并进行独立测试。
Depending on the type of programming language (or paradigm) these can be against anything you define as a unit, although the most common practice is against functions.
根据编程语言(或范例)的类型,这些可能会与您定义为一个单元的任何内容发生冲突,尽管最常见的做法是针对函数。
为什么呢 (Why do it?)
Protection - Unit testing protects against introducing new or old bugs for defensive programming
保护 -单元测试可防止为防御性编程引入新的或旧的错误
Confidence - You can add changes, or reuse or refactor code (both very common) and be sure you haven’t added a bug
信心 -您可以添加更改,重用或重构代码(这两种都很常见),并确保您没有添加错误
Documentation - Unit testing documents the behavior and flow of code so its easy for someone new to the code to understand it
文档 -单元测试记录了代码的行为和流程,因此对于新手来说很容易理解
Isolation - It isolates a module