Original: Li Sheng
What does unit testing measure?
Of course, module module in test code
But how do you do a modular unit test?
The unit test cases of some project teams are exactly same as test suites of other levels of software testing - same functional tests
Same performance test and interface
Programmer
After writing code, make sure syntax of code is correct by compiling it;
Using unit tests to check semantics of code
And a unit test, which is almost identical to configuration element test
Does this also make code semantically correct?
Actually
Good unit test design should not overlap with design of other test-level test suites
It should include following aspects of test content:
Checking module interface parameters should include
Check if number of entered actual parameters matches number of formal parameters and if attributes match
Check if actual parameters given when calling other modules match number of formal parameters of called module, and if attributes match
Verify that number, attributes, and order of parameters used when calling a predefined function are correct
Check for extraneous parameters
Check if read-only setting has been changed
Check if global variable definitions are consistent in each module
Check if certain constraints are being passed as parameters
If a module includes external input and output, it must also include:
Check if file attributes and file OPEN/CLOSE statement are correct
Check if input/output format matches definition in code
Check if buffer size is correct.
Check if file was opened before use and if end-of-file was handled
Check if I/O errors are handled and if there are text errors in output message
Tests for modular data structures should include
Checking for inappropriate or incompatible data type declarations
Check if variable exists without initial value
Checking whether a variable has been initialized correctly or has a default value
Checking for bad variable names (mistakes or bad truncation)
Checking for deviations
The main task of unit testing is to make sure that each path in a unit test is executed at least once
These path tests should detect errors caused by miscalculations, bad comparisons, and bad control flow
Common mistakes include
Misunderstanding or using wrong prioritheta operator
Mixed Data Operations
Invalid variable initial value
Insufficient data accuracy
Invalid expression character
Other tests include
Checking for incorrect use of logical operators or precedence
Check if they are theoretically equal but not actually equal due to computer precision errors
Checking for errors in comparison operations or variables
Check if loop termination condition is reasonable
Is there a bug that can't exit when testing iterative divergence
Check for cases where loop variable has been incorrectly changed
The following issues should be considered for error handling path
Check if output error message is hard to understand
Check if recorded error matches actual error
Checking for incorrect exception handling.
Check if error message can provide enough information about positioning error
In addition
Unit testing should also focus on maintainability of software. Modular module maintainability test to be carried out
Code structure
Modularity, code comment quality, standards compliance, understandability, documentation, etc.
In short
Unit testing makes sure that semantics of code matches our expectations
Unit test cases cannot be exactly same as test cases at other levels, such as an integration test and a configuration item test
Related
Why is it great in hotel business? What have I been through? Ctrip, Tencent, what does unit test test?
Hotel SOP is difficult to implement Why? What steps do I need to go through? let me tell you
Hotel How does Ctrip OTA work? How it works? How do OTAs work, what are rules?
What does hotel do? Business is foundation of talent ability Value enjoyed by customers
What is called Hotel Design VI How is Hotel Design VI Hotel Design Why is it important?
Ctrip. How to use pyramid reward method in hotel system. Do it well. What kind of activities would you like?
Alien hotel! Why did it appear in your circle of friends. Today's headlines. Tencent news. Etc.
Alien hotel! Why did it appear in your circle of friends. Today's headlines. Tencent news. Etc.
European hotel brand! What means did you use to enter China? Why? Did it work out in end?
What does a hotel do. There is a market with a price of 10,000 yuan. I am using AP base point to decompose it. let me tell you