Classic methods of software test cases|Logic coverage testing method and cases [book at the end of the article]

picture

Logical coverage testing is a commonly used white-box testing method, which is based on the internal logic structure of the program, and realizes the coverage of the program test by traversing the logical structure of the program. Logic coverage testing requires testers to have a clear understanding of the logical structure of the program.

The logic coverage test method is a general term for a series of test processes, and it is a path test that gradually makes the test process more and more complete. From the detailed degree of coverage of source program statements, it can be divided into statement coverage, decision coverage, condition coverage, judgment/condition coverage, condition combination coverage and path coverage. Next, these coverage criteria will be introduced one by one through the logic coverage test cases of the following program. The flow chart of the program is shown in Figure 1, where a, b, c, d, and e are several program points on the control flow.

main()
{
int a,b;
float x;
scanf("%d,%d,%f",&a, &b, &x);
if((a>1)and(b = 0))
x = x/a;
if((a = 2)or(x>1))
x= x+1
prinf("x=%f",x);
}        

picture

■ Figure 1 program flow chart

01. Comprehensive case of logic coverage test

A comprehensive application of relevant test methods is carried out through a case, that is, the logic coverage test case of the following program is designed.

void DoWork(int x,int y,int z)
{
int k=0,j=0;
if((x > 3)&&(z < 10))
{
k = x*y-1;
j = sqrt(k);
}//语句块1
if((x == 4)||(y> 5))
{
j= x*y+10;};
}//语句块 2
j= j%3;//语句块 3
}

 Figure 2 shows the flow chart of this example, where a, b, c, d and e are some program points on the control flow.

picture

 

■ Figure 2 program flow chart

1. Statement coverage

To test the DoWork function, you only need to design a test case to cover all executable statements in the program. The path of program execution is abd. The specific test case input is as follows.

{x=4 y=5 z=5}

Analysis: Statement coverage can ensure that every statement in the program is executed, but it cannot find errors in logical operations in the judgment, that is, it is not a sufficient inspection method. For example, in the first judgment (x>3)&&(z<10), "&&" is wrongly written as "||", and the test case is still used at this time, then the program will still follow the path abd on the flow chart execution, which again shows that statement coverage is the weakest logic coverage criterion.

2. Decision coverage

In order to realize the decision coverage of the DoWork function, two test cases need to be designed. The execution paths of the program are abd and ace respectively. The input of the corresponding test case is:

{x=4 y=5 z=5};{x=2 y=5 z=5}

Analysis: The above two test cases not only satisfy decision coverage, but also achieve statement coverage. From this point of view, it seems that the decision coverage is stronger than the statement coverage, but it still cannot determine the error of the internal condition of the decision. For example, if the condition y>5 in the second judgment is wrongly written as y<5, and then use the above test case, it can still be executed according to the original path without affecting the result. Therefore, stronger logic coverage criteria are needed to check the conditions within the decision.

3. Condition coverage

A decision usually includes several conditions. The purpose of condition coverage is to design several test cases, after executing the program under test, so that the possible values ​​of each condition in each decision are satisfied at least once.

Mark the values ​​of various conditions for each judgment of the DoWork function.

(1) For the first decision (x>3&&z<10):

The condition x>3 takes the true value as t1, and the false value as -t1;

If the condition z<10 is true, it is recorded as t2, and if it is false, it is recorded as -t2.

(2) For the second decision (x==4||y>5):

The condition x==4 takes the true value as t3, and the false value as -t3;

If the condition y>5 is true, it is recorded as t4, and if it is false, it is recorded as -t4.

According to the basic idea of ​​conditional coverage, the 8 situations that may arise from the above 4 conditions should be satisfied at least once, and the design test examples are shown in Table 1.

■ Table 1 Condition coverage test cases

picture

Analysis:  The group of test cases in Table 4-6 not only covers all 8 cases of the 4 conditions, but also covers the 4 branches b, c, d, and e of the two judgments at the same time, that is, the condition coverage is achieved at the same time and decision coverage.

Although the previous group of test cases achieved conditional coverage and decision coverage at the same time, it does not mean that conditional coverage can satisfy decision coverage. If the group of test cases in Table 2 is designed, although it satisfies the conditional coverage, it only covers the false-taking branch c of the first decision and the true-taking branch d of the second decision in the program, and cannot satisfy Determine coverage requirements.

 ■ Table 2 Another set of conditional coverage test cases

picture

4. Judgment/Condition Override

According to the basic idea of ​​decision/condition coverage, only two test cases as shown in Table 3 can be designed to cover 8 values ​​of 4 conditions and 4 decision branches.

■ Table 3 Decision/Condition Coverage Test Cases

picture

Analysis:  On the surface, the judgment/condition covers the value of all conditions in each judgment, but in fact, when the compiler checks a logical expression containing multiple conditions, some conditions in some cases will be masked by other conditions. For example, for the first judgment (x>3)&&(z<10), the two conditions of x>3 and z<10 must be satisfied simultaneously to determine that the judgment is true. If x>3 is false, the compiler will no longer check the condition of z<10, so even if this condition is wrong, it cannot be found. For the second judgment (x==4)||(y>5), if the condition x==4 is satisfied, the compiler will consider the judgment to be true, and will not check y>5 again , then the error in this condition cannot be found either. Therefore, decision/condition coverage may not be able to completely check out errors in logical expressions.

5. Condition combination coverage

Mark the condition value combination of each judgment in the DoWork function.

(1) x>3, z<10 are recorded as t1, t2, which is the true branch of the first decision.

(2) x>3, z≥10 are recorded as t1, -t2, that is, the false branch of the first decision.

(3) x≤3, z<10 are recorded as -t1, t2, which is the false branch of the first decision.

(4) x≤3, z≥10 are recorded as -t1, -t2, that is, the false branch of the first decision.

(5) x==4, y>5 is recorded as t3, t4, which is the true branch of the second decision.

(6) x==4, y≤5 are recorded as t3, -t4, which is the true branch of the second decision.

(7) x≠4, y>5 is recorded as -t3, t4, which is the true branch of the second decision.

(8) x≠4, y<=5 are recorded as -t3, -t4, that is, the false branch of the second judgment.

According to the basic idea of ​​combined coverage, the design and test cases above can be obtained as shown in Table 4.

■ Table 4 Condition combination coverage test cases

picture

Analysis: This group of test cases in Table 4 covers all combinations of 8 conditional values, and also covers all the true and false branches of the judgment, but a path abe is lost.

6. Path coverage

According to the basic idea of ​​path coverage, path coverage can be achieved by modifying the third test case in the test case that meets the combined coverage test, as shown in Table 5.

■ Table 5 Path coverage test cases

picture

Analysis:  Although the previous group of test cases satisfies the path coverage, it does not cover all the conditional combinations in the program (combinations 3 and 7 are lost), that is, the test cases that satisfy the path coverage do not necessarily meet the conditional combination coverage.

02. Give a book at the end of the article

I. Introduction

At present, rich and colorful Internet applications such as information, social networking, games, consumption, and travel have penetrated into all aspects of people's lives and work, and are profoundly changing the information age. With the growth of user scale and the increase of application complexity, the technical challenges faced by the server are becoming more and more severe. In leading Internet companies, the responsibilities of server development positions are no longer limited to simply arranging "addition, deletion, modification and query" services around the database, but require engineers to have business analysis, architecture design, code writing, technical research, teamwork, and system maintenance. and other comprehensive capabilities. In many cases, before the first line of code on the server is written, engineers have to deal with personnel such as products, operations, and legal affairs, and technical systems such as networks, middleware, operating systems, data, algorithms, operation and maintenance, and security.

2. In the AI ​​era, server development faces new challenges

On November 30, 2022, OpenAI released a chat robot program called ChatGPT, which immediately detonated the Internet and caused huge repercussions around the world. Immediately afterwards, various large language models have sprung up like mushrooms after rain. Abroad such as Google's Bard, Anthropic's Claude, domestic such as Baidu Wenxin Yiyan, Ali Tongyi Qianwen, Xunfei Xinghuo Cognitive Model, Kunlun Wanwei Tiangong Large Model, etc.

Compared with the previous model, the large model represented by ChatGPT has made a qualitative leap in code generation and code interpretation capabilities. Some qualified people have begun to use AI to write, optimize code and assist in problem solving. AI technology has greatly shortened the path to mastering knowledge. Some knowledge points that originally required reading many books and reading many columns can be quickly mastered with the help of AI tools. Some seemingly uncomplicated codes may take half an hour to write by yourself, but AI may only take a minute or two to produce, and the quality is often higher. With the blessing of AI, some junior engineers with little programming experience can also "write" relatively excellent code.

Today, we should be soberly aware that the AI ​​era will definitely bring profound changes to the production and life of human society. Although the current large model still has many shortcomings, such as hallucinations and weak reasoning ability, its potential cannot be underestimated. In the age of AI, it is inevitable that simple and repetitive tasks will be replaced by AI. In the near future, AI is fully expected to replace some low-level (such as only CRUD) programmers. In view of this, in the new era, we need to re-examine the connotation of core competitiveness, continue to learn, and constantly consolidate our own ability moat.

picture

3. Will server-side development be replaced by AI?

Large-scale software systems often have high complexity in themselves. We can simply divide complexity into two dimensions: business and technology. For systems with high business complexity, scientific and effective requirement analysis and domain modeling must be carried out to obtain a sustainable evolutionary application architecture while meeting current functional requirements; for distributed systems with high technical complexity, full Only by considering non-functional issues such as high concurrency, high availability, high performance, and data consistency can we seek the optimal solution for technical architecture in design trade-offs. Fortunately, AI is currently unable to cope with the above two types of complexity.

In addition, although the large model has the ability to generate code, interpret code and even optimize code, it still stays in the "function/method" dimension, and cannot generate code in the class dimension, module dimension, and project dimension well. At the same time, the generated code still needs human review, optimization, deployment, and verification. For complex tasks, it is also necessary to manually disassemble it into a granularity that the large model can "understand".

Furthermore, even if factors such as data security and self-developed model costs are not considered, in terms of the server-side R&D process alone, coding is only a part of the entire software life cycle, and software development also includes requirements analysis, abstract modeling, system design, data Design, non-functional design, testing, operation and maintenance, etc. In many cases, it is not difficult to write code as the ultimate technical means to solve problems, but the difficulty lies in the identification, understanding, definition and abstraction of problems, which all rely on manual deduction. When a problem is clarified and dismantled into the dimensions of a software project, faced with definite tasks, clear goals, and a reasonable structure, there will be many people who can solve the problem, and AI will naturally come into play.

picture

4. Systematize knowledge and build core competitiveness

For server development positions, it is fundamental and important to master a mainstream programming language and be familiar with commonly used middleware and databases, but it is far from core competitiveness. Only when knowledge forms a system can it be called the real core competitiveness.

So, what is included in the knowledge system of server-side development? From the perspective of the process of server-side development, which covers requirements analysis, abstract modeling, system design, data design, and non-functional design, we need to master relevant technologies and methods. From the perspective of the difficulties in server-side development in the Internet industry, we need to master corresponding solutions to problems such as high concurrency, high availability, high performance, caching, idempotence, and data consistency.

With such a huge knowledge system, how to learn efficiently? Imagine, why do you have a special understanding of the neighborhood where your home is located, and if you put yourself in a corner, you can slowly find out? The reason is that you have already formed an overall big picture of the surrounding area in your mind, and you know the key nodes clearly. If you are placed in an unfamiliar community, you may be confused. You don’t have any key nodes or the overall big picture, and you can fumble around. Even if you figure out the situation of every sewer manhole cover you see on the way, it’s meaningless. , You will forget after a few streets.

Going back to the questions raised above, the key to efficient learning and systematization of knowledge lies in: building an overall big picture at the macro level and in-depth understanding of key knowledge points. These key points are the skeleton and fulcrum of this field. Without a skeleton and fulcrum, it is naturally difficult to systematize, and without a macro picture, it is easy to go astray.

5. The industry's first book on systematic and panoramic interpretation of server-side development

 

The book "Server Development: Technology, Methods and Practical Solutions" is based on the high-quality internal training courses of Ali and Ant Group. Written by Blogging Experts. The book combines theory with practice, and expounds server-side development in a panoramic and systematic manner. The core content includes the following two parts.

  • Part 1: Technologies and Methods of Server-side Development

First introduce the responsibilities, technology stack, core process and advanced path of server development; then expand from five aspects: requirement analysis, abstract modeling, system design, data design and non-functional design, and explain server development in depth with cases It presents readers with a panorama of server-side development and helps readers quickly and systematically grasp the knowledge and methods of server-side development.

  • Part II: Solutions to typical server-side problems

For typical problems in server-side development practices such as high concurrency, high performance, high availability, caching, data consistency, idempotence, and seckill, the corresponding solutions and development specifications are given, and different solutions are analyzed in depth with cases advantages and disadvantages. In addition, it also summarizes industry cases and norms at the landing level such as interface design, log printing, exception handling, code writing, and code comments.

Readers

  • IT practitioners: server development engineers, client development engineers, product managers, test development engineers, etc.

  • College students: students majoring in computer, software, automation, electrical, communication, etc. who are interested in entering the IT industry.

    picture

     

 

 

 

 

 

Guess you like

Origin blog.csdn.net/qq_41640218/article/details/132537203