当前位置:网站首页>Interface test mock practice (II) | complete batch manual mock in combination with JQ
Interface test mock practice (II) | complete batch manual mock in combination with JQ
2022-04-22 21:55:00 【Hua Weiyun】
Because the content of this chapter is to use jq Complete with tools , Therefore, I will spend some space on the introduction at the beginning jq Machine use , If the reader is already familiar with it jq, You can just skip this part .
Let's look at the application scenario first ,App There are often some list pages for information display , For example, the merchant's dishes 、 Stock companies 、 List display of articles, etc , Like the following :
If the food is not enough ~ No , The number of dishes is small, not enough to test , If we want to test hundreds of dishes , Will it affect the performance when brushing , Whether the display is normal , Boundary value test shown in the list, etc ;
And to measure, there must be data display , At this time, it is a little troublesome to find or create so much data through the back end , In fact, the test point of our test is to test the display and performance of the front-end page , As long as this part of the data is available , It doesn't matter whether the data is actually obtained from the database .
This time you can use mock The means of , Generate equivalence classes for this kind of big data , So that the front end can get this kind of data , and Charles It is we who realize manual mock One of the sharp tools for testing !
The customary , Look at the official website first jq The explanation of :
jq Official website address :https://stedolan.github.io/jq/
Lightweight and flexible Json Processing the command line .
purpose
Speaking of this, some people have a feeling that it can be used for something , Why handmade mock To use jq 了 ? you 're right ! It is used to handle the returned by the interface json Data to achieve mock The effect of .
- Mac:Mac It's as simple as ever ( sweet ~), installed Homebrew If so, an order brew install jq that will do
- Other systems :jq Our official website is very considerate , The download methods of each system and the links of relevant download tools are given , Please check the official website for details , Links are as follows
- Basic filtration .
Simply put, it is output as is :
- Object filtering .key、.key1.key2、.["key"]
- Index filtering .key[index]、.key[ startIndex: endIndex]
.key[index]
.key[ startIndex: endIndex]
- Object building {} 、[]
If one of the expressions has more than one result , Then the output will also produce multiple results
If key It doesn't exist ,value Will be assigned as null
If you put parentheses around the key, it means that it will be evaluated as an expression .
- Other common uses :
Calculation
To obtain the length of the
- Array operations
jq For arrays, there can be Union (’+’) And subtraction (’-’) The operation of :
Combine ('+'): There are arrays a,b; a+b You'll get one that contains all a,b New array of array elements :
Difference set ('-'): There are arrays a,b; a-b You'll get one that contains only a Medium element , It doesn't contain b New array of elements in :
- More usage
For more usage, please refer to the official website :
https://stedolan.github.io/jq/manual/#Basicfilters
As shown in the following figure, the popular science recommendation column has 2 A popular science article , Now I want to mock Dozens or even hundreds of articles or advertisements .
- Grab the response of the interface json The message is as follows :
- We store the data in json In file , And then assign it to a variable
- And then we use jq Yes pageList The list in += operation , Complete a double growth , Pass the result to the variable mockData.
According to the above method , Each time the number of elements in the list doubles , Operation n The next time it becomes 2 Of n Times the power , The speed of exponential growth needless to say ~
In this way, after getting the data according to their own needs, the new data will be stored in json file , The most important data preparation process is completed :
Said so much “ crap ”, Finally, it's the protagonist , In fact, the data is ready , The use of tools is still very simple ,Charles There's one called Map Local The function of , When you want to mock Right click on your request to find :
Map Local You can replace the specified interface return with a local file , For example, replace here with the data file generated in the above nonsense for half a day MockTest.json:
Then refresh the page again , Look at the effect , The list of pages doubles as desired , You don't have to add data to the database , Keep a journal of json Files can be tested and used immediately :
above , Look forward to your communication , A lot of correct .
【 Related articles 】
- be based on Charles Interface test of agent technology Mock actual combat ( One )
- Interface test strategy and problem analysis model
版权声明
本文为[Hua Weiyun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221611471761.html
边栏推荐
- 8.1 sequence model
- The tree structure on the left side of the idea tool is not displayed
- What should web testing pay attention to?
- Collect excellent blog articles
- 摆脱 AI 生产“小作坊”:如何基于 Kubernetes 构建云原生 AI 平台
- Enterprise appraisers build a decision support platform for the government
- 难以置信!网易首席架构师竟用了500页笔记,把网络协议给趣谈了
- glib 和 glibc
- 在线YAML转XML工具
- Solving chrome cross domain problems - cross domain series
猜你喜欢

Pytoch note57 pytoch visual network structure

实验3

Online yaml to XML tool

unbelievable! The chief architect of Netease used 500 pages of notes to talk about the network protocol
![[browser] the translation provided by Google browser is invalid](/img/12/b6213c9c8bf097d4260461535a1329.png)
[browser] the translation provided by Google browser is invalid

Oplg: new generation cloud primary observable best practices

ES6 reflect object

Several innovative economic models of platefarm have inspired the current meta universe market

Function and principle of join in thread
Browser HTTP cache related knowledge
随机推荐
Why do we need to do enterprise growth evaluation and analysis?
Online yaml to XML tool
Microsoft's software engineering life cycle
知识图谱可视化技术在美团的实践与探索
未来源码 | 吴恩达教授重磅演讲:Tips for using a data-centric AI approach
[IPTV] Huawei Yuehe ec6108v9a brush machine
Glib and glibc
80386 compilation_ Introduction to register & addressing mode
How to turn off Lenovo antivirus plus
glib 和 glibc
go每日新闻(2021-03-28)——Golang 语言中的非类型安全指针
MySQL deadlock analysis and solution caused by index merging!
Test life | less than 2 years after graduation, 0 experience and won the 30W annual salary of a well-known Internet enterprise. How did he do it?
项目经理值得一试的思维方式:项目成功方程式
Noise problem at the end of alsa playback
改善C#程序的建议4:C#中标准Dispose模式的实现
Spark-2.4.2 compilation and installation
ES6 reflect object
ES6 object extension chain judgment operator and null judgment operator
Hostapd create 5g hotspot