Interface test case processing method and device, electronic equipment, computer readable storage medium and computer program product
By matching and filtering interface information, combining use case generation instructions to generate interface test cases, and using language models to predict and adjust, the problem of insufficient accuracy in the generation of interface test cases is solved and the quality and efficiency of test cases are improved.
Patent Information
- Application Number
- CN202410924621.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-09
- Publication Date
- 2024-12-17
AI Technical Summary
In the prior art, the accuracy of the generation of interface test cases is insufficient, especially the generation requirements of different types of interfaces are different, which makes it difficult to improve the accuracy of test cases.
By obtaining the information of the interface to be tested and the information of the reference test cases, performing matching degree calculations, filtering out appropriate reference test cases, and generating target test cases based on the use case generation instructions, using the language model to predict and adjust the test cases to ensure the generated The test cases meet the interface requirements.
Improve the accuracy and efficiency of interface test cases generation, reduce the dependence of manual writing, and improve test coverage and quality.
Smart Images

Figure CN119149387A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to interface testing technology, and in particular to a method, device, electronic device, computer-readable storage medium and computer program product for processing interface test cases. Background Art
[0002] Interface testing is a very important step in the software development process. Testing interfaces can verify whether each interface meets the design specifications and functional requirements, thereby ensuring the quality and stability of the software system. In related technologies, in order to improve the efficiency of interface testing and reduce labor costs, automated testing of interfaces is achieved by building automated testing tools. In automated testing, test cases for each interface will also be automatically generated to test it. However, different types of interfaces have different use case generation requirements, and the accuracy of generated interface test cases needs to be improved. Summary of the invention
[0003] The embodiments of the present application provide a method, device, electronic device, computer-readable storage medium and computer program product for processing interface test cases, which can improve the accuracy of generating interface test cases.
[0004] The technical solution of the embodiment of the present application is implemented as follows:
[0005] The present invention provides a method for processing an interface test case, the method comprising:
[0006] Obtain first interface information of the interface to be tested and second interface information of the reference test case;
[0007] Matching the first interface information with the second interface information of the reference test case to obtain a matching degree between the first interface information and the second interface information;
[0008] Based on the matching degree, selecting a first reference test case from the reference test cases;
[0009] If the first reference test case is associated with a first test case generation instruction, a target test case of the interface to be tested is generated based on the first test case generation instruction.
[0010] The present application provides a device for processing an interface test case, including:
[0011] An acquisition module, used to acquire first interface information of the interface to be tested and second interface information of a reference test case;
[0012] A matching module, used for matching the first interface information with the second interface information of the reference test case to obtain a matching degree between the first interface information and the second interface information;
[0013] A screening module, configured to screen out a first reference test case from the reference test cases based on the matching degree;
[0014] The first generating module is used to generate a target test case for the interface to be tested based on the first test case generating instruction if the first reference test case is associated with the first test case generating instruction.
[0015] In the above scheme, the matching module is also used to perform similarity matching on the first interface information and the second interface information of the reference test case to obtain the similarity matching degree between the first interface information and each of the second interface information; or, to perform structured matching on the first interface information and the second interface information of the reference test case to obtain the structured matching degree between the first interface information and each of the second interface information; or, to perform semantic matching on the first interface information and the second interface information of the reference test case to obtain the semantic matching degree between the first interface information and each of the second interface information.
[0016] In the above scheme, the screening module is also used to screen out a first reference test case whose matching degree meets the preset matching conditions from the reference test cases based on the matching degree; wherein the preset matching conditions include at least one of the following: the maximum matching degree and the matching degree greater than the preset matching threshold.
[0017] In the above scheme, the device also includes a query module, and after the screening module filters out the first reference test case from the reference test cases, the query module is used to obtain the association relationship between the reference test case and the use case generation instruction; based on the first reference test case, the association relationship is queried; if a use case generation instruction corresponding to the first reference test case is queried, it is determined that the first reference test case is associated with the first use case generation instruction, and the queried use case generation instruction is used as the first use case generation instruction.
[0018] In the above scheme, the first generation module is also used to obtain the target generation rules and target generation format included in the first use case generation instruction; construct a test case based on the target generation rules and the first interface information to obtain an initial test case for the interface to be tested; and convert the format of the initial test case based on the target generation format to obtain a target test case that conforms to the target generation format.
[0019] In the above scheme, the first generation module is also used to obtain the target model identifier, target generation rule and target generation format in the first use case generation instruction; through the language model corresponding to the target model identifier, test case prediction is performed based on the first interface information, the target generation rule and the target generation format to obtain the target test case.
[0020] In the above scheme, the device also includes an association module, and before the acquisition module acquires the first interface information of the interface to be tested and the second interface information of the reference test case, the association module is used to acquire the instruction content included in the pre-built use case generation instruction and the second reference test case pre-associated with the use case generation instruction, the instruction content including the model identifier, the generation format and the generation rule; through the language model corresponding to the model identifier, based on the generation format, the generation rule and the third interface information of the second reference test case, a test case prediction is performed to obtain a first predicted test case; the second reference test case is compared with the first predicted test case to obtain a first comparison result; if the first comparison result indicates that the difference between the second reference test case and the first predicted test case exceeds a first difference threshold, at least one of the instruction content included in the use case generation instruction or the second reference test case pre-associated with the use case generation instruction is adjusted, and the adjusted use case generation instruction is associated with the second reference test case.
[0021] In the above scheme, the association module is also used to determine the interface type corresponding to the use case generation instruction, and obtain a third reference test case under the interface type; through the language model corresponding to the model identifier, test case prediction is performed based on the generation format, the generation rules and the fourth interface information of the third reference test case to obtain a second predicted test case; the third reference test case is compared with the second predicted test case to obtain a second comparison result; if the second comparison result indicates that the difference between the third reference test case and the second predicted test case is less than a second difference threshold, the second reference test case is adjusted to the third reference test case.
[0022] In the above scheme, the device also includes a second generation module. After the screening module filters out the first reference test case from the reference test cases, the second generation module is used to obtain a second use case generation instruction if the first reference test case is not associated with the first use case generation instruction; wherein the second use case generation instruction is a general use case generation instruction, or the degree of similarity between the test scenario applicable to the second use case generation instruction and the first use case generation instruction exceeds a similarity threshold; based on the second use case generation instruction, a target test case for the interface to be tested is generated.
[0023] In the above scheme, the device also includes a verification and correction module. After generating the target test case of the interface to be tested, the verification and correction module is used to perform format correction on the target test case if the format of the target test case does not meet the target generation format or there is a format error in the target test case, until the number of format verifications on the target test case exceeds a preset number, and then the interface to be tested is marked.
[0024] An embodiment of the present application provides an electronic device, the electronic device comprising:
[0025] A memory for storing computer executable instructions;
[0026] The processor is used to implement the method for processing the interface test case provided in the embodiment of the present application when executing the computer executable instructions stored in the memory.
[0027] An embodiment of the present application provides a computer-readable storage medium storing a computer program or computer-executable instructions for implementing a method for processing an interface test case provided in an embodiment of the present application when executed by a processor.
[0028] An embodiment of the present application provides a computer program product, including a computer program or computer executable instructions. When the computer program or computer executable instructions are executed by a processor, the method for processing the interface test case provided by the embodiment of the present application is implemented.
[0029] Applying the above embodiment, when generating an interface test case for the interface to be tested, by obtaining the first interface information of the interface to be tested and the second interface information of the pre-built reference test case, and based on the matching degree of the first interface information and the second interface information, the first reference test case can be screened out from the reference test case. In the case where the first reference test case is associated with a first case generation instruction, the target test case of the case to be tested can be directly generated based on the first case generation instruction. In the above manner, since the first case generation instruction is suitable for generating a test case that matches the first reference test case, and the first reference test case is a test case suitable for testing the interface to be tested, the accuracy of the target test case generated for the interface to be tested can be improved through the first case generation instruction. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 It is a structural diagram of the processing system architecture of the interface test case provided in the embodiment of the present application;
[0031] Figure 2 It is a structural schematic diagram of an electronic device for implementing a method for processing an interface test case provided in an embodiment of the present application;
[0032] Figure 3A It is a first flow chart of the method for processing an interface test case provided in an embodiment of the present application;
[0033] Figure 3B It is a second flow chart of the method for processing interface test cases provided in an embodiment of the present application;
[0034] Figure 3C It is a first flow chart of the method for generating a target test case provided by an embodiment of the present application;
[0035] Figure 3D It is a second flow chart of the method for generating a target test case provided by an embodiment of the present application;
[0036] Figure 3E It is a third flow chart of the method for processing an interface test case provided in an embodiment of the present application;
[0037] Figure 4 It is a structural diagram of the automated interface test case generation platform provided in an embodiment of the present application;
[0038] Figure 5 This is a fourth flow chart of the method for processing interface test cases provided in an embodiment of the present application.
[0039] It should be pointed out that the above-mentioned "first" and "second" are only used to distinguish different solutions, and do not represent the degree of superiority or inferiority of the solutions or the priority in the implementation process. DETAILED DESCRIPTION
[0040] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. The described embodiments should not be regarded as limiting the present application. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of this application.
[0041] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it can be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0042] In the following description, the terms "first\second\third" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first\second\third" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described here can be implemented in an order other than that illustrated or described here.
[0043] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program with a predetermined function, and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories) or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.
[0044] Unless otherwise defined, all technical and scientific terms used in the embodiments of the present application have the same meanings as those commonly understood by those skilled in the art. The terms used in the embodiments of the present application are only for the purpose of describing the embodiments of the present application and are not intended to limit the present application.
[0045] The relevant data collection and processing in the embodiments of this application should be strictly in accordance with the requirements of relevant laws and regulations when applied in examples, obtain the informed consent or separate consent of the personal information subject, and carry out subsequent data use and processing within the scope of authorization of laws and regulations and the personal information subject.
[0046] Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.
[0047] 1) Interface refers to an agreement or protocol between two or more classes, which defines the way and method of interaction between them. Interface is an abstract type that only defines the behavior of an object without involving specific implementation. Interface can be used to define the interaction between classes and implement polymorphism.
[0048] 2) Interface testing is a testing method in software testing, which is used to verify whether the interfaces between various components in the software system communicate and interact according to the specifications. In interface testing, data transmission, communication protocols, parameter transfer and other aspects between different software components are tested to ensure that the interface functions normally, data is accurately transferred, and meets the expected specifications and standards. Interface testing usually includes: interface function testing, interface performance testing, interface security testing, interface compatibility testing, and interface reliability testing.
[0049] 3) Test cases are a collection of test activities that need to be performed during the test process to verify whether the functions, performance, security and reliability of the software system meet expectations. Test cases usually include test objectives, test conditions, input data, expected output, test steps and result analysis.
[0050] 4) Similarity matching refers to determining the relationship or similarity between two objects by comparing the degree of similarity between them. This kind of matching can be used in different fields and applications, such as text similarity matching, image similarity matching, audio similarity matching, etc. In the text field, similarity matching can be used to compare the similarity between two pieces of text, usually by calculating the distance or similarity index between them.
[0051] 5) Structured matching is a matching method based on the structure and relationship of data. Matching methods include: XML matching, XML is a markup language that can define the structure and relationship of data. In XML matching, the structure and content of two XML documents are compared to determine whether they match. JSON matching, JSON is a lightweight data exchange format, which compares the structure and key-value pairs of two JSON objects to determine whether they match.
[0052] 6) Semantic matching refers to judging the relationship or similarity between two texts based on semantic similarity or relevance in natural language processing and information retrieval. It involves understanding and comparing the meaning of texts to determine the relationship between them, not just based on the superficial similarity of words or phrases.
[0053] 7) Similarity refers to the degree of similarity or similarity between two objects. Similarity can be calculated and evaluated in various ways, such as text similarity, scene similarity, intent similarity, etc. Similarity is usually used to compare the features, attributes or structures between two objects to determine the relationship or similarity between them. In the embodiment of the present application, similarity can be used to refer to at least one of the text similarity and scene similarity between two use case generation instructions.
[0054] 8) Language Model (LLM): A machine learning model designed to understand and generate human language. They are trained on large amounts of text data and can perform a wide range of tasks, including text summarization, translation, sentiment analysis, etc. Large language models are characterized by their large scale and billions of parameters, which help them learn complex patterns in language data. They are usually based on deep learning architectures. Large language models refer to deep learning models trained with large amounts of text data, containing billions or even larger parameters. They can be used to generate natural language text and understand the meaning of natural language text. Through training, the model can learn the statistical laws and semantic associations of language to build a huge language knowledge base, thereby simulating human language understanding and generation capabilities.
[0055] Interface testing is an essential step to ensure that software functions and performance meet specifications and standards. When testing interfaces, different test cases are usually designed for different interfaces. In the related art, the test cases of interfaces were originally written manually by testers. After the testers sorted out the interface functions and logic through the requirements document, they combined the interface documents and used the test case design method to write interface test cases in a specified format. However, this method is inefficient and time-consuming, and relies on the tester's familiarity with the test method and personal experience. The quality of test cases written by testers at different levels varies, and there is a risk of incomplete coverage and missed tests. In this regard, the related art has constructed a test framework and tools for automated testing of interfaces, and uses automated testing tools to perform the interface testing process. Compared with manual testing, automated testing can improve testing efficiency, reduce labor costs, and can perform tests multiple times in a short period of time to ensure the stability and reliability of the interface. In automated testing, the production efficiency of test cases will also be improved by automatically generating test cases for each interface. However, different types of interfaces have different use case generation requirements, and the accuracy of interface test cases needs to be improved.
[0056] To this end, embodiments of the present application provide a method, device, electronic device, computer-readable storage medium, and computer program product for processing interface test cases, which can improve the accuracy of generating interface test cases.
[0057] See also Figure 1 , Figure 1 It is an architectural diagram of the interface test case processing system 100 provided in an embodiment of the present application. To implement a processing application that supports an interface test case, the terminal 401 is connected to the server 200 via the network 300. The network 300 can be a wide area network or a local area network, or a combination of the two.
[0058] The terminal 401 is used for sending an interface test case processing request for the interface to be tested to the server 200 in response to an interface test case processing instruction for the interface to be tested.
[0059] The server 200 is used to receive an interface test case processing request sent by the terminal 401, and in response to the interface test case processing request, obtain the first interface information of the interface to be tested and the second interface information of the reference test case; match the first interface information with the second interface information of the reference test case to obtain the matching degree between the first interface information and the second interface information; based on the matching degree, filter out the first reference test case from the reference test case; if the first reference test case is associated with a first case generation instruction, then generate a target test case for the interface to be tested based on the first case generation instruction.
[0060] In some embodiments, after the server 200 generates the target test case of the interface to be tested, it may actively send the target test case to the terminal 401 so that the user can view the target test case through the terminal 401. Currently, the terminal 401 may also actively obtain the target test case from the server 200.
[0061] In some embodiments, if the testing tool for testing the interface to be tested is deployed in the server 200, after generating the target test case of the interface to be tested, the server 200 can also directly use the target test case to perform automated testing on the interface to be tested through the testing tool.
[0062] In some embodiments, the method for processing interface test cases provided in the embodiments of the present application can be implemented by various electronic devices, for example, it can be implemented by terminal 401 alone, by server 200 alone, or by terminal 401 and server 200 in collaboration.
[0063] The terminal 401 can be implemented as various types of terminals such as a laptop computer, a tablet computer, a desktop computer, a set-top box, a smart phone, a smart speaker, a smart watch, a smart TV, a car terminal, etc.
[0064] In some embodiments, the server 200 may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms. The terminal 401 and the server 200 may be directly or indirectly connected via wired or wireless communication, which is not limited in the embodiments of the present application.
[0065] See also Figure 2 , Figure 2 is a structural diagram of an electronic device 400 for implementing a method for processing an interface test case provided in an embodiment of the present application, Figure 2 The electronic device 400 shown includes: at least one processor 410, a memory 450, at least one network interface 420 and a user interface 430. The various components in the electronic device 400 are coupled together via a bus system 440. It is understood that the bus system 440 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 440 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, the bus system 440 is not described in detail. Figure 2 Various buses are labeled as bus system 440 .
[0066] The processor 410 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., where the general-purpose processor can be a microprocessor or any conventional processor, etc.
[0067] The user interface 430 includes one or more output devices 431 that enable presentation of media content, including one or more speakers and / or one or more visual display screens. The user interface 430 also includes one or more input devices 432, including user interface components that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.
[0068] The memory 450 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state memory, hard disk drives, optical disk drives, etc. The memory 450 may optionally include one or more storage devices that are physically remote from the processor 410.
[0069] The memory 450 includes a volatile memory or a non-volatile memory, and may also include both volatile and non-volatile memories. The non-volatile memory may be a read-only memory (ROM), and the volatile memory may be a random access memory (RAM). The memory 450 described in the embodiments of the present application is intended to include any suitable type of memory.
[0070] In some embodiments, memory 450 can store data to support various operations, examples of which include programs, modules, and data structures, or a subset or superset thereof, as exemplarily described below.
[0071] Operating system 451, including system programs for processing various basic system services and performing hardware-related tasks, such as a framework layer, a core library layer, a driver layer, etc., for implementing various basic services and processing hardware-based tasks;
[0072] A network communication module 452, used to reach other electronic devices via one or more (wired or wireless) network interfaces 420, exemplary network interfaces 420 include: Bluetooth, Wireless Compatibility Certification (WiFi), and Universal Serial Bus (USB), etc.;
[0073] a presentation module 453 for enabling presentation of information via one or more output devices 431 (e.g., display screen, speaker, etc.) associated with the user interface 430 (e.g., a user interface for operating peripherals and displaying content and information);
[0074] The input processing module 454 is used to detect one or more user inputs or interactions from one of the one or more input devices 432 and translate the detected inputs or interactions.
[0075] In some embodiments, the device provided in the embodiments of the present application can be implemented in software. Figure 2 The processing device 455 of the interface test case stored in the memory 450 is shown, which can be software in the form of a program and a plug-in, etc., including the following software modules: an acquisition module 4551, a matching module 4552, a screening module 4553, and a first generation module 4554. These modules are logical, so they can be arbitrarily combined or further split according to the functions implemented. The functions of each module will be explained below.
[0076] In other embodiments, the processing device of the interface test case provided in the embodiment of the present application can be implemented in hardware. As an example, the processing device of the interface test case provided in the embodiment of the present application can be a processor in the form of a hardware decoding processor, which is programmed to execute the processing method of the interface test case provided in the embodiment of the present application. For example, the processor in the form of a hardware decoding processor can adopt one or more application-specific integrated circuits (Application Specific Integrated Circuit, ASIC), digital signal processors (Digital Signal Processor, DSP), programmable logic devices (Programmable Logic Device, PLD), complex programmable logic devices (Complex Programmable Logic Device, CPLD), field programmable gate arrays (Field-Programmable Gate Array, FPGA) or other electronic components.
[0077] Below, the processing method of the interface test case provided by the embodiment of the present application will be described in conjunction with the accompanying drawings. As mentioned above, the electronic device that implements the processing method of the interface test case of the embodiment of the present application can be the terminal 401, the server 200, or a combination of the two. Therefore, the execution subject of each step will not be repeatedly described below.
[0078] The processing method of the interface test case of the embodiment of the present application is described by taking the execution subject as the server 200 as an example. Figure 3A , Figure 3A This is a first flow chart of the method for processing an interface test case provided in an embodiment of the present application, which will be combined with Figure 3A The steps shown are explained.
[0079] In step 101, first interface information of an interface to be tested and second interface information of a reference test case are obtained.
[0080] In actual applications, the first interface information of the interface to be tested may include the interface version to which the interface belongs, the module to which the interface belongs, the interface name, the application programming interface (API, Application Programming Interface) address, the request header, the request input parameter, and the interface response information. Among them, the module to which the interface belongs is used to characterize the functional module to which the interface to be tested belongs in the software system; the version to which the interface belongs is used to characterize the development version to which the interface to be tested belongs; the request header (HTTP Headers) is a part of the HTTP request, which is used to pass additional information to the server 200, such as the interface name, the version to which the interface belongs, the request input parameter, etc.; the request input parameter refers to the parameters or data passed to the interface to be tested when sending a request; the interface response information refers to the data or response status returned by the interface. Among them, the interface name and the version to which the interface belongs are the unique identifiers for identifying the interface.
[0081] In actual applications, for different interfaces under different functional modules in the software system, N (where N is a positive integer) reference test cases can be pre-configured, and the reference test cases can include second interface information, and the second interface information at least includes an interface request method, an API address, and interface input parameter information. When the server 200 receives a processing request for an interface test case for an interface to be tested, it can obtain the first interface information corresponding to the interface to be tested, and the second interface information corresponding to each of the pre-configured N reference test cases.
[0082] In step 102, the first interface information is matched with the second interface information of the reference test case to obtain a matching degree between the first interface information and the second interface information.
[0083] In practical applications, by matching the first interface information with the second interface information, a reference test case that best matches the first interface information can be screened out.
[0084] In some embodiments, Figure 3A The step 102 shown can be implemented in the following manner.
[0085] In one implementation, similarity matching is performed on the first interface information and the second interface information of the reference test case to obtain the similarity matching degree between the first interface information and each second interface information.
[0086] Among them, similarity matching is a method used to compare the similarity between two texts in natural language processing. It is usually achieved by calculating the distance or similarity index between them. Common similarity algorithms include: cosine similarity algorithm, edit distance algorithm, word vector similarity algorithm, etc. In the case that both the first interface information and the second interface information are represented by text, any of the above similarity algorithms can be used to calculate the similarity matching between the two.
[0087] In another implementation, a structural match is performed on the first interface information and the second interface information of the reference test case to obtain a structural matching degree between the first interface information and each second interface information.
[0088] Among them, structured matching is a method of matching based on the structure and relationship of data. Commonly used structured matching methods include XML matching method, JSON matching method, etc. When the first interface information and the second interface information are stored in a structured manner, such as in an XML document or a JSON document, a corresponding structured matching method can be selected to calculate the structured matching degree between the first interface information and the second interface information.
[0089] In a third achievable manner, semantic matching is performed on the first interface information and the second interface information of the reference test case to obtain the semantic matching degree between the first interface information and each second interface information.
[0090] Among them, semantic matching is a natural language processing technology that involves extracting and interpreting meaning from text. This includes identifying the meaning of words and phrases, understanding the grammatical structure of sentences, and inferring the relationship and context between texts. Common semantic matching algorithms include rule-based methods, statistical methods (such as bag-of-words models, etc.), and deep learning methods (such as neural networks, Transformers, etc.). When the first interface information and the second interface information use complex text to describe the contents included (such as interface request method, API address, interface input parameter information), so that the first interface information and the second interface information have a certain semantic logic, the semantic matching degree between the first interface information and the second interface information can be calculated by semantic matching.
[0091] After determining the matching degree between the first interface information and each second interface information in various dimensions (such as similarity matching degree, structured matching degree, and semantic matching degree) through the above various implementation methods, at least one of the similarity matching degree, structured matching degree, and semantic matching degree can be used as the matching degree between the first interface information and each second interface information; in addition, the weights corresponding to the matching degrees in various dimensions can be obtained, and based on the respective weights, the matching degrees in various dimensions are weighted and summed, and the weighted sum result is used as the matching degree between the first interface information and each second interface information.
[0092] It can be understood that the above three algorithms are all matching degree calculation methods. In addition to these three algorithms, other algorithms that can be used to represent the matching degree between the first interface information and the second interface information are also included. Specifically, the user can select a suitable matching method to calculate the matching degree between the two according to the actual representation of the first interface information and the second interface information. The matching degree calculation method is not limited here.
[0093] Continue to see Figure 3A , and the description continues with step 102 above.
[0094] In step 103, based on the matching degree, a first reference test case is screened out from the reference test cases.
[0095] In some embodiments, Figure 3A The illustrated step 103 can be implemented through the following process, which is described in detail below.
[0096] Based on the matching degree, a first reference test case whose matching degree meets a preset matching condition is selected from the reference test cases, wherein the preset matching condition includes at least one of the following: the matching degree is the maximum, and the matching degree is greater than a preset matching threshold.
[0097] In some embodiments, after calculating the degree of match between the first interface information and the second interface information of N reference test cases, the second interface information with the greatest degree of match with the first interface information can be determined based on the N degrees of match, and the reference test case corresponding to the second interface information with the greatest degree of match can be used as the first reference test case.
[0098] In other embodiments, if only the maximum matching degree is used as the preset matching condition without considering the size of the matching degree, the second interface information in the determined first reference test case may not actually completely match the first interface information, and the test cases included in the first reference test case are not suitable for testing the interface to be tested. Therefore, a preset matching threshold can be set, and among the N matching degrees, the second interface information whose matching degree with the first interface information is greater than the preset matching threshold is determined, and the reference test case corresponding to the second interface information whose matching degree is greater than the preset matching threshold is used as the first reference test case of the interface to be tested.
[0099] In other embodiments, the maximum matching degree and the matching degree greater than the preset matching threshold value may be used as preset matching conditions. Based on N matching degrees, if it is determined that there are multiple second interface information with matching degrees greater than the preset matching threshold value, the second interface information with the maximum matching degree with the first interface information may be determined from the multiple second interface information with matching degrees greater than the preset matching threshold value, and the reference test case corresponding to the second interface information may be used as the first reference test case of the interface to be tested.
[0100] Continue to see Figure 3A , and the description continues with step 103 above.
[0101] In step 104, if the first reference test case is associated with a first test case generation instruction, a target test case of the interface to be tested is generated based on the first test case generation instruction.
[0102] The use case generation instruction is used to indicate the generation rules and generation format of the test case.
[0103] In some embodiments, see Figure 3B ,exist Figure 3A Before executing step 104 shown, steps 105 to 107 may also be executed, which are described in detail below.
[0104] In step 105, the association relationship between the reference test case and the case generation instruction is obtained.
[0105] In actual applications, a relationship is pre-established between reference test cases and case generation instructions, and this relationship can be stored in a table. The case generation instruction is used to indicate the generation rules and generation format of the test case. A case generation instruction can be associated with one reference test case or multiple reference test cases. However, a reference test case can only be associated with one case generation instruction.
[0106] As an example, for the interfaces of the query category, use case generation instructions used by the query class interfaces can be constructed, and the generation rules in the use case generation instructions of the query class can be applied to the generation of test cases for all interfaces of the query class in the corresponding test scenario. If there are multiple interfaces belonging to the query class in the test scenario, and the input parameters and other conditions of the test cases of the multiple interfaces are the same, then a reference test case can be constructed for the multiple interfaces of the query class, and the reference test case has an associated relationship with the use case generation instructions of the query class. If there are multiple interfaces belonging to the query class in the test scenario, and the input parameters and other conditions of the test cases of the multiple interfaces are different, then a reference test case can be constructed for each interface separately, and these reference test cases can establish an associated relationship with the use case generation instructions of the query class.
[0107] In step 106, the association relationship is queried based on the first reference test case.
[0108] Here, after obtaining the association relationship between the reference test case and the use case generation instruction, the association relationship can be queried based on screening out the first reference test case to query whether there is a use case generation instruction associated with the first reference test case.
[0109] In step 107, if a use case generation instruction corresponding to the first reference test case is found, it is determined that the first reference test case is associated with the first use case generation instruction, and the found use case generation instruction is used as the first use case generation instruction.
[0110] Here, if a case generation instruction associated with the first reference test case is found based on the association relationship, the found case generation instruction can be used as the first case generation instruction of the first reference test case. The first case generation instruction includes a generation rule and a generation format for instructing the generation of a test case for the interface to be tested.
[0111] Through the above embodiment, when an interface test case is generated for the interface to be tested, the first interface information of the interface to be tested and the second interface information of the pre-built reference test case are obtained, and based on the matching degree of the first interface information and the second interface information, the first reference test case can be screened out from the reference test case. In the case where the first reference test case is associated with a first case generation instruction, the target test case of the case to be tested can be directly generated based on the first case generation instruction. In the above manner, since the first case generation instruction is suitable for generating a test case that is consistent with the first reference test case, and the first reference test case is a test case suitable for testing the interface to be tested, the accuracy of the target test case generated for the interface to be tested can be improved through the first case generation instruction.
[0112] In some embodiments, see Figure 3C , Figure 3A The step 104 shown can be implemented by following the steps 1041A to 1043A, which are described in detail below.
[0113] In step 1041A, the target generation rule and the target generation format included in the first use case generation instruction are obtained.
[0114] In some embodiments, when the first reference test case is associated with a first use case generation instruction, a target generation rule and a target generation format included in the first use case generation instruction are obtained.
[0115] In step 1042A, a test case is constructed based on the target generation rule and the first interface information to obtain an initial test case for the interface to be tested.
[0116] In some embodiments, the target generation rules may be used to describe the contents and test functions of the test case, etc. The server 200 may construct a test case for the interface to be tested by semantically understanding the target generation rules and combining the first interface information of the interface to be tested, and obtain an initial test case that complies with the target generation rules.
[0117] As an example, the target generation rule can be described as "Please design test cases for functional testing, test cases for performance testing, and test cases for security testing for the interface to be tested based on the first interface information obtained for the interface to be tested. Each test case may include: case name, API address, request method, interface input parameters, and interface response parameters." The server 200 constructs target test cases for the interface to be tested by semantically understanding the target generation rules and combining the obtained first interface information. The target test cases may cover multiple test cases for the function, performance, security, etc. of the interface to be tested.
[0118] In step 1043A, the format of the initial test case is converted based on the target generation format to obtain a target test case that conforms to the target generation format.
[0119] In some embodiments, a target generation format is used to indicate an output format of a test case.
[0120] As an example, if the target generation format indicates that the test case is output in the format of a JSON document, the target generation format can be described as "the test case is output in JSON format, with the test case name as the key in the JSON object, and the format of the test case is as follows:
[0121]
[0122] The initial test case constructed by the server 200 based on the target generation rule may be a plurality of records including “case name, API address, request method, interface input parameters, interface response parameters” and the like.
[0123] As an example, the initial test case can be expressed as "Use case name: xxx, API address: xxx, request method: xxx, interface response parameters: xxx."
[0124] If the target generation format indicates that the test case is output in the format of a JSON document, the initial test case may be converted based on the format example given in the target generation format to obtain a target test case that conforms to the target generation format.
[0125] In other embodiments, see Figure 3D , Figure 3AThe illustrated step 104 may also be implemented by the following steps 1041B to 1042B, which are described in detail below.
[0126] In step 1041B, the target model identifier, target generation rule and target generation format in the first use case generation instruction are obtained.
[0127] In some embodiments, given that the language model learns a large amount of language data, understands the relationship between words and grammatical structures, and is thus able to generate natural and fluent text, in order to improve the quality of test case generation, the target generation rules in the first case generation instructions can be understood through the language model, and the target test case that conforms to the target generation format can be constructed through the language model.
[0128] Therefore, the model identifier can be configured in the use case generation instruction. The model identifier can be the name of the language model, which is obtained according to the enumeration value. Different use case generation instructions can configure different model identifiers of language models. The corresponding language model can be called through the model identifier to improve the generation efficiency of test cases through the language model, and the generation quality of test cases can be improved with the help of the semantic analysis ability of the language model.
[0129] After determining the first use case generation instruction of the interface to be tested, the target model identifier, target generation rule and target generation format configured in the first use case generation instruction are obtained.
[0130] In step 1042B, a language model corresponding to the target model identifier is used to perform test case prediction based on the first interface information, target generation rules, and target generation format to obtain a target test case.
[0131] Here, after obtaining the target model identifier, target generation rules and target generation format configured in the first use case generation instruction, the language model corresponding to the target model identifier can be called, and the target generation rules, target generation format, and the first interface information of the interface to be tested can be input into the language model, so that the language model can perform test case prediction and obtain several target test cases for the interface to be tested.
[0132] In some embodiments, in order to improve the quality and coverage of target test cases predicted by the language model, the business requirement document corresponding to the interface to be tested can be obtained, and the business content in the business requirement document can be input into the language model so that the language model can better understand the function of the interface to be tested and predict more comprehensive and accurate test cases.
[0133] In the case of generating the target test case by calling the language model, the instruction content in the first use case generation instruction may include generation rules and generation format. Among them, the generation rules may include project background, role playing, and construction requirements. Among them, the project background is used to enable the language model to better understand the background information of the development project in which the interface to be tested is located. The role playing is used to give the role that the language model needs to play and introduce what it needs to do. For example: As a senior test engineer, please design an interface test case for the interface to be tested based on the first interface information of the interface to be tested and the business information of the interface to be tested. The construction requirements are used to describe what method is used to design the test case and describe the content that the test case needs to include, such as "use case name, API address, request method, interface input parameters, interface response parameters" and other content.
[0134] In some embodiments, the use case generation instruction may also include three parts: instruction name, instruction category, and description. The instruction name is a unique identifier of the use case generation instruction, which is used to verify the uniqueness of the use case generation instruction. The instruction category is used to indicate the category of the instruction, which can be used to classify the use case generation instruction based on the instruction category for subsequent management, search, and use. The description is used to indicate what type of interface the use case generation instruction is applicable to.
[0135] As an example, if the interface to be tested is a query interface, the corresponding first use case generation instruction is an instruction for the query class. Then the first use case generation instruction may include:
[0136] Command name: query class interface command;
[0137] Model identification: language model 1;
[0138] Instruction category: query class interface use case generator;
[0139] Instruction content: {
[0140] Project background: XXXX;
[0141] Role: As a senior test engineer, please design interface test cases for the interface to be tested based on the first interface information and business information provided;
[0142] Construction requirements: Each test case includes: case name, API address, request method, interface input parameters, and interface response parameters;
[0143] Generated format: The test case is output in JSON format, with the test case name as the key in the JSON object. The format of the test case is as follows:
[0144]
[0145]
[0146] Description: This instruction is suitable for all query interfaces to generate interface test cases in the above format.
[0147] After determining the first use case generation instruction of the interface to be tested, the target generation rule and target generation format in the first use case generation instruction, that is, part of the instruction content, and the first interface information and business information of the interface to be tested can be input into the language model whose model is identified as language model 1 by calling the language model whose model is identified as language model 1. The target test cases predicted and output by the language model can be shown in Table 1.
[0148] Table 1
[0149]
[0150] It should be noted that XXX, X1, X2, Y1, Y2, etc. in the above Table 1 are all schematic descriptions.
[0151] In the above manner, by calling the language model, the language model is combined with the use case generation instruction and the first interface information to construct the target test case for the interface to be tested, which can improve the generation efficiency of the interface test case, reduce the error rate, and provide a better personalized user experience. In addition, for different test case generation requirements of the interface to be tested, different use case generation instructions can be constructed through natural language, which is highly maintainable and reduces the threshold for use.
[0152] In some embodiments, see Figure 3E ,exist Figure 3A Before executing step 101 shown, steps 108 to 111 may also be executed to establish an association relationship between the reference test case and the corresponding test case generation instruction, which is described in detail below.
[0153] In step 108, the instruction content included in the pre-built use case generation instruction and the second reference test case pre-associated with the use case generation instruction are obtained.
[0154] The instruction content includes model identification, generation format and generation rules.
[0155] In actual applications, pre-built use case generation instructions and pre-built reference test cases may be pre-associated.
[0156] As an example, if a test case generation instruction for instructing to generate a test case for a query class interface is pre-built for the interface category of the query class, a reference test case is pre-built for interface 1 having a query function. Since interface 1 has a query function and can be classified as a query class interface, the reference test case pre-built for interface 1 can be pre-associated with the test case generation instruction pre-built for the query class interface.
[0157] However, different software projects or different software systems may be configured with interfaces with query functions, but the pre-built use case generation instructions for query interfaces are not completely applicable to interfaces with query functions in all projects. Therefore, the pre-association relationship between the use case generation instructions and the reference test cases can also be verified and adjusted to improve the accuracy of the association relationship between the use case generation instructions and the reference test cases, so that the interface to be tested that matches the reference test case can use a more appropriate use case generation instruction to generate a target test case, thereby improving the accuracy of the target test case.
[0158] In some embodiments, for any pre-built use case generation instruction, the following steps are performed: obtaining instruction content included in the pre-built use case generation instruction and a second reference test case pre-associated with the use case generation instruction, wherein the instruction content includes a model identifier, a generation format, and a generation rule.
[0159] In step 109, test case prediction is performed based on the language model corresponding to the model identifier and the generation format, generation rules and the third interface information of the second reference test case to obtain a first predicted test case.
[0160] In some embodiments, the third interface information in the second reference test case is obtained. The second reference test case may be constructed based on a fixed format, and the third interface information is structured information in the reference test case.
[0161] As an example, if the second reference test case is constructed for "Interface 1", the third interface information in the second reference test case is as follows:
[0162] {Interface name: Interface 1
[0163] API address: / XXX / XXX / XXX / XXX
[0164] Interface input parameter information:
[0165] Fields Field Type describe Grouping Integer When the field is empty, it is not grouped. Primary Key Integer The primary key ID is not transmitted when creating a new one, but is uploaded when updating. Business word String Use # to describe business words, and it cannot be empty
[0166] }
[0167] By calling the language model corresponding to the model identifier in the use case generation instruction, the generation format, generation rules in the use case generation instruction and the third interface information in the second reference test case are passed into the language model, so that the language model predicts the test case based on the generation format, generation rules and the second interface information to obtain the first predicted test case.
[0168] In step 110, the second reference test case is compared with the first prediction test case to obtain a first comparison result.
[0169] In some embodiments, after the language model generates a first prediction test case for the interface pointed to by the third interface information, if it is necessary to determine whether the first prediction test case is accurate or appropriate, the first prediction test case can be compared with the second reference test case to obtain a first comparison result.
[0170] In step 111, if the first comparison result indicates that the difference between the second reference test case and the first predicted test case exceeds a first difference threshold, the instruction content included in the use case generation instruction or at least one of the second reference test cases pre-associated with the use case generation instruction is adjusted, and the adjusted use case generation instruction is associated with the second reference test case.
[0171] Since the second reference test case is a test case specially designed for the interface pointed to by its third interface information, the second reference test case is a test case suitable for testing the interface pointed to by its third interface information.
[0172] If the first comparison result indicates that the difference between the first predicted test case and the second reference test case exceeds the first difference threshold, it means that the use case generation instruction pre-associated with the second reference test case is not suitable for generating a test case that conforms to the second reference test case. Therefore, it is necessary to adjust the association relationship between them or adjust the instruction content of the use case generation instruction.
[0173] In some embodiments, the first prediction test case and the second reference test case are compared, and the difference between the interface input parameters and the interface response parameters between the first prediction test case and the second reference test case can be compared, or the difference between the two can be determined by comparing whether the first prediction test case can cover the second reference test case. The first difference threshold can be set according to actual conditions and is not limited here.
[0174] In some embodiments, if the first comparison result indicates that the difference between the two exceeds a first difference threshold, the instruction content included in the use case generation instruction is adjusted, which may include: adjusting the model identifier in the use case generation instruction to replace the language model used; or adjusting the generation rules in the instruction content.
[0175] As an example, adjusting the generation rules in the instruction content may include: adding descriptions such as "using test case design methods: equivalence class partitioning, boundary value analysis, error guessing method" to the generation rules, so that the language model can generate more comprehensive test cases based on the generation rule predictions.
[0176] In some embodiments, "adjusting at least one of the second reference test cases pre-associated with the use case generation instruction" in step 111 can be achieved through the following process: determining the interface type corresponding to the use case generation instruction, and obtaining a third reference test case under the interface type; using the language model corresponding to the model identifier, predicting the test case based on the generation format, generation rules and fourth interface information of the third reference test case to obtain a second predicted test case; comparing the third reference test case with the second predicted test case to obtain a second comparison result; if the second comparison result indicates that the difference between the third reference test case and the second predicted test case is less than a second difference threshold, adjusting the second reference test case to the third reference test case.
[0177] In some embodiments, there may be multiple interfaces with the same interface type, but in different software projects and different software systems, the test cases applicable to the interfaces may be different. Therefore, reference test cases may be constructed for different interfaces of the same interface type. Therefore, the second reference test case pre-associated with the use case generation instruction may be adjusted, and a third reference test case applicable to the use case generation instruction may be determined and associated with the use case generation instruction.
[0178] In some embodiments, the interface type corresponding to the use case generation instruction is determined, for example, based on the description or instruction name in the use case generation instruction, it is determined that the use case generation instruction is an instruction constructed for an interface of the interface type "query class". A third reference test case that is different from the second reference test case and belongs to the interface type is obtained. By calling the language model corresponding to the model identifier in the use case generation instruction, a test case is predicted based on the generation rules, the generation format, and the fourth interface information in the third reference test case, to obtain a second predicted test case. The comparison method of the second predicted test case and the third reference test case can refer to the comparison method between the first predicted test case and the second reference test case mentioned above, which will not be repeated here.
[0179] If the second comparison result indicates that the difference between the third reference test case and the second predicted test case is less than the second difference threshold, it indicates that the language model can generate a test case that matches the third reference test case based on the generation rules and generation format in the test case generation instruction, and the test case generation instruction is applicable to the interface pointed to by the fourth interface information in the third reference test case. Therefore, the second reference test case pre-associated with the test case generation instruction can be adjusted to the third reference test case, and an association relationship between the third reference test case and the test case generation instruction is established.
[0180] In other embodiments, "adjusting at least one of the second reference test cases pre-associated with the use case generation instruction" in step 111 can also be achieved through the following process: determining the interface type corresponding to the use case generation instruction, and obtaining a third reference test case under the interface type; based on the third reference test case and the use case generation instruction, training the language model corresponding to the model identifier to obtain the training result of the language model corresponding to the model identifier; if the training result meets the preset training effect, adjusting the second reference test case pre-associated with the use case generation instruction to the third reference test case.
[0181] In some embodiments, if the first comparison result indicates that the difference between the first predicted test case and the second reference test case exceeds the first difference threshold, it indicates that the first predicted test case predicted by the language model does not match the second reference test case, or the quality of the first predicted test case is relatively poor. This situation may be caused by poor language model training effect, or it may be caused by the generation rule in the case generation instruction not being applicable to the interface pointed to by the third interface information in the second reference test case.
[0182] Therefore, the language model corresponding to the model identifier in the use case generation instruction can be trained based on the second reference test case or a third reference test case that is different from the second reference test case under the interface type, and a reference test case whose training result meets the preset training effect is determined as the second reference test case pre-associated with the use case generation instruction.
[0183] In some embodiments, a third reference test case different from the second reference test case under the interface type is obtained, and for any third reference test case, the following process is performed: through the language model corresponding to the model identifier in the use case generation instruction, the generation rules, generation format, fourth interface information in the third reference test case, and interface input parameters in the use case generation instruction are used as inputs of the language model, and the predicted test case is used as the output to train the language model to obtain a training result. When the training result indicates that the difference between the predicted response parameters of the predicted test case output by the language model and the interface response parameters in the third reference test case is less than a third difference threshold, it is determined that the training result meets the preset training effect. Determine the third reference test case whose training result meets the preset training effect, and adjust the second reference test case pre-associated with the use case generation instruction to the third reference test case.
[0184] Through the above embodiment, by calling the language model corresponding to the model identifier in the use case generation instruction, based on the generation rules, generation format and the third interface information in the second reference test case in the use case generation instruction, test case prediction is performed, and according to the comparison result between the first predicted test case and the second reference test case of the language model, the instruction content in the use case generation instruction or the second reference test case corresponding to the use case generation instruction is adjusted, so that the correspondence between the reference test case and the use case generation instruction is more accurate, so that the language model corresponding to the model identifier in the use case generation instruction generates the first predicted test case more consistent with the second reference test case. Moreover, the second reference test case is a test case applicable to the interface pointed to by its second interface information. Therefore, in this way, when generating test cases for the interface to be tested, the first use case generation instruction that is more matched with the interface to be tested can be determined, and the target test case generated by the first use case generation instruction is more applicable to the interface to be tested, thereby improving the accuracy and quality of the target test case.
[0185] It can be understood that the second interface information, the third interface information, and the fourth interface information in the embodiment of the present application are only used to distinguish the different reference test cases they correspond to.
[0186] In some embodiments, Figure 3A After the execution of step 103 shown, the following operations can also be performed: if the first reference test case is not associated with the first use case generation instruction, obtain the second use case generation instruction; wherein the second use case generation instruction is a general use case generation instruction, or the similarity between the test scenario applicable to the second use case generation instruction and the first use case generation instruction exceeds a similarity threshold; based on the second use case generation instruction, generate a target test case for the interface to be tested.
[0187] In actual applications, if no applicable first use case generation instruction is configured for the interface to be tested, that is, if there is no associated first use case generation instruction for the first reference test case that matches the interface to be tested based on the association relationship, the use case generation instruction can be specified as the second use case generation instruction, and the target test case for the interface to be tested is generated based on the second use case generation instruction.
[0188] In one achievable manner, the second use case generation instruction may be specified as a general use case generation instruction. The general use case generation instruction is configured to be applicable to all types of interfaces to generate test cases. A general use case generation instruction is constructed as a fallback instruction for automated testing of interfaces. When the first reference test case of the instruction to be tested is not associated with a first use case generation instruction, or when there is no matching first reference test case for the instruction to be tested, the general use case generation instruction may be directly specified as a fallback instruction, that is, as a second use case generation instruction, and a target test case of the interface to be tested is generated based on the second use case generation instruction.
[0189] In another achievable manner, since each use case generation instruction is configured with information such as instruction category and instruction description, therefore, when the first reference test case is not associated with the first use case generation instruction, its test scenario can be analyzed based on the business information of the interface to be tested, such as the software project it is in, the interface category it belongs to, etc. By performing semantic analysis on the above information, a second use case generation instruction can be determined in the pre-built use case generation instruction as a use case generation instruction for generating a target test case for the interface to be tested. Among them, the similarity between the test scenario applicable to the second use case generation instruction and the first use case generation instruction exceeds the similarity threshold, which may include but is not limited to the following situations: the second use case generation instruction and the first use case generation instruction are both constructed for the same type of interface of the same software project, but the generation formats configured in the second use case generation instruction and the first use case generation instruction are different.
[0190] As an example, in some software projects, there may be some special class interfaces, for example, some fields in the request header of the special class interface need to be encrypted. For such interfaces, it may not be possible to build applicable use case generation instructions, or the accuracy of the test cases generated by the language model based on the use case generation instructions built for the special class interface is low. When it is necessary to generate test cases for such special class interfaces, the general use case generation instruction can be directly specified as the second use case generation instruction, and a general test case can be generated for the special class interface based on the general use case generation instruction.
[0191] In some embodiments, after "generating a target test case for the interface to be tested" is executed, the following operations can also be performed: if the format of the target test case does not meet the target generation format or there is a format error in the target test case, the target test case is formatted and corrected until the number of format checks on the target test case exceeds a preset number, and then the interface to be tested is marked.
[0192] In practical applications, the target generation format is the format used when generating a target test case for the interface to be tested. For example, when generating a target test case based on a first case generation instruction, the target generation format is the generation format included in the first case generation instruction; when generating a target test case based on a second case generation instruction, the target generation format is the generation format included in the second case generation instruction.
[0193] In some embodiments, after generating the target test case of the interface to be tested based on the first use case generation instruction or the second use case generation instruction, the generated target test case can be processed secondary, that is, format correction and format verification are performed to obtain a more standardized test case set.
[0194] As an example, if the target generation format used requires the test cases to be output in JSON format, and the format of the target test cases output by the language model is not in JSON format, or the JSON format of some test cases output by the language model is incorrect, for example, some test cases in the returned JSON format contain Chinese punctuation marks. In this case, the target test cases need to be formatted correctly. Exemplarily, the target test cases that are not in JSON format are converted to JSON format; or, the target test cases with format errors are formatted correctly, for example, the Chinese punctuation marks in the JSON document are replaced with corresponding English punctuation marks.
[0195] After the target test case is formatted, the target test case is formatted again to determine whether it conforms to the target generation format. If the format check still fails, the target test case can be formatted again, or the language model can be re-called to regenerate the target test case. Then the target test case is formatted again. If, through the above process, the number of format checks on the target test case exceeds the preset number of times, it still indicates that the target test case does not conform to the target generation format, then the interface to be tested can be marked, exemplarily, the interface to be tested is marked as "failed to generate test case". Among them, the preset number of times can be set according to actual needs and is not limited here.
[0196] In a specific embodiment, the intelligent quality inspection system is a Web project. There are many customers who use the integrated system and the project iteration frequency is high. In order to reduce the regression time before going online, the intelligent quality inspection system implements automated testing of interfaces through existing or self-developed test frameworks. In automated testing, the most time-consuming part is writing a set of test cases in the format specified by the interface. The embodiment of the present application uses a language model to construct use case generation instructions and reference test cases to achieve automatic construction of test cases for the interface to be tested.
[0197] See also Figure 4 The embodiment of the present application constructs a language model automatic interface test case generation platform, which includes: an instruction library 510, an interface market 520, a policy center 530, and a use case set 540. Among them, the instruction library 510 supports the creation and debugging of use case generation instructions; the interface market 520 is used to manage the first interface information of each interface, and each interface corresponds to a record (first interface information) in the interface market 520; the policy center 530 is used to build tasks, driving the language model to generate interface test cases according to the use case generation instructions; the use case set 540 is used to manage the interface test cases generated by the language model, supports viewing and downloading test cases, and also supports format conversion of test cases. The following is a detailed description of each module of the platform.
[0198] 1. Instruction library 510. Instruction library 510 mainly includes two functions: managing use case generation instructions and debugging use case generation instructions, including adding, deleting, modifying and checking a single use case generation instruction. A use case generation instruction contains five parts: "instruction name, large model name (the above-mentioned model identifier), instruction category, instruction content, and description". Among them, the instruction content generation rules and generation format, the generation rules can include project background, role playing, and construction requirements. The specific introduction is as follows:
[0199] 1) Instruction name: customized as needed, with uniqueness check in the instruction library 510.
[0200] 2) Model name: obtained based on the enumeration value, supports configuration, such as chatGPT3.5, chatGPT4.0.
[0201] 3) Instruction category: It can be customized and is mainly used to generate instruction categories for all use cases in the instruction library 510 to facilitate subsequent search and use.
[0202] 4) Instruction content: Instructions for instructing the language model on how to generate test cases. The embodiment of the present application is mainly about the application of generating interface test cases. The instruction content may include the following aspects:
[0203] a. Project background. The background is mainly for the language model to better understand the background information of the project.
[0204] b. Play a role, describe the role that the language model needs to play, and introduce what the language model needs to do, such as: As a senior test engineer, please design interface test cases for the interface based on the provided interface information and business information.
[0205] c. Construction requirements, which are used to describe what methods are used to design test cases and what the test cases need to include, such as "case name, API address, request method, interface input parameters, interface response parameters" and so on.
[0206] d.Generate format, specify the output format of the test case.
[0207] 5) Description: Used to indicate what type of interface this use case generation instruction applies to.
[0208] It should be noted that case data (equivalent to the above-mentioned reference test cases) are pre-built for different interfaces, and there is an association between the use case generation instructions and the case data in the instruction library 510.
[0209] 2. The interface mart 520 is mainly used to manage interface information (the first interface information corresponding to the interface). The interface mart 520 supports maintaining multiple versions of interface information. In the interface mart 520, the interface name and the interface version serve as unique identifiers in the interface mart 520. One interface corresponds to a record in the interface mart 520, and each record contains "interface version, interface module, interface name, API address, request header, request input parameters, interface response information". The interface mart 520 supports multiple data sources.
[0210] Interface data source:
[0211] 1) Manually created interface information;
[0212] 2) Interface information for importing Excel files;
[0213] 3) Interface information obtained from the swagger address.
[0214] 3. The policy center 530 is mainly used to create tasks for generating interface test cases. When creating a task, you can specify an interface range and a fallback instruction. When the task is executed, first, according to the interface range, all the interfaces to be tested that need to generate interface test cases are obtained from the interface mart 520; secondly, the first use case generation instruction is automatically matched from the instruction library 510 as the best instruction for each interface to be tested. If the best instruction is matched, the first use case generation instruction is used to generate the target test case for the interface to be tested; if the best instruction is not matched, the fallback instruction is used to generate the target test case for the interface to be tested. Each task only supports execution once. After creating and saving the task, the default task is disabled and needs to be manually enabled. The task takes effect immediately after the specified time is enabled to generate the target test case data set for the interface to be tested.
[0215] 4. Use case set 540: The original data of the use case set 540 is the test case data generated according to the tasks constructed by the policy center 530, and supports downloading in multiple formats.
[0216] In some embodiments, before the automated interface test case generation platform is officially enabled, each use case generation instruction in the instruction library 510 may also be debugged.
[0217] The instruction library 510 supports online debugging of a single use case generation instruction. The debugging of a single use case generation instruction requires the instruction content in the use case generation instruction and the case data pre-associated with the use case generation instruction to be passed in. The model result can be obtained by calling the language model, and the instruction content is repeatedly adjusted according to the returned model result, or the case data pre-associated with the use case generation instruction is adjusted until the language model can return a satisfactory result to the user according to the instruction content. The case data here refers to the data that needs to be tested by the language model (equivalent to the second interface information in the above-mentioned second reference test case), and the data must be structured data. See the description of the second interface information in the above-mentioned embodiment for details.
[0218] Debugging the use case generation instructions can include any of the following methods:
[0219] 1) Add a method for designing test cases in the instruction content: compare the test cases returned by the language model (i.e., the first predicted test cases mentioned above) with the test cases in the case data (equivalent to the second reference test cases mentioned above) to determine whether the test cases returned by the language model have basically covered the test cases in the case data. If not, add "use test case design methods: equivalence class partitioning, boundary value analysis, error guessing method" and other content to the instruction content.
[0220] 2) Specify case data (pre-trained data) for the use case generation instruction: Specify case data (equivalent to the third reference test case mentioned above) for the interface to be tested, pre-train the language model based on the specified case data, and generate an interface test case for the interface to be tested based on the pre-trained language model. There are multiple case data for the interface to be tested in the case database, and each case data can be used as pre-trained data for the language model. After multiple debugging, find the case data with the best pre-training effect as the pre-trained data for the use case generation instruction, and associate the case data with the use case generation instruction.
[0221] The language model is a machine learning model that can use a large amount of data and algorithms to analyze problems. By continuously training the language model through various case data, a customized model corresponding to the use case generation instruction can be obtained, and test cases with various data forms and contents that meet the requirements of the use case generation instruction can be generated. Using such a language model can greatly improve production efficiency, reduce error rates, and provide a better personalized user experience. Different use case generation instructions can be written for test case generation requirements of different interfaces, and they are highly maintainable and support modification at any time and online debugging.
[0222] In some embodiments, if a business vocabulary management module is newly added to the software system, the module supports the functions of creating, editing, deleting, viewing, downloading, uploading, etc. Before the R&D submits the test, the interface definition (including the first interface information and the business requirement document) under the module has been maintained in swagger. Based on the interface information and business requirement document in swagger, the target test case set of the platform's automatic output interface is generated by relying on the automated interface test case before submitting the test, which is used for the interface automation test after the test is submitted.
[0223] See also Figure 5 The process of generating interface test cases for the interfaces under the business vocabulary management module may include the following steps:
[0224] In step 201, a task is created in the policy center.
[0225] The task specifies the fallback instruction to be used as "general class interface instruction", specifies the interface module as "lexicon management", saves and enables the task.
[0226] In step 202, first interface information of all interfaces to be tested is obtained.
[0227] After the above created task is enabled, firstly, the use case generation instruction with the instruction name of "general class interface instruction" is obtained from the instruction library 510 as a fallback instruction. Secondly, according to the interface module "lexicon management" configured in the task, all interface record information under the interface module is obtained from the interface market 520 to obtain the first interface information of all interfaces to be tested.
[0228] In step 203, the first interface information of the interface to be tested is matched with the second interface information of all case data to determine the best instruction of the interface to be tested.
[0229] Here, when matching, each interface to be tested is traversed, and a similarity algorithm is used to perform similarity matching based on the first interface information of the interface to be tested and the second interface information in the case data (such as the interface request method, API address, and interface input parameter), to find the case data with the highest matching value with the first interface information. Since the use case generation instruction and the case data have an association relationship, the first use case generation instruction associated with the case data with the highest matching value of the first interface information can be determined through the association relationship, and the first use case generation instruction determined by the method with the highest similarity matching value is used as the best instruction for the interface to be tested.
[0230] In step 204, if the best instruction for the interface to be tested is not determined, a fallback instruction is used to generate an interface test case for the interface to be tested.
[0231] If the best instruction is not obtained when performing similarity matching on the first interface information of the interface to be tested, the fallback instruction configured in the task is used as the best instruction for the interface. After all interfaces to be tested are traversed, there will be a corresponding best instruction. After obtaining the first interface information of the interface to be tested and the instruction content of the best instruction, the language model corresponding to the model name in the best instruction is called. The first interface information of the interface to be tested, the generation rules and generation format in the best instruction are passed into the language model to obtain the target test case for the interface to be tested.
[0232] In step 205, format correction and format verification are performed on the target test case.
[0233] Finally, the model results (target test cases for the interface to be tested) are processed twice to generate an interface test case set for the interface to be tested. The secondary processing includes "format correction" and "format verification".
[0234] Through the above embodiment, the interface test case is generated by the language model, and it is only necessary to write the case generation instruction for different interface types in the instruction library 510, and the interfaces under this interface type are applicable. The first interface information obtained from swagger and the business information extracted from the business requirements document are passed in, and the interface test case of the interface to be tested can be automatically generated by calling the language model. Different test case generation requirements only require the construction and maintenance of different case generation instructions, such as: Framework 1 supports interface test case sets in table format; Framework 2 supports interface test case sets in JSON format. Here, only two case generation instructions need to be built and maintained, and the two case generation instructions require the language model to output interface test cases in table format and interface test cases in JSON format respectively. The case generation instructions used by the language model are mainly described clearly in natural language. If the entire process is encapsulated as a framework, the user only needs to write the case generation instruction in the instruction library 510 of the platform, and provide the first interface information of each interface to be tested under the interface module required to generate the test case, and finally the interface test case set of the interface to be tested will be automatically generated. This method not only reduces the threshold for use, but also greatly improves the production efficiency of test cases, and the entire platform is easy to maintain.
[0235] The following continues to describe the exemplary structure of the interface test case processing device 455 provided in the embodiment of the present application implemented as a software module. In some embodiments, Figure 2 As shown, the software modules stored in the interface test case processing device 455 of the memory 440 may include:
[0236] An acquisition module 4551 is used to acquire first interface information of an interface to be tested and second interface information of a reference test case;
[0237] A matching module 4552, used to match the first interface information with the second interface information of the reference test case to obtain a matching degree between the first interface information and the second interface information;
[0238] A screening module 4553 is used to screen out a first reference test case from the reference test cases based on the matching degree;
[0239] The first generating module 4554 is configured to generate a target test case for the interface to be tested based on the first test case generating instruction if the first reference test case is associated with the first test case generating instruction.
[0240] In some embodiments, the matching module 4552 is also used to perform similarity matching on the first interface information and the second interface information of the reference test case to obtain the matching degree between the first interface information and each second interface information; or, to perform structured matching on the first interface information and the second interface information of the reference test case to obtain the structured matching degree between the first interface information and each second interface information; or, to perform semantic matching on the first interface information and the second interface information of the reference test case to obtain the semantic matching degree between the first interface information and each second interface information.
[0241] In some embodiments, the screening module 4553 is also used to screen out a first reference test case whose matching degree meets a preset matching condition from the reference test cases based on the matching degree; wherein the preset matching condition includes at least one of the following: the matching degree is maximum, and the matching degree is greater than a preset matching threshold.
[0242] In some embodiments, the interface test case processing device 455 also includes a query module. After the screening module 4553 filters out the first reference test case from the reference test cases, the query module is used to obtain the association relationship between the reference test case and the use case generation instruction; based on the first reference test case, the association relationship is queried; if a use case generation instruction corresponding to the first reference test case is queried, it is determined that the first reference test case is associated with the first use case generation instruction, and the queried use case generation instruction is used as the first use case generation instruction.
[0243] In some embodiments, the first generation module 4554 is also used to obtain the target generation rules and target generation format included in the first use case generation instruction; construct a test case based on the target generation rules and the first interface information to obtain an initial test case for the interface to be tested; and convert the format of the initial test case based on the target generation format to obtain a target test case that conforms to the target generation format.
[0244] In some embodiments, the first generation module 4554 is also used to obtain the target model identifier, target generation rules and target generation format in the first use case generation instruction; through the language model corresponding to the target model identifier, test case prediction is performed based on the first interface information, target generation rules and target generation format to obtain the target test case.
[0245] In some embodiments, the interface test case processing device 455 also includes an association module. Before the acquisition module 4551 acquires the first interface information of the interface to be tested and the second interface information of the reference test case, the association module is used to obtain the instruction content included in the pre-built use case generation instruction and the second reference test case pre-associated with the use case generation instruction, and the instruction content includes a model identifier, a generation format and a generation rule; through the language model corresponding to the model identifier, based on the generation format, the generation rule and the third interface information of the second reference test case, a test case prediction is performed to obtain a first predicted test case; the second reference test case is compared with the first predicted test case to obtain a first comparison result; if the first comparison result indicates that the difference between the second reference test case and the first predicted test case exceeds a first difference threshold, at least one of the instruction content included in the use case generation instruction or the second reference test case pre-associated with the use case generation instruction is adjusted, and the adjusted use case generation instruction is associated with the second reference test case.
[0246] In some embodiments, the association module is also used to determine the interface type corresponding to the use case generation instruction, and obtain a third reference test case under the interface type; through the language model corresponding to the model identifier, test case prediction is performed based on the generation format, generation rules and fourth interface information of the third reference test case to obtain a second predicted test case; the third reference test case is compared with the second predicted test case to obtain a second comparison result; if the second comparison result indicates that the difference between the third reference test case and the second predicted test case is less than a second difference threshold, the second reference test case is adjusted to the third reference test case.
[0247] In some embodiments, the interface test case processing device 455 also includes a second generation module. After the screening module 4553 filters out the first reference test case from the reference test cases, the second generation module is used to obtain a second use case generation instruction if the first reference test case is not associated with the first use case generation instruction; wherein the second use case generation instruction is a general use case generation instruction, or the degree of similarity between the test scenario applicable to the second use case generation instruction and the first use case generation instruction exceeds a similarity threshold; based on the second use case generation instruction, a target test case for the interface to be tested is generated.
[0248] In some embodiments, the interface test case processing device 455 also includes a verification and correction module. After generating a target test case for the interface to be tested, the verification and correction module is used to perform format correction on the target test case if the format of the target test case does not meet the target generation format or there is a format error in the target test case. The interface to be tested is marked when the number of format verifications on the target test case exceeds a preset number.
[0249] The embodiment of the present application provides a computer program product, which includes a computer program or a computer executable instruction, and the computer program or the computer executable instruction is stored in a computer-readable storage medium. The processor of the electronic device reads the computer executable instruction from the computer-readable storage medium, and the processor executes the computer executable instruction, so that the electronic device executes the processing method of the interface test case described in the embodiment of the present application.
[0250] The present application embodiment provides a computer-readable storage medium, in which computer executable instructions or computer programs are stored. When the computer executable instructions or computer programs are executed by a processor, the processor will execute the method for processing interface test cases provided by the present application embodiment, for example, Figure 3A The processing method of the interface test case is shown.
[0251] In some embodiments, the computer-readable storage medium may be a memory such as RAM, ROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; or may be various devices including one or any combination of the above memories.
[0252] In some embodiments, computer executable instructions may be in the form of a program, software, software module, script or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment.
[0253] As an example, computer-executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file that stores other programs or data, such as in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files storing one or more modules, subroutines, or code portions).
[0254] As an example, computer executable instructions may be deployed to be executed on one electronic device, or on multiple electronic devices located at one site, or on multiple electronic devices distributed at multiple sites and interconnected by a communication network.
[0255] In summary, through the above embodiments, when an interface test case is generated for the interface to be tested, by obtaining the first interface information of the interface to be tested and the second interface information of the pre-built reference test case, and based on the matching degree of the first interface information and the second interface information, the first reference test case can be screened out from the reference test case. In the case where the first reference test case is associated with the first case generation instruction, the target test case of the case to be tested can be directly generated based on the first case generation instruction. In the above manner, since the first case generation instruction is suitable for generating a test case that is consistent with the first reference test case, and the first reference test case is a test case suitable for testing the interface to be tested, the accuracy of the target test case generated for the interface to be tested can be improved through the first case generation instruction.
[0256] Moreover, to generate interface test cases through the language model, it is only necessary to write case generation instructions for different interface types in the instruction library, and all interfaces under this interface type are applicable. The first interface information obtained from swagger and the business information extracted from the business requirements document are passed in, and the interface test cases of the interface to be tested can be automatically generated by calling the language model. Different test case generation requirements only require the construction and maintenance of different case generation instructions, such as: Framework 1 supports interface test case sets in table format; Framework 2 supports interface test case sets in JSON format. Here, only two case generation instructions need to be built and maintained, and the two case generation instructions require the language model to output interface test cases in table format and interface test cases in JSON format respectively. The case generation instructions used by the language model can be clearly described mainly in natural language. If the entire process is encapsulated as a framework, the user only needs to write the case generation instructions in the platform's instruction library, and provide the first interface information of each interface to be tested under the interface module for generating the test case, and finally the interface test case set of the interface to be tested will be automatically generated. This method not only reduces the threshold for use, but also greatly improves the production efficiency of test cases, and the entire platform is easy to maintain.
[0257] The above is only an embodiment of the present application and is not intended to limit the protection scope of the present application. Any modifications, equivalent substitutions and improvements made within the spirit and scope of the present application are included in the protection scope of the present application.
Claims
1. A method for processing an interface test case, characterized in that: The method comprises: Obtain first interface information of the interface to be tested and second interface information of the reference test case; Matching the first interface information with the second interface information of the reference test case to obtain a matching degree between the first interface information and the second interface information; Based on the matching degree, selecting a first reference test case from the reference test cases; If the first reference test case is associated with a first test case generation instruction, a target test case of the interface to be tested is generated based on the first test case generation instruction.
2. The method according to claim 1, characterized in that: The matching of the first interface information with the second interface information of the reference test case to obtain a matching degree between the first interface information and the second interface information includes: Performing similarity matching on the first interface information and the second interface information of the reference test case to obtain a similarity matching degree between the first interface information and each of the second interface information; or, Performing structural matching on the first interface information and the second interface information of the reference test case to obtain a structural matching degree between the first interface information and each of the second interface information; or, Semantic matching is performed on the first interface information and the second interface information of the reference test case to obtain a semantic matching degree between the first interface information and each of the second interface information.
3. The method according to claim 1, characterized in that The step of selecting a first reference test case from the reference test cases based on the matching degree includes: Based on the matching degree, selecting a first reference test case whose matching degree meets a preset matching condition from the reference test cases; The preset matching condition includes at least one of the following: a maximum matching degree and a matching degree greater than a preset matching threshold.
4. The method according to claim 1, characterized in that: After the first reference test case is screened out from the reference test cases, the method further includes: Obtain the association relationship between reference test cases and test case generation instructions; Based on the first reference test case, query the association relationship; If a use case generation instruction corresponding to the first reference test case is found, it is determined that the first reference test case is associated with the first use case generation instruction, and the found use case generation instruction is used as the first use case generation instruction.
5. The method according to claim 1, characterized in that The generating the target test case of the interface to be tested based on the first test case generating instruction includes: Obtaining a target generation rule and a target generation format included in the first use case generation instruction; Constructing a test case based on the target generation rule and the first interface information to obtain an initial test case for the interface to be tested; Based on the target generation format, the initial test case is converted into a format to obtain a target test case that conforms to the target generation format.
6. The method according to claim 1, characterized in that The generating the target test case of the interface to be tested based on the first test case generating instruction includes: Obtaining a target model identifier, a target generation rule, and a target generation format in the first use case generation instruction; The language model corresponding to the target model identifier is used to perform test case prediction based on the first interface information, the target generation rule and the target generation format to obtain a target test case.
7. The method according to claim 1, characterized in that The reference test case is associated with a test case generation instruction. Before obtaining the first interface information of the interface to be tested and the second interface information of the reference test case, the method further includes: Obtaining instruction content included in a pre-built use case generation instruction and a second reference test case pre-associated with the use case generation instruction, wherein the instruction content includes a model identifier, a generation format, and a generation rule; Using the language model corresponding to the model identifier, based on the generation format, the generation rule and the third interface information of the second reference test case, test case prediction is performed to obtain a first predicted test case; Comparing the second reference test case with the first prediction test case to obtain a first comparison result; If the first comparison result indicates that the difference between the second reference test case and the first predicted test case exceeds a first difference threshold, the instruction content included in the use case generation instruction or at least one of the second reference test cases pre-associated with the use case generation instruction is adjusted, and the adjusted use case generation instruction is associated with the second reference test case.
8. The method according to claim 7, characterized in that The adjusting the second reference test case pre-associated with the use case generation instruction includes: Determine the interface type corresponding to the use case generation instruction, and obtain a third reference test case under the interface type; By using the language model corresponding to the model identifier, based on the generation format, the generation rule and the fourth interface information of the third reference test case, test case prediction is performed to obtain a second predicted test case; Comparing the third reference test case with the second prediction test case to obtain a second comparison result; If the second comparison result indicates that the difference between the third reference test case and the second predicted test case is less than a second difference threshold, the second reference test case is adjusted to the third reference test case.
9. The method according to claim 1, characterized in that: After the first reference test case is screened out from the reference test cases, the method further includes: If the first reference test case is not associated with the first use case generation instruction, obtaining a second use case generation instruction; The second use case generation instruction is a general use case generation instruction, or the similarity between the test scenarios applicable to the second use case generation instruction and the first use case generation instruction exceeds a similarity threshold; Based on the second use case generation instruction, a target test case for the interface to be tested is generated.
10. The method according to any one of claims 1 to 9, characterized in that: After generating the target test case of the interface to be tested, the method further includes: If the format of the target test case does not meet the target generation format or there is a format error in the target test case, the target test case is formatted and corrected until the number of format checks on the target test case exceeds a preset number, and the interface to be tested is marked.
11. A device for processing interface test cases, characterized in that: The device comprises: An acquisition module, used to acquire first interface information of the interface to be tested and second interface information of a reference test case; A matching module, used for matching the first interface information with the second interface information of the reference test case to obtain a matching degree between the first interface information and the second interface information; A screening module, configured to screen out a first reference test case from the reference test cases based on the matching degree; The first generating module is used to generate a target test case for the interface to be tested based on the first test case generating instruction if the first reference test case is associated with the first test case generating instruction.
12. An electronic device, characterized in that: The electronic device comprises: A memory for storing computer executable instructions; A processor, configured to implement the method according to any one of claims 1 to 10 when executing the computer executable instructions stored in the memory.
13. A computer-readable storage medium storing computer-executable instructions or a computer program, characterized in that: When the computer executable instructions or computer program are executed by a processor, the method according to any one of claims 1 to 10 is implemented.
14. A computer program product comprising computer executable instructions or a computer program, characterized in that When the computer executable instructions or computer program are executed by a processor, the method according to any one of claims 1 to 10 is implemented.
