Main Problems and Solutions of unit test practices (1)

Source: Internet
Author: User
This article is my speech at the "China system and software process improvement Annual Meeting in Guangdong". It mainly shares some key points of unit testing and main issues of unit testing practices, and how to solve these problems.

 

I. unit test Overview

 

1.1 What is Unit Testing

Unit testing is an independent test of code units. Why is unit testing required? This is determined by the basic features of the Code. A basic feature of code is data classification.

The Code usually has many judgments. A decision is a classification. Nested determination doubles the number of categories.

If a class is missing during code writing, a bug is generated. If a class is not correctly handled even though the code is written, a bug is also generated. To ensure that a function has no errors, you must perform the following two steps: 1. Data Classification must be complete; 2. Processing of each category must be correct. By doing so, we can say that the functional logic of the Code is correct.

So how can we check whether the functional logic of the Code is correct?

Debugging is temporary and incomplete. For example, a function has ten input types, and debugging can cover five or six types. System tests do not target a specific function, but do not focus on whether the functional logic of a function is correct.

To detect the functional logic of a function, you must list data by category, check whether the code processes each category, and whether the processing of each category is correct.

-- This is unit test.

 

1.2 Basic Unit Test Methods

From the above analysis, we can see that the basic method of unit test is to list the input according to the data type, execute the tested program, and then determine whether the output meets expectations.

What results can unit tests achieve? That is: no matter what other people like, I am always right!

Here "Others" refers to associated code. "I" refers to the code that is currently being written or tested. The unit test must ensure that I am right, no matter whether the associated code is wrong or not. Specifically, I want to consider what kind of data will be produced by the associated code and how the data will be classified and processed. As long as my classification and processing are correct, no matter what other people do, I am always right.

 

 

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.