当前位置:网站首页>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 !

边栏推荐
- Five minutes to understand the exploratory test
- 1175. prime number arrangement / Sword finger offer II 104 Number of permutations
- CentOS install MySQL
- Bugku CTF daily one question dark cloud invitation code
- CentOS 6.3 x64 PHP 5.2.6 扩展安装OpenSSL出错的解决方法
- 如何关闭一个开放的DNS解析器
- Repetition is the mother of skill
- Random ball size, random motion collision
- Don't worry about whether you can be a coder if you don't learn English well. Learn it first
- Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)
猜你喜欢

MySQL variables, stored procedures and functions

2022-2028 global single travel industry research and trend analysis report

Vulnerability discovery - App application vulnerability probe type utilization and repair

CTF tool (1) -- archpr -- including installation / use process

2022-2028 global ethylene oxide scrubber industry research and trend analysis report

Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)

2022-2028 global carbon fiber room scraper system industry research and trend analysis report

2022-2028 global plant peptone industry research and trend analysis report

BeanUtils. Copyproperties() vs. mapstruct

VR panorama adds contrast function to make the display of differentiation effect more intuitive!
随机推荐
Rust controls Dajiang programmable UAV Tello
Warmup preheating learning rate "suggestions collection"
Bugku CTF daily one question dark cloud invitation code
Thoughts on the future of data analysis in "miscellaneous talk"
CentOS installation starts redis
Don't worry about whether you can be a coder if you don't learn English well. Learn it first
What does it mean to open an account online? Is it safe to open an account online?
Rust book materials - yazhijia Library
2022-2028 global electric yacht industry research and trend analysis report
How do it outsourcing resident personnel position their pain points?
2022-2028 global encrypted external hard disk industry research and trend analysis report
6-1 exploit -ftp exploit
Is it safe to choose mobile phone for stock trading account opening in Guangzhou?
Why should VR panoramic shooting join us? Leverage resources to achieve win-win results
C WinForm program interface optimization example
lvm-snapshot:基于LVM快照的备份之准备工作
Search rotation sort array
2022-2028 global retro glass industry research and trend analysis report
$watch will not trigger data change - $watch not firing on data change
ABAQUS 2022 latest edition - perfect realistic simulation solution