当前位置:网站首页>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 ICT test probe industry research and trend analysis report
- The programmer's girlfriend gave me a fatigue driving test
- Plot size and resolution with R markdown, knitr, pandoc, beamer
- 20220215-ctf-misc-buuctf-ningen--binwalk analysis --dd command separation --archpr brute force cracking
- CSDN常用复杂公式模板记录
- Why should VR panoramic shooting join us? Leverage resources to achieve win-win results
- Pycharm useful shortcut keys
- Search rotation sort array
- Simple application example of rhai script engine
- Don't worry about whether you can be a coder if you don't learn English well. Learn it first
猜你喜欢
20220216 misc buuctf another world WinHex, ASCII conversion flag zip file extraction and repair if you give me three days of brightness zip to rar, Morse code waveform conversion mysterious tornado br
2022-2028 global plant peptone industry research and trend analysis report
女朋友说:你要搞懂了MySQL三大日志,我就让你嘿嘿嘿!
[designmode] factory pattern
ABAQUS 2022 latest edition - perfect realistic simulation solution
2022-2028 global herbal diet tea industry research and trend analysis report
Implementation of OSD on Hisilicon platform (1)
How does the VR cloud exhibition hall bring vitality to offline entities? What are the functions?
The programmer's girlfriend gave me a fatigue driving test
Introduction to ES6 promise, new features of ES7 and es8 async and await
随机推荐
2022-2028 global mobile scanning radiology room industry survey and trend analysis report
C /platform:anycpu32bitpererrored can only be used with /t:exe, /t:winexe and /t:appcontainerexe
2022-2028 global plant peptone industry research and trend analysis report
Rust controls Dajiang programmable UAV Tello
2022-2028 global rampant travel industry research and trend analysis report
Bugku CTF daily one question dark cloud invitation code
2022-2028 global elevator emergency communication system industry research and trend analysis report
Fh6908a negative pole turn off synchronous rectification analog low voltage drop diode control IC chip tsot23-6 ultra low power rectifier 1W power consumption < 100ua static replacement mp6908
leetcode 474. Ones and zeroes (medium)
How does the VR cloud exhibition hall bring vitality to offline entities? What are the functions?
Why did kubernetes win? The changes in the container circle!
Advanced mathematical modeling
ABAQUS 2022 software installation package and installation tutorial
ABAQUS 2022 latest edition - perfect realistic simulation solution
20220215 misc buctf easycap Wireshark tracks TCP flow hidden key (use of WinHex tool)
Wordpress blog uses volcano engine veimagex for static resource CDN acceleration (free)
Redis - cache penetration, cache breakdown, cache avalanche
Why should VR panoramic shooting join us? Leverage resources to achieve win-win results
Kubernetes ---- pod configuration container start command
IFLYTEK active competition summary! (12)