【Software Testing】Project testing—MySQL database operation application scenarios? Must have detailed knowledge (super detailed)


foreword

The database is basically a compulsory part of the software test interview. The most common is handwritten SQL or oral SQL. The interviewer will give you a scene, such as class, score, course, etc. Generally, there are mostly query statements in the inspection table, such as multi-table queries, join queries, subqueries, etc.

As a test, the weight of the database in daily work is still relatively large, mainly in the following application scenarios:

1. Project deployment and data preparation after deployment

The development and configuration environment is good, but there is no connection to the database, so we need to create a new database and connect it ourselves.
The database has been built, but the data table has not been created, so we need to create the data table ourselves.
The database and data table have been created, but there is no data in the data table, we need to add data ourselves.
There is data in the data table, but the amount of data is not enough. Development only provides one or two sample data, and testing requires a lot of data creation.
The background management of the project does not have a registration function, so we need to manually insert the user name and password into the data table.

2. Add, delete, modify and check on the front-end page, check whether the database has been updated accordingly, and check the accuracy of data storage

Example 1: In a CRM project, after a new customer is created, check whether it is consistent with the newly created customer information in the database table.
Example 2: The order generated by the payment transaction can be checked from the database to see whether the order is actually stored and whether the data information is consistent.

3. Directly manipulate the data to meet the extreme scenarios required by the test cases

For example, in some scenarios, such as the function of creating a new customer in a CRM project, we only need to verify the boundary value of an input box, but we need to keep creating new ones on the front-end page, submitting and saving them all the time, and every time we create a new one, we need to fill in the required items that do not need to be tested for the time being. , is too troublesome, you can directly modify the corresponding field value in the data table.

4. When performance testing or automated testing generates a large amount of data through scripts, check whether the database is effectively stored in batches

5. Optimize test cases by operating the database to improve test efficiency

6. When an error is reported in the front-end input box field, it may be that the database parameter type is set incorrectly or the field length is not enough, you can open the database to check whether the field parameter type and length are correct

7. Performance test, improve system performance by optimizing SQL statement or table structure, such as slow query, etc.

8. Create data scenarios and construct preconditions for certain use cases

Example 1: Statistical annual profit requires data from 1 to 12 months. It is impossible to measure a demand for a year, and the data can be directly inserted into the database.

Example 2: When registering a mobile phone number, re-use a mobile phone number by changing the non-unique state of the database table field for repeated registration.

Example 3: By modifying the amount, price, etc., it is used for payment testing. For example, if it originally needs 100 RMB, it can be changed to 0.01 RMB by modifying the data.

Example 4: For membership points, you can directly modify the points in the database to see if you have reached membership.

9. Understand how to operate the database through the interface

10. When doing test structure analysis, you can use the database to figure out the data flow direction, which table to put which field to display when and where
...

Only some common scenarios in daily work are listed.

Next, let's introduce the database and commonly used SQL statements.

Addition, deletion, modification and query of data table

increase (insert)

-- 插入数据
INSERT INTO user_info ( user_id, user_name, PASSWORD, user_nick, card_num )
VALUES
	( 1, 'zhangsan', 'abc123', 'zhangsanfeng', 124567894651329785 ),
	( 2, 'lisi', '122bbb', 'limochou', 124567894651324567 ),
	( 3, 'wangwu', '123aaa', 'wangbaiwan', 214567894651324567 ),
	( 4, 'liuqi', '12aaa', 'liuchuanfeng', 214563356651324567 ),
	( 5, 'zhangliu', '12aaa', 'zhangwuji', 214563356658966567 );

delete

grammar:

delete from 表名 where 条件

The delete statement cannot delete the value of a column. (You can use the update table name set username = "" where userid = 1)
Use the delete statement to delete only the data of the row that meets the where condition, without deleting other rows in the table and the table itself.
truncate user_info_table (clear the data directly)

The difference between drop and delete:
drop is to delete a column in a database, data table, or data table.
delete is to delete a row of data.

change (update)

grammar:

update [表名] set [列名]=[新值] where [列名]=[某值];

The update syntax can add and update columns in the original table row.
The set clause indicates which columns to modify and which values ​​to give.
The where clause specifies which rows should be updated. If there is no where clause, all rows are updated.

check (select)

Example 1:
The following table is available

Please add a picture description

where child clause

-- 1. 满足价格大于等于9的所有信息
SELECT * FROM order_info WHERE price >= 9;

-- 2. 查找满足product_id在1002和1003之间的
SELECT * FROM order_info WHERE product_id BETWEEN 1002 AND 1003;

-- 3. 查找user_id在1、3、5这三个数内的信息
SELECT * FROM order_info WHERE user_id IN (1,3,5);

-- 4. 查找订单状态是已支付的信息
SELECT * FROM order_info WHERE order_status = 'pay';

-- 5. 查找用户名类似于已li开头的信息
SELECT * FROM user_info WHERE user_name LIKE 'li%';

-- 6. 查找用户名中第二个字母是h的信息
SELECT * FROM user_info WHERE user_name LIKE '_h%';

-- 7. 查找用户名中第二个字母不是h的信息
SELECT * FROM user_info WHERE user_name NOT LIKE '_h%';

-- 8. 查找用户名中最后一个字母以i结尾的信息
SELECT * FROM user_info WHERE user_name LIKE '%i';

-- 9. 查找价格大于8,并且订单状态是已支付的所有信息
SELECT * FROM order_info WHERE price > 8 AND order_status = 'pay';

-- 10.查找用户表中user_nick为null的信息
SELECT * FROM user_info WHERE user_nick IS NULL;

-- 11.查找用户表中user_nick为 not null的信息
SELECT * FROM user_info WHERE user_nick IS NOT NULL;

aggregate function

-- 1. 查找订单表中最大的价格,查找订单表中最小的价格
SELECT MAX(price),MIN(price) FROM order_info;

-- 2. 查找订单表中user_id=2的最小价格
SELECT MIN(price) FROM order_info WHERE user_id = 2;

-- 3. 分别列出订单表中user_id=2的最小价格和最大价格
SELECT MIN(price),MAX(price) FROM order_info WHERE user_id = 2;

-- 4. 分别列出订单表中user_id=2的最小价格和最大价格,并把最小价格的展示结果的列名改为"min_price"
SELECT MIN(price) AS min_price,MAX(price) FROM order_info WHERE user_id = 2;

-- 5. 求订单表的价格的平均值,求订单表中user_id=2的价格的平均值
SELECT AVG(price) FROM order_info;
SELECT AVG(price) FROM order_info WHERE user_id = 2;

-- 6. 分别列出订单表中user_id=2的价格的平均值、最小值、最大值
SELECT AVG(price),MIN(price),MAX(price) FROM order_info WHERE user_id = 2;

-- 7. 求订单表中user_id=1的价格的总和
SELECT SUM(price) FROM order_info WHERE user_id = 1;

-- 8. 求订单表中user_id=1或者user_id=3的价格总和
SELECT SUM(price) FROM order_info WHERE user_id = 1 OR user_id = 3;

group

-- 1.首先筛选状态为已支付的订单,然后按照user_id分组,分组后每一组对支付金额进行求和,最终展示user_id和对应组求和金额
SELECT user_id,SUM(price) FROM order_info WHERE order_status = 'pay' GROUP BY user_id;

-- 2.首先筛选状态为支付的订单,然后按照user_id分组,分组后每一组对支付金额进行求和,再过滤求和金额大于10的,最终展示user_id和对应组的求和金额
SELECT user_id,SUM(price) FROM order_info WHERE order_status = 'pay' GROUP BY user_id HAVING SUM(price) > 10;

Data table join query and subquery

-- 1.查询订单表中的价格大于10元的用户的昵称(小提示:用户昵称在用户表中,订单价格在订单表中)
SELECT a.user_nick FROM user_info a INNER JOIN order_info b ON a.user_id = b.user_id WHERE b.price > 10;
SELECT user_nick FROM user_info WHERE user_id IN (SELECT user_id FROM order_info WHERE price > 10);

-- 2.查询用户名以l开头的用户买过的所有订单id和对应价格(小提示:订单id和对应价格在订单表中,用户名在用户表中)
SELECT o.order_id,o.price FROM order_info o WHERE o.user_id IN (SELECT user_id FROM user_info u WHERE u.user_name LIKE 'l%');

Example 2:
There are 2 tables below

Please add a picture description

Please add a picture description

-- 1.修改供应商id为4的供应商名称为‘hongshuangxi’
UPDATE suppliers_info SET supplier_name = 'hongshuangxi' WHERE supplier_id = 4;

-- 2.查询商品重量大于0.10的商品的名称
SELECT product_name FROM products_info WHERE weight > 0.10;

-- 3.查询商品名称以字母p开头的商品的所有信息
SELECT * FROM products_info WHERE product_name like 'p%';

-- 4.查询商品重量大于0.10,小于0.20的商品名称
SELECT product_name FROM products_info WHERE weight > 0.10 AND weight < 0.20;

-- 5.按照商品分类统计各自的商品总个数,显示每个分类和其对应的商品总个数
SELECT classification,COUNT(classification) FROM products_info GROUP BY classification;

-- 6.将所有商品的名称按照商品重量由高到低显示
SELECT product_name,weight FROM products_info ORDER BY weight DESC;

-- 7.显示所有商品的信息,在右边显示有供应商的商品对应的供应商信息
SELECT * FROM products_info a LEFT JOIN suppliers_info b ON a.supplier_id = b.supplier_id;

-- 8.显示重量大于等于0.15的商品的供应商的联系人和手机号
SELECT s.contacts,s.contacts_phone_num FROM suppliers_info s INNER JOIN products_info p ON s.supplier_id = p.supplier_id and p.weight >= 0.15;
The following is the most complete software test engineer learning knowledge architecture system diagram in 2023 that I compiled

1. From entry to mastery of Python programming

Please add a picture description

2. Interface automation project actual combat

Please add a picture description

3. Actual Combat of Web Automation Project

Please add a picture description

4. Actual Combat of App Automation Project

Please add a picture description

5. Resume of first-tier manufacturers

Please add a picture description

6. Test and develop DevOps system

Please add a picture description

7. Commonly used automated testing tools

Please add a picture description

Eight, JMeter performance test

Please add a picture description

9. Summary (little surprise at the end)

Every effort will not be in vain, and every contribution is worth cherishing. Persist in the struggle, believe in yourself, success is waiting for you ahead. As long as you are willing to pursue, happiness will beckon to you.

Everyone's destiny is in their own hands, as long as they have dreams, courage, and actions, they can welcome the dawn of success. Although there will be mud and thorns on the road of life, as long as you have firm faith, you will be able to overcome difficulties!

The road to success is not smooth, but only with hard work and unremitting efforts can we go further and higher. Don't be afraid of failure, believe in yourself, go forward bravely, and you will surely reap the joy of success!

Guess you like

Origin blog.csdn.net/shuang_waiwai/article/details/130427112