How to do unit test well

Source: Internet
Author: User

Objective

Unit test is the test of the basic component unit of software, it belongs to the category of white box test, it mainly analyzes the logic structure of the code to design the test case. In dynamic testing, unit testing is a very efficient test method, and is the first test in the software testing cycle. From the cost point of view, the sooner the defect detection, the stronger unit test to reduce the defect location and repair difficulties, thereby reducing the cost of defect resolution, while strengthening unit testing also reduces the subsequent integration testing and system testing burden. According to industry statistics, a BUG in the unit testing phase found that the cost is 1, to the integration test will become 10, to the system test up to 100, to the actual market after the birth of up to 1000. However, unit testing is not well developed in domestic software enterprises, on the one hand, due to the lack of attention to unit testing, the lack of input, on the other hand, the unit testing practice has not accumulated enough, unit testing in a groping state.

The quality of the software is determined by the three dimensions of organization, process, and technology, and no single dimension can determine the quality of the software alone. Good organization structure can guarantee the smooth implementation of the process, good process can improve the standardization and controllability of software development, so as to improve the efficiency and quality of software development, and the use of good technology and the carrier of good technology-people, then fundamentally guarantee the quality of software.

In a word, organization, process and technology are the triangle of software quality, this article will discuss how to do the unit test from these three aspects.

Organizational structure should ensure that test groups participate in unit testing

At present, both industry and academia believe that unit testing should be carried out by developers, this is because from the unit test process, the unit test generally uses the White box test method, can not be separated from the in-depth testing of the object code, but also need to construct the driving module, pile function, so carry out unit testing needs better development knowledge. From the knowledge structure of the personnel and the familiarity of the code, the developer has some advantages.

Unit testing is carried out by developers to bring some special benefits. As we know, in practice, a developer conducting unit tests typically recommends a cross test method, such as a test of the unit by the caller of the unit being measured, which avoids unit testing of its own code. This crossover test arrangement avoids the fact that the test is too much affected by the development idea, that it is not easy to identify the problems created during the development process, and that it is advantageous for the organization to achieve a technical backup or full communication. Even if the method of cross test is not adopted, and the producer of the arrangement unit carries out unit test, it has great superiority, its biggest advantage is fast, and can better realize "prevent error". This kind of self test arrangement is also a good choice in the case of staff stress.

From the empirical point of view, Unit test input and coding input is basically 1:1, if the full-time Test team to carry out unit testing, it is obviously not appropriate to maintain such a large single task force.

The above is about the advantages of unit testing by developers, which is mainly considered from the efficiency of unit testing. However, from the perspective of unit test effects, it is necessary to ensure that the test group participates in unit tests from the organizational structure, because:

Firstly, from the current situation of domestic enterprises, the quality consciousness of testers is higher than that of the developers, and the testers can improve the quality of the test by participating in unit Test.

Second, the more you know about the system being tested, the deeper the test will be, the more the tester participates in unit testing, and the ability of testers to familiarize themselves with the tested system from the code level, which is very helpful to the test group's later integration and system testing activities, and will greatly improve the quality of integration and system testing

The way in which the test group participates in unit testing should be based on the actual situation of the software organization. If the software organization tests resources adequately, the ratio of testers to developers is high, so the tester can bear the unit test work of some important modules independently, and if the test resource is low, the tester's ratio to the developer is lower, then the unit Test Plan and unit test design can be done by the tester. While the implementation and execution of unit tests is done by developers, and if the test resources are scarce, even unit test plans, unit test design can not afford, then the test group should at least participate in the development Group of the relevant unit test documents, Unit Test Report Review, to ensure the quality of unit testing.

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.