当前位置:网站首页>When should I write unit tests? What is TDD?
When should I write unit tests? What is TDD?
2022-04-23 01:39:00 【Wei Bo-】
One 、 Traditional methods and TDD Method
1、 Some people think that writing unit tests after software coding ( traditional method ), The process is as follows :

shortcoming : Writing unit tests after writing functional code will lead to unit tests “ Particle size ” It's coarser . For the same function code , If the TDD programme , The result may be 10 individual “ Small ” Single test to cover , Each single test is relatively simple and easy to understand , Readability and maintainability are good , The single test changes little during reconstruction ; If you write a single test in the traditional way , It's often done with 1 individual “ Big ” Single test to cover , This single test logic is more complex , Because it has a lot to measure , Readability and maintainability are poor .
2、 Later, more and more people chose to write unit tests before software coding , This approach becomes test first or test driven development (Test-Driven Development,TDD), The process is as follows :

explain : First write a failed test , Then create the product code , And make sure that this test passes , The next step is to refactor the code or create another test that will fail . The specific process is to write a small amount of function code first , Then write unit tests , Repeat the two processes , Until the function code development is completed . The result is : Basically, the function code has been developed , Unit testing is almost complete .
(1) Write a test that will fail , To prove the lack of code or function in the product .
When writing tests , Assume that the product code is already working , In this way, the failure of the test indicates that there are defects in the product code . This test will initially fail to compile , Only after adding the required code , Only after compiling can it pass , Then the test can run , But it will fail , Because the required functions have not been realized yet .
(2) Write product code that meets the test expectations , Make the test pass .
(3) Refactoring code .
If the test passes , You can write the next unit test or refactor , Make the code more readable or remove duplicate code, etc . Refactoring can be done after writing multiple tests , It can also be done after each test . Refactoring is an important practice , He makes sure the code is easier to read , Better maintenance , At the same time, it can still pass all the tests written before .
Two 、 Succeed in TDD Three core skills
Succeed in TDD Three skills are required :
1、 Write excellent tests , You can maintain 、 Can be read 、 reliable .
2、 Write tests before coding .
3、 Good test design .
版权声明
本文为[Wei Bo-]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230136077734.html
边栏推荐
- Detonate the bomb (DFS)
- Summary of commonly used commands of LSF
- Gbase 8s Group by 功能介绍
- Gbase 8s检查点简介
- Itextsharp page setup
- CVPR | 2022 | expressed by transformer learning multiple hypotheses! A new framework for 3D human pose estimation!
- Chris LATTNER, father of llvm: the golden age of compilers
- 计蒜客家谱(dfs求直系后代数)
- gin框架的学习--golang
- Learning methods and career development guide (2022 Edition)
猜你喜欢

DO447管理用户和团队的访问

World reading day: 18 it books with Douban score above 9.0 are worth collecting

01 knapsack problem - and deformation problem

42、使用mmrotate中k3det进行旋转目标检测,并进行mnn部署和ncnn部署

Realize the function of progress bar through layerdrawable

(product resources) mingdeyang ad8488 module high performance digital X-ray FMC interface 128 analog channel high-speed ADC chip

彻底卸载Antidote 10 ?Antidote卸载不干净怎么办?

Soatest preliminary understanding

Introduction to PCIe xdma IP core (with list) - mingdeyang science and Education (mdy edu. Com)

CVPR | 2022 | expressed by transformer learning multiple hypotheses! A new framework for 3D human pose estimation!
随机推荐
Is the stable currency a super opportunity to accelerate the death of the public chain or replace BTC?
安装mysql出问题求解决
[registration] tf54: engineer growth map and excellent R & D organization building
[interview skills] how to face an interview without a leading group
Full Permutation (DFS and next_permutation solution)
Gbase 8s存储结构简介及空间管理
After disk D is distributed to Disk C, what should I do if the database recovery hangs? Please answer
GBASE 8s 并发控制之封锁操作
2n queen problem
CDR2022首发全新版本性能介绍
清研环境深交所上市:年营收1.8亿 市值41亿
Good test data management, in the end how to do?
LSF的使用方法总结
iTextSharp 页面设置
UVC camera encapsulation class
How to introduce SPI into a project
01 knapsack problem - and deformation problem
Use Charles to grab app package
Rôles attributs personnels Abréviations
Gbase 8s query processing and optimization