[Interface Test] Test Basics

1. Introduction to interface testing

1. Definition of interface testing

Interface testing is a test that tests the interfaces between system components . The main goal is to detect the interaction points between external systems and internal subsystems to check the exchange, transmission and control management process of data, as well as the communication between systems. Mutual logical dependencies, etc.

As programs with separate front-end and back-end development become more and more common, the interfaces developed by the back-end must comply with specifications. When users use the program, the interaction between data is also implemented using interfaces, so testing the interface is very necessary and important.

Here I would like to introduce you to some basic front-end and back-end concepts:

  • Front-end : refers to the level of user operation, usually providing a visual interface, such as Web front-end and APP front-end. The main tasks of the front end are web page layout, content rendering, providing user input windows, screen resolution adaptation and interactive effects, etc.
  • Backend : It is also the server side, the level of user data processing. Receive the data passed by the front end and process it, and then return the processing results to the front end. The main tasks of the backend are responsible for programming architecture ideas, database management, data access, platform stability and performance, etc.
  • Front-end and back-end interfaces : The collective name for data interaction between the front-end and the back-end, also called data interface, is a type of remote call. Generally speaking, it is developed by the back-end and used by the front-end according to certain conventions and specifications. Users perform certain operations on the front-end and send requests to the back-end to obtain data or achieve certain purposes. The front-end and back-end cooperate to complete the user's operations.

2. The purpose and significance of interface testing

The focus of interface testing is to check the data exchange , transmission and control management processes, as well as the mutual logical dependencies between systems, etc. As long as the interface is exposed, it should be accurate, safe, standardized, and stable.

The core of interface testing is to ensure the correct and stable operation of the system . The closer a system server is to the bottom layer, the greater its overall impact on the system. The interface is an entrance exposed to the outside world by the server. Therefore, interface testing can ensure the specification and stability of the interface and the correct entrance of the server.

Interface testing can ensure product quality and improve user experience . Interface testing can expose more hidden defects and fix them during the interface development stage, reducing product development costs. Subsequent performance testing and interface function testing can also go more smoothly, allowing products to be delivered on time while ensuring quality.

The significance of interface testing is:

  1. Verify the correctness and stability of the interface: By testing the functionality and performance of the interface, you can verify that the interface meets expectations and determine its stability and correctness under different conditions.

  2. Improve system reliability: The interface is the bridge for interaction between system components, and its quality directly affects the reliability of the entire system. Through testing, defects and errors in the interface can be discovered and repaired in a timely manner, thus improving the reliability of the system.

  3. Reduce development costs and save testing costs: In an era when agile development is prevalent, testing work also requires rapid iteration following product release. In the past two years, the concept of shifting testing to the left has been proposed, allowing testing work to be intervened as early as possible, because the earlier defects are discovered, the lower the cost of repairing them. According to the data model, one BUG in the bottom layer can cause about 8 BUGs in the upper layer, and the BUG in the bottom layer can easily cause the collapse of the entire system. Carrying out interface testing can reduce the number of BUGs in interface testing, reduce repair costs, and save testing costs.

  4. Ensure the security of the system: Interface testing can detect security vulnerabilities at the interface level and ensure the security of the system.

  5. Promote teamwork: Interface testing requires cooperation and coordination between different departments and can promote teamwork and communication.

In short, interface testing is an important part of ensuring system quality and reliability, and helps improve system robustness and user experience.

3. Classification of interface tests 

Interface testing can be mainly divided into the following categories:

  1. Functional testing: Mainly verify whether the interface can correctly complete the expected functional requirements, including input and output, return value, exception handling, etc.
  2. Performance testing: Mainly verify the performance of the interface under load, concurrency and other pressures, including response time, throughput, number of concurrencies, etc.
  3. Security testing: Mainly verify whether there are security vulnerabilities in the interface, such as SQL injection, cross-site scripting attacks, permission control, etc.
  4. Compatibility testing: Mainly verify the compatibility of the interface under different operating systems, browsers, devices and other environments to ensure that the interface can operate normally.

In short, for different testing purposes and requirements, you can choose the corresponding test type for interface testing to fully cover the functions and abnormal conditions of the interface and ensure that the interface can work normally and achieve the expected results.

4. Common interface protocols

Interface protocol refers to the communication methods and requirements that need to be followed between interfaces that need to exchange information. There are many types of interface protocols. The interface protocol must not only specify the communication at the physical layer, but also specify the requirements at the syntax layer and semantic layer.

Interfaces usually have the following protocol types:

TCP

TCP (Transmission Control Protocol) is a connection-oriented , reliable , byte stream -based transport layer protocol. It is a transport layer protocol in the OSI network seven-layer model. TCP provides reliable data transmission in the IP environment. It will open up a well-connected channel for the data to be sent before sending the data. TCP is designed to accommodate a layered protocol hierarchy that supports multiple network applications. TCP relies on TCP to provide reliable communication services between pairs of processes in a host computer that are connected to different but interconnected computer communication networks.

UDP

UDP (User Datagram Protocol) provides a way for applications to send encapsulated IP packets without establishing a connection . Both TCP and TCP are transport layer protocols in the OSI network seven-layer model, but UDP provides non-connection-oriented and unreliable data stream transmission. It only sends the datagrams passed by the application to the IP layer, but does not guarantee that they can reach their destination.

HTTP

HTTP (Hyper Text Transfer Protocol) is a simple request-response protocol that usually runs on top of TCP. It specifies what kind of messages the client may send to the server and what kind of response it gets. It is an application layer protocol in the OSI network seven-layer model. The main features are simple, fast, flexible, connectionless and stateless .

HTTPS

HTTPS (full name: Hypertext Transfer Protocol Secure) is an HTTP channel aimed at security. Based on HTTP, it ensures the security of the transmission process through transmission encryption and identity authentication. HTTPS adds SSL to the foundation of HTTP. The security foundation of HTTPS is SSL, so the details of encryption require SSL. HTTPS has a different default port than HTTP and an encryption/authentication layer (between HTTP and TCP). This system provides authentication and encrypted communication methods. It is widely used for security-sensitive communications on the World Wide Web, such as transaction payments.

RPC

RPC (Remote Procedure Call Remote Procedure Call Protocol) is a protocol that requests services from a remote computer over the network without knowing the underlying network technology. Simply put, one node requests services provided by another node. In the OSI network seven-layer model, RPC spans the transport layer and application layer. RPC makes it easier to develop applications, including network-distributed multi-program applications. Web Service and RESTFul are both RPC, but the message organization form and message protocol are different.

FTP

Also known as File Transfer Protocol, it is a protocol used to transfer files over a network. FTP uses a client/server model, where the client transfers files by transferring them back and forth between local and server.

SOAP

Also known as Simple Object Access Protocol, it is an XML-based protocol for transmitting structured data over the network. SOAP uses HTTP or SMTP protocols for transport and uses XML format to encode the data.

REST

Also known as representative state transfer, it is an architectural style based on the HTTP protocol. REST uses HTTP methods (GET, POST, PUT, DELETE, etc.) to operate on resources and uses URIs to identify the location of resources.

2. Interface documentation

1. Introduction to interface documents

An interface document is a description document that describes how a software component or Web service interacts with the outside world. It provides detailed descriptions of the interface name, interface URL, calling method, parameter format, response format, and return examples, so that callers can easily understand and use the interface.

The main purpose of the interface document is to provide a standard document format so that callers of the interface can operate according to the instructions provided in the document, and at the same time, it can also facilitate the development and maintenance of the interface.

In project development with front-end and back-end separation, an API interface document is crucial. It is an interface jointly defined by front-end and back-end engineers, and subsequent development work needs to be developed based on this interface document. Interface documents can enable front-end and back-end engineers to have a unified document for communication during the project development process. If project personnel change, they can easily view and understand the project functional interface. It is also very beneficial in terms of later maintenance.

2.Interface documentation

Take "Tencent Document Open API Introduction" as an example to introduce the interface document, address: Tencent Document

 

An excellent interface document includes: introduction, conceptual terms, API overview, usage steps, API interface details and other content.

  1. Introduction: Briefly introduce the theme, purpose and scope of the interface document, so that readers can quickly understand the core content of the document. It does not need to be too much, just describe clearly what the document is used for.

  2. Conceptual terminology: Explanation of professional vocabulary, listing important concepts and terms related to interfaces to ensure readers have a full understanding of them. This includes some basic computer science and programming terminology, as well as interface-specific terminology.

  3. API overview: a classification summary of the API, what functions the API provides; an overview of the interface, including interface name, version, supported languages ​​and related documents, etc.

  4. Usage steps: How to use the API interface, the communication protocol adopted, points to note when using it, authentication, and the meaning of the error code returned should all be reflected.

  5. API interface details: API interface details are the core content of the interface document and the place most viewed by development engineers. It records the details of each interface and provides usage examples. Some interface documents only have one API interface details, allowing developers to know how many interfaces can be used and how to use them.

  6. Other content: interface-related content. For example, "Tencent Documentation Open API Introduction" has a large item on development and application registration, which is not the main content in the interface document, but is related to the interface.

In short, a good interface document should be clear, concise and easy to understand, providing enough details so that readers can easily understand and use the interface. At the same time, documentation should be easy to find and understand so readers can quickly solve problems and get necessary support.

3. Interface analysis

An interface should have four parts: request method, URL, request parameters and return parameters.

  • Request method: The method in which the interface request is sent, such as GET, POST, PUT, and DELETE.
  • URL: The address requested by the interface.
  • Request parameters: Generally there are four contents, namely parameter name, parameter type, whether it is required and description.
  • Return parameters: The return parameters have various structures, they can be Code and Message, or they can be an object or a list.

The details of an interface should include four parts, namely interface description, input parameters, output parameters and examples.

  • Interface description: Introduction to interface functions and definition of the interface (including the URL of the interface and the request method).
  • Input parameters: Definition and description of input parameters.
  • Output parameters: the return value after calling the interface.
  • Example: usage of interface, sample code.

As shown below:

3.1 Interface description

describe

definition

Interface name

/openapi/v1/user/auth

Request method

POST

Request format

application/x-www-form-urlencoded

 This interface is used to obtain the user's login status

 3.2 Input parameters

The following request parameter list only lists interface request parameters and some public parameters. For a complete list of public parameters, see Public Request Parameters.

parameter name

type

required

describe

APPID

Integer

yes

public parameters

TIMESTAMP

Integer

yes

public parameters

NONCE

Integer

yes

public parameters

SIGNATURE

String

yes

public parameters

Choose one of the three login methods below. Only one method can be uploaded at a time.

When logging in with Enterprise WeChat Token/Code, pass the following parameters

parameter name

type

required

describe

third_token

String

yes

Third-party bills, users verify user information with third parties

login_type

Integer

yes

Fill in 0

 When logging in with QQ, pass the following parameters

parameter name

type

required

describe

third_dad

Integer

yes

Third-party login domain

third_point

Integer

yes

Third-party login QQ account

third_pskey

String

yes

Third-party login PSkey

login_type

Integer

yes

Fill in 1

When logging in with WeChat, pass the following parameters 

parameter name

type

required

describe

third_wx_appid

String

yes

Third-party WeChat appid

third_openid

String

yes

Third-party WeChat login OpenID

third_access_token

String

yes

Third-party WeChat access token

login_type

Integer

yes

Fill in 2

When logging in with a third-party callback, pass the following parameters

parameter name

type

required

describe

third_token

String

yes

Third-party bills, users verify user information with third parties

login_type

Integer

yes

Fill in 3

3.3 Output parameters

parameter name

type

describe

come

String

User ID

toid_key

String

User login key

jump_code

String

Use one-time code for jump

3.4 Example

The figure below is an example of creating a document interface.

Guess you like

Origin blog.csdn.net/Javascript_tsj/article/details/133409058
Recommended