The actual combat of the baffle of the system test tool (1)

System test weapon baffle combat (1) - Programmer Sought

Actual combat of the bezel of the system test tool (2)
Actual combat of the bezel of the system test tool (3)
Actual combat of the bezel of the system test tool (4) Actual combat
of the bezel of the system test tool (5)
Actual combat of the bezel of the system test tool (6)
The end of the actual combat of the baffle of the system test tool (7)

cause of baffle

  • Today is the era of multi-service and multi-collaboration. Any system is no longer an isolated island, but interdependent.
  • Due to the difficulties of environment stability, data preparation, and parallel development between multiple systems, joint debugging and testing between multiple systems requires a lot of communication costs and troubleshooting costs. In order to solve this headache, the concept of baffles was introduced.
  • In fact, the baffle test is mainly a mock developed to simulate peripheral systems, services, and interfaces.
  • For example, in scenarios where the e-commerce system calls third-party payment for order payment and recharge, while both parties follow the interface agreement, technical personnel can focus on their own function realization regardless of development joint debugging, functional testing or performance testing.
  • In a word, in order to reduce the impact of peripheral systems, focus on your own functions under the framework of the interface protocol and reduce nonsense.

Solve the problem

  • The baffle solves the problem of instability: the Mock service is very simple, and the business logic is simple or even absent, so it is stable enough.
  • Quickly construct complex data: By customizing the returned results, very complex data can be constructed, and business verification can be done without the need for a third party to prepare data for us.
  • Quickly construct exception scenarios: For some abnormal situations, such as high network delay, retry mechanism, and special exception return, baffles can be used to construct.
  • Contract testing, driving test development, performance testing, and demonstration testing are all applicable.

frame description

  • Let’s review our general system architecture first. For example, the e-commerce system below will call peripheral system payment, SMS, real-name authentication, email notification, etc. External communication protocols include tcp, https, http, and smtp.

    image


    This mainly explains the scenario of calling the peripheral system. In fact, the internal system calls are more complicated than this.

  • After we introduce the architecture of the baffle, the baffle should be transparent to the core system access, which is a beautiful lie. The specific architecture is as follows:

     

    image

  • Let's take a deeper look at the structure of the lower bezel, which is divided into dynamic data and static data provision from the perspective of function.

     

    image

  • Bezel front

    Provide the service of the interface, what protocol and port to use.

  • static data

    Static data is prepared as needed before writing the test code, stored in the json data format (1.2) or other file data (1.1), and its data basically does not need to be changed.

  • dynamic data

    Dynamic data is generated when the test code is running or queried according to the business.

    Data without context is just some dynamic data output, using dynamic functions to generate data (2.1), dynamic function generation can use mockjs, which provides commonly used data generation, which will be introduced in detail later.

    The data has a contextual relationship, the current interface needs the previous interface data, and the database or NOSQL is used to provide the data (2.2).

  • Timed callback

    The use of timed tasks can regularly push data to the core system according to business needs, which closes the entire business call link. His data comes from static or dynamic data.

Technology Selection

According to the above architectural requirements, among the various open source frameworks, <label style="color:red"> mountebank+mockjs </label> is selected . Many other frameworks are not commented here. There is no distinction between good and bad software. Fit matters!

Mountebank itself is quite powerful. According to the official statement, mountebank can provide cross-platform and multi-protocol test mocks, which provide test drivers just like what we call stub code. It is the most
powerful open source and can completely heal your pain.

In a word, mountebank realizes the baffle service simply and conveniently.

Mountebank is abbreviated as mb, pay attention to the direct name later.

Mockjs itself can also provide the function of mocking. I mainly like its powerful and rich data types, and it is quite convenient to generate dynamic data.
Try it first:

Mock.mock({
  "number|1-100": 100
})

This function can easily get a random number from 1 to 100, which is quite convenient.

Environment installation

Since mountebank is based on nodejs, you must first install nodejs, and the version requirement is v6 or above (I won’t talk about its strengths here, and friends who are front-ends know it well).

官方下载https://nodejs.org/en/download/

or

yum install -y nodejs

Then mb is installed with other components

#安装mountebank
npm install -g mountebank
#http请求提交试用
npm install superagent --save
#日志打印
npm install log4js
#获取UUID试用
npm install uuid --save
#获取时间
npm install moment
#mysql连接用
npm install mysql -S
#定时任务
npm install cron
#mock常用函数组件
npm install mockjs

Actual combat of the bezel of the system test tool (2)
Actual combat of the bezel of the system test tool (3)
Actual combat of the bezel of the system test tool (4) Actual combat
of the bezel of the system test tool (5)
Actual combat of the bezel of the system test tool (6)
The end of the actual combat of the baffle of the system test tool (7)



Author: Old Du Zatan
Link: https://www.jianshu.com/p/e04489add6ce
Source: Jianshu
The copyright belongs to the author. For commercial reprint, please contact the author for authorization, for non-commercial reprint, please indicate the source.

Guess you like

Origin blog.csdn.net/liuqinhou/article/details/131227735