Test Case Design

Source: Internet
Author: User

The importance and necessity of the test, as well as the test category, have been mentioned in the previous article. This article will not repeat it, but will go directly to the test case design issue.

The context of this article is as follows:

Black box testing

Boundary Value Analysis

From long-term test experience, we can find that most errors occur on the boundary of the input and output ranges. Therefore, when designing test cases, the basic idea is to select a value equal to, just greater than, or just less than the boundary value as the test data.Minimum, slightly higher than minimum, normal, slightly lower than maximum, maximumSelect the input value. For the following convenient expressions, we use min, min +, nom, Max-, and Max respectively.

Why are these points selected? The boundary value is based on the single defect hypothesis,That is, the failure is rarely caused by multiple defects at the same time.Therefore, Boundary Value Analysis: You can obtain the test case by making a variable take the extreme value and other variables take the normal value.

For example, a function has this branch.

If(2≤x≤8||25≤y≤69){//……}

Using the Boundary Value Analysis method design, we can obtain test cases: {(6, 25), (6, 26), (6, 40), (6, 68), (6, 69), and (2, 40 ), (), (), ()} {(xnom, ymin), (xnom, ymin +) (xnom, ynom), (xnom, Ymax -), (xnom, Ymax) and (xmin, ynom), (xmin +, ynom), (xmax-, ynom), (xmax, ynom )}

The worst case test of the N variable function will generate a 4N + 1 test case.

Division of equivalence classes

Using this method to design test cases is divided into two steps: one is to divide equivalence classes based on conditions, and the other is to design test cases based on the divided equivalence classes.

Valid equivalence classes are divided into valid equivalence classes and invalid equivalence classes. Valid equivalence classes refer to input sets that are reasonable and meaningful to the program. Invalid equivalence classes refer to input sets that are unreasonable and meaningless to the program. For example, if condition 6 ≤ A ≤ 10, then {6, 7, 8, 9, 10}Valid equivalence class. Values smaller than 6 and greater than 10 are invalid equivalence classes.

The principle of case design is to allow cases to overwrite valid and invalid equivalence classes as much as possible until the valid and invalid equivalence classes are overwritten.

White box testing

Take the following program as an Example

            public voidTest(int A, int B,int X)               {            if (A>1&& B == 0)            {                X = X / A;            }            if (A == 2 ||X > 1)            {                X = X + 1;            }           Console.WriteLine("A:{0}\nB:{1}\nX:{2}",A,B,X);               }

Flowchart

T and F indicate the logical judgment result, and A, B, C, D, and E indicate the execution path.

Statement Overwrite

Statement overwrite is used to design several use cases and run the program so that each executable task can be executed once. For the design of overwriting test cases with statements, [, 4] [, 4] can be used, that is, a → B → e can overwrite all executable statements. The disadvantage of statement overwrite is that it is slow to control the structure and logic operations. For example, if a loop statement is executed once, this code segment is overwritten, but it obviously cannot reflect the results after all loops; statements that overwrite test cases cannot differentiate consecutive switch statements.Statement overwrite is the weakest overwrite.

Overwrite Determination

Decision coverage is to design several test cases so that each branch of each decision in the program can be executed at least once. Design of test cases with decision coverage: [(, 4), (, 3)] A → C → e, [(, 1), (, 1)] A → B → D, each branch of each decision can be overwritten once. The simplicity of decision overwrite with statement overwrite and the problem of statement overwrite are overcome,However,BooleanValue.

Conditional coverage

Conditional coverage is to design several test cases so that the possible values of each criterion can be obtained once. There are four conditions in total: A> 1 is the first condition. If a> 1, Take T1; otherwise, F1; B = 0 is the second condition, if B = 0, take T2; otherwise, it is F2 ...... Design of a test case that uses conditional coverage: [(, 3), (, 4)] coverage condition f1t2f3t4, path: A → B → e and [(, 1 ), (, 2)] if the coverage condition is t1f2t3f4 and the path is a → B → e, the true and false of each condition can be overwritten.

Decision/condition override

It refers to the design of enough multi-use cases, so that all values of each condition are executed at least once, and each judgment may have a value at least once. Design a test case that uses the criterion/condition to overwrite: [(2, 0, 4), (2, 0, 3)], path is a → C → e, and coverage is t1t2t3t3, H and [(111), (111)]. The path is a → B → D, and the coverage condition is f1f2f3f4. The condition coverage not only satisfies the condition coverage, but also satisfies the condition coverage.

Condition combination coverage

It refers to the design case, so that all the condition values of each judgment can be combined at least once. Test Case Design for conditional combination coverage: [(, 4), (, 3)] coverage conditions t1t2t3t4, [(, 1), (, 2)] coverage conditions: t1f2t3f4, [(, 3), (, 4)] coverage conditions: f1t2f3t4, [(, 1), (, 1)] coverage conditions: f1f2f3f4.

Path Overwrite

It refers to the design case, covering all possible paths in the program. There are four paths: A → C → e, A → B → D, A → B → e, A → C → D. The advantage of path coverage is that you can thoroughly test the program segment, but there are also disadvantages: first, the path increases exponentially with the increase of the branch, with 10 if statements, there are 2 ^ 10 test paths. Second, there may be relationships between conditions in multiple judgment statements, so many paths may be redundant.

In fact, the most important thing is to grasp the several principles of the test and understand those principles. These are just the extension and instantiation of the Principles.

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.