Unit Testing Overview

Source: Internet
Author: User

Software is like a whole of a lot of parts, each part of the parts division of labor to complete the unique function. In response to this feature of the software, independent testing of the smallest functional units of the software, such as functions in a traditional program, or tests of classes in object-oriented programming, is called unit testing.

The unit test of the software has the following characteristics: (1) it refers to checking and verifying the smallest testable unit in the software. For unit testing in the meaning of the unit, in general, according to the actual situation to determine its specific meaning, such as the C language unit refers to a function, Java unit refers to a class, graphical software can refer to a window or a menu. In short, the unit is the minimum set of the measured function module. (2) Unit testing is the minimum level of test activity to be performed during the software development process, and the independent unit of the software will be tested in isolation from other parts of the program.

As can be seen from the above characteristics, the unit to different software definitions, need to separate analysis, second, unit testing, the lowest level of testing, and is independent of each. From these two features, the unit test is undoubtedly complex and cumbersome, the efficiency is very low, and the function or class between the program can not work independently, each functional unit must coordinate work to complete the software's established task. So is it not necessary to test unit tests individually for individual units?

In fact, no good programmer can guarantee that their program in the writing process without bugs, even through the compilation, but also the syntax is not a problem, as for the logic problem or design defects can not be detected in the process of compilation. And when the programmer rushed to integrate the various functional units, a variety of bugs will be the software's subsequent changes caused great interference, after all, in an incredibly large system to find an unknown where the error can be compared to a small unit to find the error is difficult to shuffling. After the unit test is complete, we can confidently deliver our own code without any worries.

How to do unit tests:

• Construction of minimum operating scheduling system, i.e. drive module (Driver), to simulate the upper module of the module under test.

• Simulate a unit interface pile (Stub), which is the interface of other cell functions to be called by the unit being measured.

• Simulate the generation of data or state to prepare a dynamic environment for unit testing.

  

Isolate test strategy

• Global input/output variable test (Driver) within the unit.

• The interface test for the function (Stub) called within the cell.

• Overlay Test (statement overlay/Branch overlay/COMPOUND predicate overlay/path overlay).

  

There are a number of principles to keep in mind in unit testing, including:

You should perform a static check before the unit test, the code of the daytime.

Unit testing of new or modified code.

The object being tested is the code that implements a set of related functions (one or a set of functions) unit tests are carried out according to the plan and scheme of the unit test, excluding the randomness of the test.

Project managers ensure that test cases are audited (brainstorming).

When test cases are inconsistent with the expected results, the executor of the unit test must record the actual test results truthfully.

When the test reaches the planned end of the standard, the unit test ends.

A certain code coverage requirement is required for the side unit to be reached.

When the program is modified, the tester performs a regression test to ensure that no new errors are introduced after the modification.

In fact, we often do unit tests. After writing a function, always execute it to see if the function is normal, which is the unit test. Of course, this unit test is temporary. Only the temporary unit testing software, the test for the code is not complete, code coverage is not high, not covered by the code may leave a large number of small errors, these errors will affect each other, when the bug exposed when difficult to debug, greatly improve the late testing and maintenance costs, but also reduce the competitiveness of developers. In other words, unit tests We do often do, but do not complete. For programmers who pursue high-quality software, unit testing is a process that must be experienced during software authoring.

  

Unit Testing Overview

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.