当前位置:网站首页>Unit test concept and purpose
Unit test concept and purpose
2022-07-01 00:29:00 【Another piece of braised pork】
Navigation
Why do we need unit testing ?
Imagine an old system that has been used for more than ten years , When you need to modify the code , The developer in charge of the modification has just taken over , In this case , Presumably most people dare not modify the original code , Because it is often changed A Code at , The results showed that there were hundreds of thousands of miles apart after the launch Z The function is affected .
Why does this happen ? The essential reason is that the developers do not have enough knowledge of the system code ? Obviously not . A system developed by many people , Often the style is not uniform , The internal calling relationship is complicated . We need a means , That is, the code style can be standardized at a certain level , More importantly, you can find the impact of code changes on functions as soon as possible .
unit testing , Formal means , It can help developers and testers improve code quality 、 Find code problems earlier .
What is unit testing
unit testing (unit testing), It refers to the inspection and verification of the smallest testable unit in the software . as for “ unit ” Size or range of , There is no clear standard , Mainly based on the language used . If you are using functional programming , A unit most likely refers to a function . Your unit test will call this function with different parameters , And assert that it returns the expected result ; In object-oriented languages , Go to the next method , Up to a class can be a unit , From a single method to an entire class can be a unit .
Unit testing in a broad sense , There are three aspects :
- 1. Code day reading (Code review): Observe whether the input parameters of the code are verified 、 Whether the algorithm is correct 、SQL sentence 、 Exception handling and so on ;
- 2. Static code analysis (Static analysis): Bring in assumed parameters , Infer whether the code can execute normally , Whether the analysis results are correct ;
- 3. Dynamic code analysis (Dynamic analysis): By writing test scripts , Actually call the tested code , To verify code execution ;
The first two depend mainly on the human brain , It's limited . So when we talk about unit testing , It mostly refers to the third way of dynamic code . Dynamic code is not only more efficient 、 The results are more accurate , And can be preserved for a long time 、 Multiple runs , You can run away every time you submit code , Test and verify the new functions , It can also return to the original functions .
Who does the unit test
There are two options : Developers do or The tester does
Developers do unit tests :
- advantage : Stronger development and coding ability , Have a better grasp of the system , So writing test scripts is faster ;
- Inferiority : Weak test concept , The coverage scenario is not comprehensive ; Test your own code , There is the possibility of lazy water ;
Testers do unit tests :
- advantage : Be able to design more comprehensive test cases , Higher coverage ; More strictly , Put an end to water drainage ;
- Inferiority : Coding ability is weak , The efficiency of test script writing is low ;
My point of view is that unit tests are done by testers . First, in daily work , Discover and develop unit test and waterproof verification , To increase test coverage , resort to every conceivable means , Coverage data is up , But in fact, it is not really detected . Then I think highly of TDD Pattern , stay TDD In the mode of , The tester writes the test case first , Developers will implement , This model can not only make the requirements more explicit 、 Reduce late requirement modification , And the test left shift is realized , Better guarantee code quality .
Unit tests are done by testers , It is not only a test of the coding ability of testers , It is also a test of the workflow . For most people who are used to traditional waterfall programming IT people , Pair programming 、 Test driven development needs a clear feasibility precedent and adaptation process , I'm also doing exploratory practice in the company's microservice project .
The purpose of unit testing
Unit tests can help us solve 、 Prevent certain problems , But that alone is not enough , Is the value of unit testing big enough for us to do it ? For businesses , Benefits , Always first . Unit testing is popular in the enterprise , Its primary purpose , Is to improve the efficiency of the enterprise !
How can unit testing improve efficiency ? Most people have their first feelings about unit testing , It will increase the workload of developing code , before 7 The need to be able to develop in the future , With unit testing, you may have to 14 days .

But we have to look at it as a whole , The life cycle of software goes far beyond “ Development ” This one link . Although the introduction of unit testing increases the cost of development , But from “ Test pyramids ” In theory , The sooner you find an error , The lower the cost of correction , So the more tests at the bottom , On the contrary, the more efficiency can be improved !

边栏推荐
- 2022-2028 global capsule shell industry research and trend analysis report
- 2022-2028 global retro glass industry research and trend analysis report
- VR panorama adds contrast function to make the display of differentiation effect more intuitive!
- The principle and related problems of acid in MySQL
- Luogu p1144 shortest circuit count
- MySQL index test
- Design e-commerce seckill system
- Query points in MATLAB Delaunay triangulation
- CSDN常用复杂公式模板记录
- 2022-2028 global rotary transmission system industry research and trend analysis report
猜你喜欢

ABAQUS 2022 software installation package and installation tutorial

How does the VR cloud exhibition hall bring vitality to offline entities? What are the functions?

6-1 exploit -ftp exploit

2022-2028 global ICT test probe industry research and trend analysis report

2022-2028 global elevator emergency communication system industry research and trend analysis report
![[designmode] factory pattern](/img/62/9be808b3e1c2139d564caa307fcd30.png)
[designmode] factory pattern

What should I do without 50W bride price

Introduction to ES6 promise, new features of ES7 and es8 async and await

2022-2028 global herbal diet tea industry research and trend analysis report

IFLYTEK active competition summary! (12)
随机推荐
MySQL storage engine
VR panorama adds contrast function to make the display of differentiation effect more intuitive!
Search rotation sort array
On the application of cluster analysis in work
Rust controls Dajiang programmable UAV Tello
How does the VR cloud exhibition hall bring vitality to offline entities? What are the functions?
The full technology stack, full scene and full role cloud native series training was launched to help enterprises build a hard core cloud native technology team
Error 2059 when Navicat connects to MySQL
高等数学建模
Introduction to ES6 promise, new features of ES7 and es8 async and await
Using Excel to quickly generate SQL statements
Rust book materials - yazhijia Library
2022-2028 global capsule shell industry research and trend analysis report
ABAQUS 2022 latest edition - perfect realistic simulation solution
1175. prime number arrangement / Sword finger offer II 104 Number of permutations
LVM snapshot: preparation of backup based on LVM snapshot
Vmware16 installing win11 virtual machine (the most complete step + stepping on the pit)
Red Hat将在Project Atomic上运用容器负载服务器
What is the fastest way to import data from HDFS to Clickhouse? Spark is imported through JDBC or HDFS
The principle and related problems of acid in MySQL