Unit testing Introduction

Unit test is a test of the basic unit of software / module, also known as the test module. Base unit / module may be a function, class instance, the method, stored procedure, may be any function with a clear, defined specifications, clearly defined interfaces, and combination of its size is generally small program code module.

1 Overview

Unit testing is the basic unit of the software testing / module, also known as the test module. Base unit / module may be a function, class instance, the method, stored procedure, may be any function with a clear, defined specifications, clearly defined interfaces, and combination of its size is generally small program code module.

Unit tests focused on the design or discovery procedure implemented logic errors, make the problem early exposure to locate the solution to the problem.

Multi-unit test method combining white box and black box testing, both the target cell function, also concerned the logical structure of the program modules. The two together, can be avoided due to excessive concern path leading to a large amount of testing issues, but also avoid some paths may be lost from the external test case design problems due.

Today, more the view that unit testing should be done by coders, I believe that this view is justified. After all, the embodiment of tester unit testing more work than coder embodiment. Of course, if the test relation to aviation, aerospace, medical and other major life and property of the software system, the need to invest a lot of resources to ensure the quality of the system, you can implement strategies testers using unit testing.

Unit testing should focus primarily functional tests, while statistical test coverage, test module and the input / output interface is correct, the internal data stream is correct and the like.

The main functional testing test module has correctly implemented the design requirements of the function, as well as whether the omission of function. There is a concept of functional coverage. Because the test module may include a plurality of function points, doing tests, functional design test cases to cover these points to ensure that they function points tested. General requirements for functional coverage 100%.

General requirements for coverage of statement coverage and branch coverage, also asked to test all of the critical path. Expression of the critical path is not very clear, but if asked to do the basic path coverage test set, even a relatively small module is difficult to do. If a unit testing tools (e.g. CppUnit, Junit, etc.), may be statistical coverage.

After the unit tests, because if some branches due to various conditions can not be covered, you need to give instructions.

2, unit testing step

Unit testing program involves several steps, design, implementation, evaluation, etc., respectively, as described below.

① plan: Determine test requirements, develop test strategies, test used to determine the resources (such as personnel, equipment, etc.), create test schedule tasks. This part of the work can be simply described.

② Design: Design a unit test model, develop test programs to develop specific test cases, test scripts to create reusable.

③: Execute test cases for testing the unit modules, and the verification result of the test recording defect occurred during the test.

④ review: unit testing results of assessment. Mainly to test the completeness of assessment.

Since the cell module is often not a standalone program, designed to consider the unit modules links with other modules, the other modules associated with the module and drive module stub analog measured. The module being tested, and the pile driving module constituting the program modules can be run together.

Define drive module and said stub below.

Drive module: the test module corresponding to a main routine for receiving data or generate data, the data is transmitted to the test module, and then output the measured results, or to compare the measured results with the expected results.

Stubs: Also called a stub. To replace the sub-module is called test module. Stubs can be used for data processing, need not all functional modules are analog, you can simply return a value.

3, the contents of the test unit

1) functional tests Unit

SUMMARY functional testing unit are as follows:

  • Whether functional unit designed to achieve full points.
  • Operation of the order of priority and has been performed correctly.
  • Processing accuracy of calculation is correct.
  • Whether error in the calculation will magnify.

2) the test module interface

At the beginning of the test unit, to deal with the sensing module test data stream. If the data is not correctly input and output, it can not perform other tests.

Interface module tests may be required following outsourcing projects:

  • In the form of parameters and input parameters of the calling module when the module is matched in the measured number of attributes, order.
  • When the measured module calls a sub-module, which form the input parameters to the parameter sub-module sub-module on the number of matches, attributes, order.
  • Whether to amend the only form of input parameters.
  • Output parameters of the standard to the correct function in the number, property, sequentially.
  • Define global variables are the same in each module.
  • Whether the restriction is transmitted in the form of parameters.
  • When the external module files, database input / output, file operations must be tested. For example, the size of the buffer, whether to open the file in read and write files before the file is closed at the other end.

3) Data Flow Test

Internal data flow testing include the following:

  • Incorrect or inconsistent data type description.
  • Use a variable has not been assigned or has not been initialized.
  • The default value of the initial value of the error or errors.
  • Variable name misspellings or clerical errors.
  • Inconsistent data types.
  • Global variables have an impact on whether the module.

4) Test logical path

Logical path testing include the following:

  • It has reached an important function point path.
  • Boundary point determining logic is correct.
  • Exception / error handling.
  • When comparing the module design can improve the abnormal or expected error conditions, and set the appropriate error handling and exception handling for exceptions or errors in the program, the program can be re-arrangement of the error, the logic to ensure correctness. The focus should consider the following questions:
  • It is abnormal or wrong description understandable.
  • Exception handling is reasonable, the positioning error after error is accurate.
  • Whether an error and the actual error is consistent.
  • Handling of error conditions are correct.

Most of the above mentioned many things already included in the encoded specification or code checklist, if prior to entering the module test unit, and has a peer review examination table, the module may potentially fewer defects.

4, unit test design

Unit testing can be applied in almost all test case design method.

Unit test procedure described below.

① unit module designed to run the first test case. The first test the unit under test is generally performed using the simplest method. When using this embodiment may be performed, and the test environment can be determined are available testing unit.

② design unit test cases to be tested. Read the description, each test case is targeted by a test with a specification or more of the content, design specifications to verify whether the function corresponding to the implementation.

Test test exception handling function ③ design. Use may cause the module function failure of invalid data, test module response to invalid data is reasonable, and how to respond to treatment after abnormal or wrong module, the authentication module have not done should not do the job.

④ other test cases designed to verify the design requirements for the module. E.g. accuracy, performance, recoverability, security and the like.

⑤ load test run, you need to view and record test results, especially with the expected test results inconsistent results situation.

⑥ supplement the test cases, execute test cases to run in front of the main branch not covered and statements.

⑦ Repeat steps 1 through 6 above, until the functional coverage, covering the main logic, and other abnormal conditions and boundary coverage.

We hope to introduce unit testing, can help to bring you this article.

Published 17 original articles · won praise 2 · Views 5277

Guess you like

Origin blog.csdn.net/tiekun888/article/details/50898684