Basic methods of unit testing

Source: Internet
Author: User
Tags data structures error handling

The object of unit testing is the smallest unit of software design--the module. Unit testing is based on a detailed description, unit testing should be in the module of all the important control path design test cases, in order to find the internal error in the module. The unit test uses the White box test technique more, the system several modules may carry on the test in parallel.

Unit Test Tasks

Unit test tasks include: 1 module interface test, 2 module local data structure test, 3 module boundary condition test, 4 module all independent execution path test, 5 module error handling path test.

Module interface testing is the basis of unit testing. Only if the data can flow into and out of the module, other tests will make sense. The following factors should be considered when testing the interface correctly:

1 The actual parameters of the input are the same as the number of formal parameters;

2 The actual parameters of the input match the properties of the formal parameters;

3 The actual parameter of input is consistent with the dimension of formal parameter;

4 the number of actual parameters given to the other modules is the same as the number of parameter of the modulated module;

5 whether the properties of the actual parameters given by the other modules are matched with the parameter attributes of the modulated module;

6 the dimension of the actual parameters given to the other modules is consistent with the shape parameter of the modulated module;

7 The number, attributes, and order of parameters used when calling predefined functions are correct;

8 whether there is a parameter reference independent of the current entry point;

9 whether the read-only parameter has been modified;

10 the definition of the whole variable is consistent with each module;

11 Whether some constraints are passed as parameters.

If the module includes external input and output, you should also consider the following factors:

1 file attributes are correct;

2 Open/close statement is correct;

3 format description and input output statements are matched;

4 The buffer size matches the record length;

5 whether the file has been opened before use;

6 Whether the end of the file is processed;

7 whether the input/output error is handled;

8 whether there is a textual error in the output information;

The local data structure is checked for the purpose of ensuring that the information temporarily stored in the module is complete and correct during the execution of the program. Local data structures are often the source of errors, and test cases should be carefully designed to identify the following categories of errors:

1 inappropriate or incompatible type description;

2 variables have no initial value;

3 variable initialization or the lack of value error;

4 incorrect variable name (misspelled or incorrectly truncated);

5 There is an overflow, underflow, and address exception.

In addition to local data structures, if possible, unit tests should also identify the impact of global data, such as a Fortran public area, on the module.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.