Getting Started with Test Cases (3) - Writing Test Cases Using Boundary Value Analysis

In the book "Software Testing", the role of boundary value analysis is described in this way: If you can walk confidently and safely on the edge of a cliff without falling, flat ground will be a problem.
The demo code in this article is all written in Python

1. Overview of boundary value analysis method

  • Software can easily cause problems at the boundary. Software is very extreme, either right or wrong.
    For software, if it can run at the boundary, then there should be no problems under normal circumstances.
  • The boundary value method is also one of the commonly used methods for use cases. Its application steps are very simple:
    1. Find a boundary
    2. Test the boundary
    3. Test both sides of the boundary

2. Judgment of boundary conditions

In the application of boundary value method, the first and most critical thing is to find the boundary.

  • If you find the following keywords when reading requirements - "first time", "{number} day", "{number} page", etc., this kind of description that obviously has a quantity and a boundary should be sensitive. I feel "this is the need to use the boundary value method".

For example
, the problem of page paging that is often encountered is a very typical boundary value problem.

Assume this is a mall requirement:

  • Demand to be tested: Only 10 products are displayed on one page. When there are more than 10 products, the page displays a "next page" button.
  • Test point: If the page is larger than 10 pieces of data, only ten pieces of data will be displayed, and the "Next Page" button will be displayed.
  • The code demonstration is like this. naxt_page is a method to display the next page button, but the page will only be displayed when the incoming data_num is greater than 10:
    def naxt_page(data_num):
        # 当页面数据大于10时,展示下一页按钮
        if data_num > 10:
            print("展示下一页按钮") # 达到按钮展示条件时打印日志
    
  • Obviously, when data_num=10, it is the key point of the test. So 10 is the boundary value at this time.

3. Judgment on both sides of the border

  • Find both sides of the border. After determining the boundary, the usual approach is to simply add one unit and subtract one unit to the boundary to determine both sides of the boundary.

The example
is still based on the above example:

  • After finding the boundary value, find the values ​​on both sides of the boundary.

  • In this example, the data on the page is each product, so it can be seen that the quantities are all integers. Therefore, the data on both sides of the boundary should be 9 and 11.
    Note: If the target to be measured at this time is not the product, but the price. For example, if the price of the product reaches 10 yuan, you can use the "10 yuan off" coupon, then the boundary value The data on both sides should be 9.99 and 10.01.

  • After determining the data on both sides of the boundary, you can now write a complete use case for this test point:
    Insert image description here

  • In fact, the boundary is not necessarily a number. For example, in UI testing of buttons, the boundary value method can also be used to design test cases - during testing, if you click on the edge of the button, it will respond, if you click in the middle of the button, you will respond, if you click outside the button, it will not respond. In this way, you can test whether the program is correct when writing the click area of ​​this button.

This is the case when there is only one boundary value, but in most cases there is more than one boundary value. The way to determine the boundary value can follow the following rules:

  • Closed interval: The range is [1-10], with points 0 and 1 on the left boundary, points 10 and 11 on the right boundary, and any point between the boundaries.
  • Closed interval and open interval: the range is (1-10], take points 1 and 2 on the left boundary, take points 10 and 11 on the right boundary, and pick any point between the boundaries.
  • Open interval: the range is (1-10), take points 1 and 2 on the left boundary, take points 9 and 10 on the right boundary, and pick any point between the boundaries.

4. Sub-boundary conditions

  • Boundaries with clear values ​​are the easiest to find. They will be described in the requirements document, or they will be obvious during the use of the software (such as starting the application for the first time).
  • Some boundaries exist within the software and are almost invisible during use.
  • The problem of loss of precision of floating point numbers: The computer uses binary to store data, and the code uses decimal when performing operations. Some numbers in decimal and some decimals in decimal cannot be well represented by binary, so precision will appear during the conversion process. lost.
  • Therefore, you may encounter this bug during testing. If a product is worth 9.99 yuan and is settled together with another product worth 0.01 yuan, you cannot use the "1 off every ten" coupon.
  • The problem of floating point precision loss is a typical sub-boundary condition, which needs to be taken into consideration when designing relevant test cases.
  • When considering this type of problem, you need to have a certain knowledge base. On the one hand, you can communicate more with programmers, and on the other hand, you also need daily accumulation.

5. Special boundary conditions: default value, null value

  • While considering the obvious boundary conditions, also consider the case of null values, 0, and default values.
  • That is, when there is no data input, or when the input value is a null value, the application should have a cover-up process.
  • Although these situations may not be explicitly described in the requirements, they must be considered when designing test cases.

6. Equivalence class division method and boundary value method

  • The equivalence class division method is often used together with the boundary value method. Use boundary values ​​as conditions for equivalence class division.

The example
is still based on the paging example above.

  • In this example, for testing whether to display the "Next Page" button, when the page has a total of 1 piece of data and when the page has a total of 9 pieces of data, the two situations are equivalent, because the pages both display the corresponding 1 and 9 pieces of data, and the "next page" button is not displayed. In the same way, the same is true when there are 11 pieces of data and 12 pieces of data.
    Insert image description here

7. Finally

  • Boundary value analysis method, like equivalence class division method, is a very common design use case method, and there are many tutorials on the Internet.
  • But there are still many people who may only know these two methods, but have not studied them systematically or combined them with their work content. I hope it will be helpful to you after reading this article.

Appendix: [Test case entry series catalog]

Getting Started with Test Cases (1) - How to write a test case title, preconditions, test steps and expected results?
Getting Started with Test Cases (2) - Using Equivalence Classification to Write Test Cases
Getting Started with Test Cases (3) - Using Boundary Value Analysis to Write Test Cases
Getting Started with Test Cases (4) - Using Process Analysis and State Analysis to Write Test
Cases Getting Started with Use Cases (5) - How to Conduct Requirements Analysis
Getting Started with Test Cases (6) - Summarizing test points based on test type and granularity

—————————————————————————————————————————————————————————————————————————————————————————————————
I am a blog of myself. No. [Essential Skills for Software Testing] will upload testing related information from time to time. You can go and get it if necessary.
Insert image description here
Insert image description here
If necessary, please click on the QR code below the article to get it~
Insert image description here

Guess you like

Origin blog.csdn.net/weixin_40883833/article/details/126651900