当前位置:网站首页>Apifox (postman + swagger + mock + JMeter), an artifact of full stack development and efficiency improvement

Apifox (postman + swagger + mock + JMeter), an artifact of full stack development and efficiency improvement

2022-07-05 00:36:00 Straw hat Luffy driven by interest

One 、ApiFox brief introduction

After downloading, install it directly . If you don't want to install the client , It can also be used directly WEB edition , More lightweight .


Two 、ApiFox Usage scenarios of

Apifox Interface management 、 Development 、 Test the whole process integration tool , Use the audience for the entire R & D technology team , The main users are The front-end development The backend development and Testers .

  • The front-end development
    • Interface document management
    • Interface data Mock
    • Interface debugging
    • Front end code is automatically generated
  • The backend development
    • Interface document management
    • Interface debugging
    • Interface automation testing
    • Back end code is automatically generated
  • Testers
    • Interface debugging
    • Interface automation testing

3、 ... and 、ApiFox With the advantage of one enemy four

In the use of Postman + Swagger + Mock + JMeter when , We often encounter the following problems :

It's very difficult to maintain data consistency between different tools 、 Inefficient . And it's not just about the workload , The bigger problem is data inconsistency between multiple systems , Leading to inefficient collaboration 、 Frequent problems , Developers and testers are in agony .

  1. Developers in Swagger After defining the document , Interface debugging also needs to go Postman Define it again .
  2. The front-end development Mock When it comes to data mockjs Define it again , You also need to set it manually Mock The rules .
  3. Testers need to go to JMeter Define it again .
  4. Front end according to mockjs Mock The data is developed , Back end according to Swagger The defined interface document is developed , They all passed the test , I thought I could go online right away , As a result, a variety of problems were found :
    • The interface changed during development , Only modified Swagger, But they didn't synchronize the changes in time mockjs.
    • The interface data type of back-end development is inconsistent with the document , It's hard to see the problem with the naked eye .
  5. Again , Test in JMeter Well written test cases , When it's really running, you'll find all kinds of inconsistencies .
  6. Time is long. , The inconsistencies will get more and more serious .

ApiFox How to solve these problems ?

Apifox = Postman + Swagger + Mock + JMeter

Apifox yes API file 、API debugging 、API Mock、API Automated testing integrated collaboration platform .

Through a system 、 A piece of data , Solve the problem of data synchronization between multiple systems . Just define the interface document , Interface debugging 、 data Mock、 Interface testing can be used directly , There is no need to redefine ; Interface documentation and interface development debugging use the same tool , After the interface debugging is completed, it can ensure that it is completely consistent with the interface document definition . Efficient 、 In time 、 accuracy !


Four 、ApiFox Simple introduction

Install the client ( Or use WEB End ) after , You can use it directly :

  • Create new teams and projects :

  • Set the theme :( Default is white theme )

  • The interface test : Get weather data

The corresponding results after running are as follows :

{
    
	"reason": " The query is successful !",
	"result": {
    
		"city": " Hangzhou ",
		"realtime": {
    
			"temperature": "14",
			"humidity": "55",
			"info": " Fine ",
			"wid": "00",
			"direct": " dongfeng ",
			"power": "3 level ",
			"aqi": "140"
		},
		"future": [
			{
    
				"date": "2022-02-27",
				"temperature": "8/14℃",
				"weather": " Sunny to cloudy ",
				"wid": {
    
					"day": "00",
					"night": "01"
				},
				"direct": " The east wind turns and there is no wind direction "
			},
			{
    
				"date": "2022-02-28",
				"temperature": "9/20℃",
				"weather": " Cloudy to drizzle ",
				"wid": {
    
					"day": "01",
					"night": "07"
				},
				"direct": " Continue to turn from no wind to northwest wind "
			},
			{
    
				"date": "2022-03-01",
				"temperature": "7/15℃",
				"weather": " Light rain ",
				"wid": {
    
					"day": "07",
					"night": "07"
				},
				"direct": " The northwest wind turns and there is no wind direction "
			},
			{
    
				"date": "2022-03-02",
				"temperature": "7/17℃",
				"weather": " It's sunny to cloudy ",
				"wid": {
    
					"day": "00",
					"night": "02"
				},
				"direct": " There is no wind direction "
			},
			{
    
				"date": "2022-03-03",
				"temperature": "8/14℃",
				"weather": " Light to moderate rain ",
				"wid": {
    
					"day": "07",
					"night": "21"
				},
				"direct": " There is no wind direction "
			}
		]
	},
	"error_code": 0
}


5、 ... and 、API Interface design and interface documents

Apifox Interface documentation follows OpenApi 3.0 ( primary Swagger)、JSON Schema At the same time , It's very easy to use visualization Document management function , Zero learning cost , Very efficient . And support online sharing of interface documents .

When we define API After the interface , It can be directly generated online API file :


6、 ... and 、API data Mock

Interface data Mock: built-in Mock.js Rules engine , Very convenient mock All kinds of data , And you can define the data structure and write mock The rules . Support adding “ expect ”, According to the request parameters, different mock data . most important of all Apifox Zero configuration that will do Mock Very human data , The details are introduced later in this paper .

  • Create a new Mock Interface :

  • Define the interface name and input parameters :

  • Set up mock The corresponding result :

We can click the preview to view the generated random mock data (ApiFox The most intelligent place is , He can set it according to you mock Parameters , To automatically identify and randomly select the corresponding parameter values , For example, our birthday The field will be automatically recognized as birthday ):

  • Code auto generation :

We can customize mock Data interface , To automatically generate the corresponding entity class code .

  • preservation mock Interface , And run the test :

Test browser access :

7、 ... and 、API automated testing

Provide interface set testing , You can choose the interface ( Or interface use cases ) Quickly create test sets . At present, more functions of interface automation test are still under development , Coming soon ! The goal is : JMeter Some functions are basically , And use it better .

8、 ... and 、 Database integration

As shown in the figure below ,ApiFox You can connect to remote or local databases , It can be used as a lightweight visualization tool for database operation :

make new connection :

Support multiple source data import :

Nine 、 Online debugging

This document is written in Apifox It's done , I have tried this tool before , I didn't expect that so many powerful new functions have come out recently .

Click the run button in the upper right corner of the document , Will appear “ The online operation ” Module :

You can directly debug the interface on this interface ! direct 1. Fill in the parameters ,2. Select environment ,3. Point send , The interface request is sent out ! Here is the return result ! There is no need for Postman! Not to mention API Copy it again !

I thought. , If before the launch , It's using Apifox Words , There is simply no accident :

Parameter does not exist ? I got the data after online debugging , By comparison, I know which parameter does not exist
Wrong parameter type ? alike , After online commissioning , By comparison , I know which parameter has the wrong type
Interface does not exist ( Because the interface is written incorrectly )? When debugging, it will be reported that the interface does not exist , Find the back end at the first time ~

Ten 、ApiHub


ApiHub It integrates many third-party applications Api Tools , for example :

Let's take a gaud map API Use case of :

The effect is as follows :


Of course, you can also test other interface calling functions of Gaode map here ~

other

Besides ApiFox It also has many other functions , for example :

  1. Data model : Reusable data structure , Defining interfaces Return data structure And Request parameter data structure ( only JSON and XML Pattern ) You can directly reference . Support model direct nested reference , direct JSON/XML Smart import , Support oneOf、allOf And other advanced combination modes .
  2. Interface debugging :Postman Some functions , For example, environment variables 、 In front of / Post script 、Cookie/Session Global Shared And so on ,Apifox There are , And ratio Postman More efficient and easy to use . After the interface runs, click Save as use case Button , It can generate Interface use cases , Interface use cases can be run directly later , No more parameters need to be entered , Very convenient . Custom script 100% compatible Postman grammar , And support running javascript、java、python、php、js、BeanShell、go、shell、ruby、lua And other language codes .
  3. Interface use cases : Usually, an interface has multiple use cases , such as The parameters are correct Use cases 、 Parameter error Use cases 、 Data is empty Use cases 、 Different data states Use cases, etc . The correctness of data will be automatically verified when running the interface case , Using interface use cases to debug interfaces is very efficient .
  4. Database operation : Support reading database data , Used as an interface request parameter . Support reading database data , Used to verify ( Assertion ) Whether the interface request is successful .
  5. Quick request : similar Postman Interface debugging mode , It is mainly used for temporary debugging No documentation required The interface of , You can quickly debug without defining the interface in advance .
  6. Code generation : Define according to the interface and data model , Automatic system generation Interface request code Front end business code And Back end business code .
  7. Teamwork :Apifox Born for teamwork , Interface cloud real-time synchronous update , ripe The team / project / Member rights management , Meet the needs of various enterprises .

Want to know more , You can check the official website :ApiFox Official website address ,ApiFox Official Q & A qun

原网站

版权声明
本文为[Straw hat Luffy driven by interest]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050034311677.html