Script testing method, device, equipment and storage medium

CN117909238BActive Publication Date: 2026-09-25PEOPLE'S INSURANCE COMPANY OF CHINA
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410083259.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-01-19
Publication Date
2026-09-25
Estimated Expiration
2044-01-19

AI Technical Summary

Technical Problem

[0005]本申请提供一种脚本测试方法、装置、设备及存储介质,用以解决接口测试脚本的验证过程效率较低的问题

Benefits of technology

[0017]本申请提供的脚本测试方法、装置、设备及存储介质,通过自动对待测试脚本进行静态分析,并在静态分析出现非正常情况下,对待测试脚本进行修正,实现避免后续进行场景测试的过程中出现异常,并由于采用了待测试脚本及对应的需求描述文件、接口说明文件,确定测试场景信息,实现得到全面的测试场景,对脚本中缺乏的测试场景进行补全,得到更加完整的测试结果,最后生成测试结果报告实现将测试结果直观的体现出来,由于整体流程不需要人工参与,增加了脚本的测试效率。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117909238B_ABST
    Figure CN117909238B_ABST
Patent Text Reader

Abstract

The application provides a script test method, device and equipment and a storage medium, and belongs to the technical field of data processing. The method comprises the following steps: obtaining a to-be-tested script, a requirement description file corresponding to the to-be-tested script and an interface specification file; performing static analysis on the to-be-tested script to obtain a static analysis result, wherein the static analysis result comprises an execution state; if the execution state is abnormal, modifying the to-be-tested script according to the static analysis result to obtain a new to-be-tested script; determining test scene information according to the to-be-tested script, the requirement description file and the interface specification file; determining a scene test result corresponding to the test scene information according to the to-be-tested script and the test scene information; and generating a test result report corresponding to the static analysis result and the scene test result. The method provided in the application solves the problem of low efficiency of the interface test script verification process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, and in particular to a script testing method, apparatus, device, and storage medium. Background Technology

[0002] Currently, a large amount of data is processed in computers and servers, which requires computers or servers to access the data. When new data needs to be accessed, corresponding interfaces need to be developed. The newly developed interfaces need to be verified by manually writing interface test scripts.

[0003] Currently, in existing technologies, the interface test scripts themselves also require manual verification for correctness.

[0004] However, the inventors have discovered that the existing technology has at least the following technical problems: the verification process of the current interface test script is inefficient. Summary of the Invention

[0005] This application provides a script testing method, apparatus, device, and storage medium to solve the problem of low efficiency in the verification process of interface test scripts.

[0006] Firstly, this application provides a script testing method, including:

[0007] Obtain the script to be tested, along with its corresponding requirement description file and interface specification file. Perform static analysis on the script to be tested to obtain the static analysis results, including the execution status. If the execution status is abnormal, modify the script to be tested based on the static analysis results to obtain a new script. Determine the test scenario information based on the script to be tested and its corresponding requirement description file and interface specification file. Determine the scenario test results based on the script to be tested and the test scenario information. Generate a test result report corresponding to the static analysis results and the scenario test results.

[0008] In one possible implementation, the test scenario information is determined based on the script to be tested and its corresponding requirements description file and interface specification file. This includes: determining the existing scenario information corresponding to the script to be tested; searching the interface development code repository based on the script to be tested to obtain the first scenario information; searching the interface requirements description library based on the requirements description file to obtain the second scenario information; and searching the interface specification document library based on the interface specification file to obtain the third scenario information. The different scenario information from the existing scenario information, the first scenario information, the second scenario information, and the third scenario information are collectively determined as the test scenario information.

[0009] In one possible implementation, based on the script to be tested, the interface development code library is searched to obtain the first scenario information, including: obtaining the feature information of the script to be tested; based on the feature information, the target test script in the interface development code library is searched; and the scenario information corresponding to the target test script is determined as the first scenario information.

[0010] In one possible implementation, the process of locating a target test script in the interface development codebase based on feature information includes: calculating the similarity between the script to be tested and at least one existing script in the interface development codebase based on the feature information. If the similarity to the target existing script is greater than a preset threshold, then the target existing script is identified as the target test script, where the target existing script is any existing script.

[0011] In one possible implementation, the test scenario information includes test input information and standard output information. Accordingly, based on the script to be tested and the test scenario information, the scenario test result corresponding to the test scenario information is determined, including: running the script to be tested using the test input information and obtaining the script execution result. If the script execution result is the same as the standard output information, it will be normally determined as the scenario test result corresponding to the test scenario information; otherwise, it will be abnormally determined as the scenario test result corresponding to the test scenario information.

[0012] In one possible implementation, the static analysis results also include error messages. Accordingly, the script to be tested is modified based on the static analysis results to obtain a new script, including: reading the script modification program corresponding to the error messages; and using the script modification program to modify the script to be tested to obtain the new script.

[0013] In one possible implementation, the test script is modified based on the static analysis results to obtain a new test script. This includes: reading the target generator corresponding to the static analysis results, where the target generator is a generator in a pre-trained generative adversarial network; inputting the test script into the target generator to obtain the output data of the target generator; and determining the new test script based on the output data.

[0014] Secondly, this application provides a script testing apparatus, comprising: a file acquisition module for acquiring a script to be tested and a corresponding requirement description file and interface specification file; a static analysis module for performing static analysis on the script to be tested to obtain static analysis results, wherein the static analysis results include execution status; a script modification module for modifying the script to be tested according to the static analysis results to obtain a new script to be tested if the execution status is abnormal; an information determination module for determining test scenario information based on the script to be tested and the corresponding requirement description file and interface specification file; a result determination module for determining the scenario test results corresponding to the test scenario information based on the script to be tested and the test scenario information; and a report generation module for generating a test result report corresponding to the static analysis results and the scenario test results.

[0015] Thirdly, this application provides an electronic device, including: a processor and a memory communicatively connected to the processor; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory, causing the processor to execute the script testing method as described in the first aspect.

[0016] Fourthly, this application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the script testing method as described in the first aspect.

[0017] The script testing method, apparatus, equipment, and storage medium provided in this application automatically perform static analysis on the script to be tested and correct the script in case of abnormalities in the static analysis, thereby avoiding anomalies during subsequent scenario testing. By using the script to be tested and the corresponding requirement description file and interface specification file, the test scenario information is determined, resulting in a comprehensive set of test scenarios. Missing test scenarios in the script are supplemented to obtain more complete test results. Finally, a test result report is generated to intuitively present the test results. Since the entire process does not require manual intervention, the efficiency of script testing is increased. Attached Figure Description

[0018] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0019] Figure 1 This is a schematic diagram illustrating an application scenario of the script testing method provided in the embodiments of this application;

[0020] Figure 2 A flowchart illustrating the script testing method provided in this application embodiment;

[0021] Figure 3This is a schematic diagram of the structure of the script testing device provided in the embodiments of this application;

[0022] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.

[0023] The accompanying drawings have illustrated specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to specific embodiments. Detailed Implementation

[0024] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.

[0025] Currently, large amounts of data are processed through computers and servers, requiring frequent data access. When new data needs to be accessed, developers need to create corresponding interfaces. To ensure the correctness of these interfaces, interface test scripts must be manually written for verification.

[0026] However, in existing technologies, the API test scripts themselves still require manual verification of their correctness. This results in low efficiency in the verification process of API test scripts.

[0027] To address the above technical problems, the inventors propose the following technical concept: perform static analysis on the script to be tested to obtain static analysis results; automatically modify the script to be tested based on the static analysis results if the static analysis results are abnormal; determine the test scenario by combining the script to be tested with the corresponding requirement description file and interface specification file; test the script to be tested using the obtained test scenario to obtain scenario test results; and generate a test result report by combining the static analysis results and scenario test results.

[0028] Figure 1 This is a schematic diagram illustrating an application scenario of the script testing method provided in the embodiments of this application. For example... Figure 1 In this scenario, the following components are included: database 101 and server 102.

[0029] In the specific implementation process, database 101 can include a single database or a combination of multiple databases. For example, it can be one or more databases such as Oracle, MySQL, DRDS (Distributed Relational Database Service), and ES (Elasticsearch). This application does not impose any special restrictions on this.

[0030] Server 102 can be implemented using a single server or a cluster of multiple servers with more powerful processing capabilities and higher security. Where possible, it can also be replaced by a computer or laptop with strong computing power.

[0031] The connection between server 102 and database 101 can be either wired or wireless.

[0032] Database 101 is used to store the scripts to be tested, the corresponding requirement description files, interface description files, test scenario information, etc.

[0033] Server 102 is used to read the test scripts, corresponding requirement description files, interface description files, test scenario information, etc. stored in database 101, and use this data to perform script testing.

[0034] It is understood that the structure illustrated in the embodiments of this application does not constitute a specific limitation on the script testing method. In other feasible embodiments of this application, the above architecture may include more or fewer components than illustrated, or combine some components, or split some components, or arrange different components, which can be determined according to the actual application scenario and is not limited here. Figure 1 The components shown can be implemented by hardware, software, or a combination of both.

[0035] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.

[0036] Figure 2 This is a flowchart illustrating the script testing method provided in an embodiment of this application. The execution entity of this embodiment may be... Figure 1 The server 102 in this embodiment can also be a computer and / or a mobile phone, etc., and this embodiment does not impose any special restrictions on it. Figure 2 As shown, the method includes:

[0037] S201: Obtain the script to be tested and the corresponding requirement description file and interface description file.

[0038] In this step, the corresponding requirement description file and interface specification file can be located based on the identifier of the script to be tested. The identifier of the script to be tested can be either the identifier of the test task or the identifier of the script itself. Alternatively, the requirement description file and interface specification file can be read from the storage location of the script to be tested. Obtaining the script to be tested can be achieved by polling the interface test script library to extract incremental interface test script information, or by receiving script test instructions, reading the script identifier from the script test instructions, and then using the script identifier to retrieve the script to be tested. The script to be tested can be a script used to test whether the interface functionality is normal, verifying whether the interface meets the functional requirements of normal and abnormal scenarios.

[0039] The requirements description file and interface specification file can be uploaded to the database by the requirements personnel and developers. The requirements description file includes the business background of the interface, the functions to be implemented, and the input parameters. The interface specification file includes the interface functionality, including the interface address, input parameters, business logic code, and output information. The interface functionality is implemented by the interface development code and may include code written in a computer programming language to implement the system interface functionality. It includes the interface address, input parameters, business logic code, and output information.

[0040] S202: Perform static analysis on the script to be tested to obtain the static analysis results, which include the execution status.

[0041] In this step, static analysis of the script to be tested may include inputting the script to be tested into a preset static analysis program and obtaining the static analysis results output by the static analysis program; it may also include breaking down the script to be tested into keywords, identifiers, operators, etc., and then determining whether the contents obtained from these breakdowns conform to specific syntax rules, and then determining the semantics of these contents, including whether variables, parameter functions and return values ​​have the correct types, etc.; it may also include code structure analysis and security vulnerability analysis.

[0042] Code structure analysis can include checking whether the code conforms to specific design patterns, whether there is redundant or duplicate code, or whether it can be optimized to improve performance. Security vulnerability analysis can include determining script readability, maintainability, and scalability. Execution status can include normal or abnormal; in the case of abnormal execution status, static analysis results may also include error messages.

[0043] S203: If the execution status is abnormal, modify the script to be tested based on the static analysis results to obtain a new script to be tested.

[0044] This step may include inputting the static analysis results and the script to be tested into a script modification program pre-written by the staff to obtain a new script to be tested.

[0045] S204: Determine the test scenario information based on the script to be tested and the corresponding requirement description file and interface specification file.

[0046] In this step, the script to be tested can be the original script that has a normal static analysis result, or a modified new script. This step may include: based on the content of the script to be tested, finding target test scripts with a similarity exceeding a first threshold, and determining the scenario information corresponding to the target test scripts as the first scenario information; based on the content of the requirement description file, finding target requirement description files with a similarity exceeding a second threshold, and determining the scenario information corresponding to the target requirement description files as the second scenario information; based on the content of the interface specification file, finding target interface specification files with a similarity exceeding a third threshold, and determining the scenario information corresponding to the target interface specification file as the third scenario information. The different scenario information from the first, second, and third scenario information is collectively determined as the test scenario information.

[0047] The test scenario information can include normal scenario information and abnormal scenario information. Scenario information represents information related to the usage scenario, which can include interface address, input parameters, interface feature information, etc.

[0048] S205: Based on the script to be tested and the test scenario information, determine the scenario test results corresponding to the test scenario information.

[0049] This step may include replacing the information in the test script with the test scenario information, running the replaced test script, and obtaining the scenario test results.

[0050] Specifically, replacing information in the test script with test scenario information can include determining the data type of the data in the test scenario information, replacing the data of the same data type in the script to be tested, thereby completing the replacement of information in the test script.

[0051] S206: Generate test result reports corresponding to static analysis results and scenario test results.

[0052] This step may include writing the static analysis results and scenario test results into a preset test result report template to obtain a test result report; it may also include writing the execution status, the modified content of the script to be tested, and the scenario test results into a preset test result report template when the execution status of the static analysis results is abnormal, to obtain a test result report.

[0053] As can be seen from the description of the above embodiments, the embodiments of this application automatically perform static analysis on the script to be tested, and correct the script to be tested in case of abnormality in the static analysis, so as to avoid anomalies in the subsequent scenario testing process. Since the script to be tested and the corresponding requirement description file and interface specification file are used to determine the test scenario information, a comprehensive test scenario is obtained, and the missing test scenarios in the script are supplemented to obtain a more complete test result. Finally, a test result report is generated to intuitively reflect the test results. Since the whole process does not require manual intervention, the testing efficiency of the script is increased.

[0054] In one possible implementation, the process of performing static analysis on the script to be tested and obtaining the static analysis result in step S202 above may include steps S2021 and S2022.

[0055] S2021: Perform format analysis on the script to be tested and obtain the format analysis results.

[0056] This step may include checking whether the interface test script conforms to the format specification based on a format rule library. Specifically, this may involve finding specific fields in the script under test, searching for the corresponding checking program in the format rule library, and then using the checking program to perform format analysis on the script under test to obtain the format analysis results. Alternatively, a format checking program corresponding to the language of the script under test can be used to perform format analysis on the script under test and obtain the format analysis results.

[0057] For example, whether it includes key information such as test plans, thread groups, interface address configuration files, and database configuration files.

[0058] Accordingly, step S203 may include using a program from the format rule library to automatically correct formatting issues.

[0059] S2022: Perform syntax analysis on the script to be tested and obtain the syntax analysis results.

[0060] This step is similar to step S2021 above, checking whether the script to be tested conforms to the syntax rules according to the syntax rule base.

[0061] For example, whether the data format uses standard conversion code to prevent precision loss, whether the KeySet and array of HashMap (an implementation of the Map interface of hash tables) use standard traversal conversion methods to prevent information loss, and whether the JSONObject and JSONArray data structures are obtained in a common way, etc.

[0062] Accordingly, step S203 may include using a program from a syntax rule base to automatically correct syntax problems.

[0063] In one possible implementation, step S204 above involves determining the test scenario information based on the script to be tested and the corresponding requirement description file and interface specification file, including:

[0064] S2041: Determine the existing scenario information corresponding to the script to be tested.

[0065] This step may include extracting keywords from the script to be tested, finding the correspondence between preset keywords and scene information based on the keywords, and obtaining the corresponding existing scene information.

[0066] The mapping between keywords and scenario information can be pre-written by staff and stored in formats such as tables or key-value pairs. Existing scenario information, as well as the first, second, and third scenario information described below, can all include interface characteristic information such as interface addresses and input parameters. This scenario information can include normal and abnormal scenarios. For example, in the process of searching for information returned from the database based on a file number, in a normal scenario, the interface inputs an existing file number, and the interface retrieves the information corresponding to the file number from the database. In an abnormal scenario, the interface inputs a non-existent file number or a file number with an incorrect format. After obtaining the file number, the interface cannot find the corresponding information or the file number verification fails, returning an appropriate prompt message.

[0067] S2042: Based on the script to be tested, locate the interface development code library to obtain the first scenario information.

[0068] This step may include extracting keywords from the script to be tested, searching the interface development code library based on the keywords to obtain the corresponding existing code, and determining the scenario information corresponding to the found existing code as the first scenario information; it may also include calculating the similarity between the script to be tested and at least one existing code in the interface development code library, determining the existing code with a similarity exceeding a preset first threshold as the target code, and determining the scenario information corresponding to the target code as the first scenario information.

[0069] S2043: Based on the requirements description file, search the interface requirements description library to obtain the second scenario information.

[0070] This step may include extracting keywords from the requirement description file, searching the interface requirement description library based on the keywords to obtain the corresponding existing description file, and determining the scenario information corresponding to the found existing description file as the second scenario information; it may also include calculating the similarity between the requirement description file and at least one existing description file in the interface requirement description library, determining the existing description file with a similarity exceeding a preset first threshold as the target code, and determining the scenario information corresponding to the target code as the second scenario information.

[0071] S2044: Based on the interface specification document, search the interface specification document library to obtain the third scenario information.

[0072] This step is similar to steps S2042 and S2043 above, and will not be repeated here.

[0073] S2045: Collect the different scene information from the existing scene information, the first scene information, the second scene information, and the third scene information to determine the test scene information.

[0074] In this step, for example, if we already have scenario information A, the first scenario information includes scenario A and scenario B, the second scenario information is scenario C, and the third scenario information is scenario A, then scenario A is repeated. Therefore, scenario A, scenario B, and scenario C are collectively determined as the test scenario information. As another example, if we already have scenario information B, the first scenario information includes scenario A and scenario B, the second scenario information is scenario D, and the third scenario information is scenario E, then scenario B is repeated once. Therefore, scenario A, scenario B, scenario C, and scenario E are collectively determined as the test scenario information.

[0075] As can be seen from the description of the above embodiments, the embodiments of this application determine the existing scenario information corresponding to the script to be tested, and search the interface development code library, interface requirement description library, and interface specification document library according to the script to be tested, requirement description file, and interface specification document, respectively, to obtain more scenario information, and determine the different scenario information in each obtained scenario information as the test scenario information, thereby completing the test scenario and increasing the accuracy of the test.

[0076] In one possible implementation, in step S2042 above, based on the script to be tested, the interface development code library is searched to obtain the first scenario information, including:

[0077] S421: Obtain the feature information of the script to be tested.

[0078] This step may include identifying preset fields contained in the script to be tested as feature information, or identifying information corresponding to preset fields in the script to be tested as feature information; it may also include identifying comment content in the script to be tested as feature information.

[0079] Among them, determining the information corresponding to the preset fields in the script to be tested as feature information may include determining the adjacent fields after the preset fields in the script to be tested as feature information of the script to be tested.

[0080] S422: Based on the feature information, locate the target test script in the interface development code library.

[0081] This step may include identifying test scripts containing feature information in the interface development code library as target test scripts. Alternatively, it may include finding the correspondence between feature information and script identifiers to obtain target script identifiers, and then identifying the test scripts corresponding to these target script identifiers as target test scripts.

[0082] The correspondence between feature information and script identifiers can be pre-set by staff and stored in tabular format.

[0083] S423: Determine the scenario information corresponding to the target test script as the first scenario information.

[0084] This step may include finding the correspondence between the identifier and the scene information based on the identifier of the target test script to obtain the first scene information.

[0085] As can be seen from the description of the above embodiments, the embodiments of this application obtain the feature information of the script to be tested, obtain the target test script in the interface development code library from the feature information, thereby determining the corresponding scenario information, realizing the use of the code library to complete the test scenario, increasing the completeness of the test scenario, and making the obtained test results more accurate.

[0086] In one possible implementation, step S322 above, which involves locating the target test script in the interface development code library based on the feature information, includes:

[0087] S3221: Based on the feature information, calculate the similarity between the script to be tested and at least one existing script in the interface development code library.

[0088] This step may include obtaining existing feature information corresponding to existing scripts, calculating the similarity between the feature information and the existing feature information, and using this as the similarity between the script to be tested and the existing scripts.

[0089] The method for calculating the similarity between feature information and existing feature information may include calculating the cosine similarity between feature information and existing feature information.

[0090] S3222: If the similarity to the target existing script is greater than the preset threshold, then the target existing script is determined as the target test script, where the target existing script is any existing script.

[0091] In this step, the preset threshold can be set by the staff based on experimental data or empirical parameters.

[0092] For example, if the interface development code library includes existing scripts A, B, C, and D with similarity scores of 0.2, 0.5, 0.9, and 0.7 respectively, and the preset threshold is 0.8, then existing script C will be identified as the target test script.

[0093] As can be seen from the description of the above embodiments, the embodiments of this application calculate the similarity between feature information and existing scripts in the interface development code library, and determine the existing scripts with a similarity greater than a preset threshold as target test scripts. This realizes the ability to find existing scripts similar to the script to be tested in the interface development code library and use them as target test scripts. It also realizes the use of scenario information of similar test scripts as first scenario information, thereby increasing the accuracy of test scenarios.

[0094] In one possible implementation, the test scenario information includes test input information and standard output information.

[0095] Accordingly, in step S206 above, the scenario test result corresponding to the test scenario information is determined based on the script to be tested and the test scenario information, including:

[0096] S2061: Run the script to be tested using the test input information and obtain the script execution result.

[0097] This step may include writing test input information into the script to be tested and running the script to be tested to obtain the script execution result; it may also include writing the test input information and the name of the script to be tested into a preset command line template to obtain the command line to be run, executing the command line to be run, and obtaining the script execution result.

[0098] S2062: If the script execution result is the same as the standard output information, it will be normally determined as the scene test result corresponding to the test scene information; otherwise, it will be abnormally determined as the scene test result corresponding to the test scene information.

[0099] In this step, whether the script execution result is the same as the standard output information can be determined by calculating the similarity between the script execution result and the standard output information. If the similarity exceeds a preset similarity threshold, the script execution result is determined to be the same as the standard output information; otherwise, it is determined to be different. If the script execution result is different from the standard output information, the scenario test result is abnormal.

[0100] As can be seen from the description of the above embodiments, the embodiments of this application run the script to be tested using test input information to obtain the script running result. If the script running result is the same as the standard output information, the scenario test result is determined to be normal; otherwise, it is abnormal. The test result is automatically generated, which increases the efficiency of script testing and facilitates the subsequent generation of test result reports.

[0101] In one possible implementation, the static analysis results also include error messages.

[0102] Accordingly, in step S203 above, the script to be tested is modified based on the static analysis results to obtain a new script to be tested, including:

[0103] S2031: Read the script modification program corresponding to the error message.

[0104] This step may include finding the correspondence between error messages and script modification program identifiers, obtaining the modification program identifier corresponding to the error message, and then reading the script modification program from the modification program identifier.

[0105] The correspondence between error messages and script modification program identifiers can be pre-set by staff based on experimental data or empirical parameters, and stored in a table or key-value pair format. The process of reading the script modification program by the modification program identifier can include reading the script modification program named with the modification program identifier, or reading the script modification program whose name includes the modification program identifier.

[0106] S2032: Modify the script to be tested using a script modification program to obtain a new script to be tested.

[0107] This step may include inputting the script to be tested into a script modification program and running the script modification program to obtain a new script to be tested; or it may include writing the name of the script to be tested and the name of the script modification program into a preset command line template to obtain an executable command line, executing the executable command line, thereby causing the script modification program to modify the script to be tested and obtain a new script to be tested.

[0108] As can be seen from the description of the above embodiments, the embodiments of this application read the script modification program corresponding to the error message and use the script modification program to modify the script to be tested to obtain a new script to be tested, thereby realizing automatic modification of the script to be tested, reducing manual modification time, and increasing script testing efficiency.

[0109] In one possible implementation, step S203 above modifies the script to be tested based on the static analysis results to obtain a new script to be tested, including:

[0110] S2033: Read the target generator corresponding to the static analysis results, where the target generator is a generator in the pre-trained generative adversarial network.

[0111] In this step, the Generative Adversarial Network (GAN) can be pre-trained by the engineers. Before training, the scripts containing grammatical errors are preprocessed, including word segmentation and stop word removal, to facilitate subsequent model processing and create a generator and a discriminator. The generator's task is to fix at least one of the format, grammatical, or semantic errors, while the discriminator's task is to determine whether the fixed sentences are correct. During training, the GAN model is trained using scripts containing grammatical errors as input. During training, the generator learns the correct grammatical rules and attempts to deceive the discriminator. The discriminator then identifies the fake data generated by the generator (i.e., the fixed grammatical errors). Through this adversarial training, the generator gradually improves its ability to fix grammatical errors.

[0112] S2034: Input the script to be tested into the target generator and obtain the output data output by the target generator.

[0113] This step may include inputting the content of the script to be tested into the input layer of the target generator, and the output content of the target generator's output layer is the output data.

[0114] S2035: Based on the output data, determine the new script to be tested.

[0115] This step may include writing the output data to a blank file to obtain a new test script, or using the output data to overwrite the contents of the original test script to obtain a new test script.

[0116] As can be seen from the description of the above embodiments, the embodiments of this application can increase the accuracy of the generator by using the generator corresponding to the static analysis results, thereby producing a new script to be tested after repair more accurately.

[0117] Figure 3 This is a schematic diagram of the script testing device provided in an embodiment of this application. Figure 3 As shown, the script testing device 300 includes: a file acquisition module 301, a static analysis module 302, a script modification module 303, an information determination module 304, a result determination module 305, and a report generation module 306.

[0118] The file acquisition module 301 is used to acquire the script to be tested and the corresponding requirement description file and interface specification file.

[0119] The static analysis module 302 is used to perform static analysis on the script to be tested and obtain static analysis results, including the execution status.

[0120] The script modification module 303 is used to modify the script to be tested based on the static analysis results if the execution status is abnormal, so as to obtain a new script to be tested.

[0121] The information determination module 304 is used to determine the test scenario information based on the script to be tested and the corresponding requirement description file and interface specification file.

[0122] The result determination module 305 is used to determine the scenario test result corresponding to the test scenario information based on the script to be tested and the test scenario information.

[0123] The report generation module 306 is used to generate test result reports corresponding to static analysis results and scenario test results.

[0124] The apparatus provided in this embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effects are similar, and will not be described again here.

[0125] In one possible implementation, the information determination module 304 is specifically used to determine the existing scenario information corresponding to the script to be tested. Based on the script to be tested, it searches the interface development code library to obtain the first scenario information. Based on the requirement description file, it searches the interface requirement description library to obtain the second scenario information. Based on the interface specification file, it searches the interface specification document library to obtain the third scenario information. The different scenario information from the existing scenario information, the first scenario information, the second scenario information, and the third scenario information are collectively determined as the test scenario information.

[0126] The apparatus provided in this embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effects are similar, and will not be described again here.

[0127] In one possible implementation, the information determination module 304 is specifically used to obtain the feature information of the script to be tested. Based on the feature information, the target test script is located in the interface development code library. The scenario information corresponding to the target test script is determined as the first scenario information.

[0128] The apparatus provided in this embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effects are similar, and will not be described again here.

[0129] In one possible implementation, the information determination module 304 is specifically used to calculate the similarity between the script to be tested and at least one existing script in the interface development code library based on feature information. If the similarity corresponding to the target existing script is greater than a preset threshold, then the target existing script is determined as the target test script, wherein the target existing script is any existing script.

[0130] The apparatus provided in this embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effects are similar, and will not be described again here.

[0131] In one possible implementation, the test scenario information includes test input information and standard output information.

[0132] Accordingly, the result determination module 305 is specifically used to run the script to be tested using the test input information and obtain the script execution result. If the script execution result is the same as the standard output information, it will be normally determined as the scenario test result corresponding to the test scenario information; otherwise, it will be abnormally determined as the scenario test result corresponding to the test scenario information.

[0133] The apparatus provided in this embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effects are similar, and will not be described again here.

[0134] In one possible implementation, the static analysis results also include error messages.

[0135] Accordingly, the script modification module 303 is specifically used to read the script modification program corresponding to the error message. The script to be tested is modified using the script modification program to obtain a new script to be tested.

[0136] The apparatus provided in this embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effects are similar, and will not be described again here.

[0137] In one possible implementation, the script modification module 303 is specifically used to read the target generator corresponding to the static analysis results, where the target generator is a generator in a pre-trained generative adversarial network. The script to be tested is input into the target generator to obtain its output data. Based on the output data, a new script to be tested is determined.

[0138] The apparatus provided in this embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effects are similar, and will not be described again here.

[0139] To implement the above embodiments, this application also provides an electronic device.

[0140] refer to Figure 4The diagram illustrates a structural schematic of an electronic device 400 suitable for implementing embodiments of this application. The electronic device 400 can be a terminal device or a server. The terminal device can include, but is not limited to, mobile terminals such as mobile phones, laptops, digital radio receivers, personal digital assistants (PDAs), portable Android devices (PADs), portable media players (PMPs), and in-vehicle terminals (e.g., in-vehicle navigation terminals), as well as fixed terminals such as digital TVs and desktop computers. Figure 4 The electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.

[0141] like Figure 4 As shown, the electronic device 400 may include a processor (e.g., a central processing unit, a graphics processing unit, etc.) 401 and a memory 402 communicatively connected to the processor. The processor can perform various appropriate actions and processes based on programs stored in the memory 402, computer execution instructions, or programs loaded from storage device 408 into random access memory (RAM) 403, implementing the script testing method in any of the above embodiments. The memory may be a read-only memory (ROM). The RAM 403 also stores various programs and data required for the operation of the electronic device 400. The processing device 401, the memory 402, and the RAM 403 are interconnected via a bus 404. An input / output (I / O) interface 405 is also connected to the bus 404.

[0142] Typically, the following devices can be connected to I / O interface 405: input devices 406 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 407 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 408 including, for example, magnetic tapes, hard disks, etc.; and communication devices 409. Communication device 409 allows electronic device 400 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 4 An electronic device 400 with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively.

[0143] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable storage medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication device 409, or installed from storage device 408, or installed from memory 402. When the computer program is executed by processing device 401, it performs the functions defined in the methods of embodiments of this application.

[0144] It should be noted that the computer-readable storage medium described above in this application can be a computer-readable signal medium or a computer storage medium, or any combination of the two. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable storage medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable storage medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.

[0145] The aforementioned computer-readable storage medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device.

[0146] The aforementioned computer-readable storage medium carries one or more programs, which, when executed by the electronic device, cause the electronic device to perform the method shown in the above embodiments.

[0147] Computer program code for performing the operations of this application can be written in one or more programming languages ​​or a combination thereof. These programming languages ​​include object-oriented programming languages—such as Java, Smalltalk, and C++—and conventional procedural programming languages—such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0148] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0149] The modules described in the embodiments of this application can be implemented in software or in hardware. The names of the units do not necessarily limit the module itself; for example, a script modification module can also be described as a "script modification module to be tested".

[0150] The functions described above in this document can be performed, at least in part, by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: Field Programmable Gate Arrays (FPGAs), Application-Specific Integrated Circuits (ASICs), Application Standard Products (ASSPs), System-on-Chip (SoCs), Complex Programmable Logic Devices (CPLDs), and so on.

[0151] This application also provides a computer-readable storage medium storing computer-executable instructions. When the processor executes the computer-executable instructions, it implements the technical solution of the script testing method in any of the above embodiments. Its implementation principle and beneficial effects are similar to those of the script testing method, and can be found in the implementation principle and beneficial effects of the script testing method, which will not be repeated here.

[0152] In the context of this application, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable media can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0153] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the technical solution of the script testing method in any of the above embodiments. Its implementation principle and beneficial effects are similar to those of the script testing method, and can be found in the implementation principle and beneficial effects of the script testing method, which will not be repeated here.

[0154] The above description is merely a preferred embodiment of this application and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of disclosure in this application is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features with similar functions disclosed in this application.

[0155] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.

[0156] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.

Claims

1. A script testing method, characterized in that, include: Obtain the script to be tested and the corresponding requirement description file and interface specification file; Static analysis is performed on the script to be tested to obtain static analysis results, wherein the static analysis results include the execution status; If the execution status is abnormal, then the target generator corresponding to the static analysis result is read, wherein the target generator is a generator in the pre-trained generative adversarial network; The script to be tested is input into the target generator to obtain the output data of the target generator; Based on the output data, determine the new script to be tested; Determine the existing scene information corresponding to the script to be tested; Obtain the feature information of the script to be tested; Based on the aforementioned feature information, locate the target test script in the interface development code library; The scenario information corresponding to the target test script is determined as the first scenario information; Based on the aforementioned requirement description file, the interface requirement description library is searched to obtain the second scenario information; Based on the interface specification file, the interface specification document library is searched to obtain the third scenario information; The different scene information among the existing scene information, the first scene information, the second scene information, and the third scene information are collectively determined as the test scene information; Based on the script to be tested and the test scenario information, determine the scenario test result corresponding to the test scenario information; Generate a test result report corresponding to the static analysis results and the scenario test results.

2. The method according to claim 1, characterized in that, The step of finding the target test script in the interface development code library based on the feature information includes: Based on the feature information, calculate the similarity between the script to be tested and at least one existing script in the interface development code library; If the similarity to an existing target script is greater than a preset threshold, the existing target script is identified as the target test script, where the existing target script is any existing script.

3. The method according to claim 1, characterized in that, The test scenario information includes test input information and standard output information; Accordingly, determining the scenario test result corresponding to the test scenario information based on the script to be tested and the test scenario information includes: The test script is run using the test input information to obtain the script execution result; If the script execution result is the same as the standard output information, it will be normally determined as the scenario test result corresponding to the test scenario information; otherwise, it will be abnormally determined as the scenario test result corresponding to the test scenario information.

4. A script testing device, characterized in that, include: The file acquisition module is used to acquire the script to be tested and the corresponding requirement description file and interface specification file of the script to be tested. The static analysis module is used to perform static analysis on the script to be tested and obtain static analysis results, wherein the static analysis results include the execution status. The script modification module is used to read the target generator corresponding to the static analysis result if the execution status is abnormal, wherein the target generator is a generator in the pre-trained generative adversarial network. The script to be tested is input into the target generator to obtain the output data of the target generator; Based on the output data, determine the new script to be tested; The information determination module is used to determine the existing scene information corresponding to the script to be tested; Obtain the feature information of the script to be tested; Based on the aforementioned feature information, locate the target test script in the interface development code library; The scenario information corresponding to the target test script is determined as the first scenario information; according to the requirement description file, the interface requirement description library is searched to obtain the second scenario information; according to the interface description file, the interface description document library is searched to obtain the third scenario information; the existing scenario information, the first scenario information, the second scenario information, and the different scenario information in the third scenario information are jointly determined as the test scenario information; The result determination module is used to determine the scenario test result corresponding to the test scenario information based on the script to be tested and the test scenario information. The report generation module is used to generate test result reports corresponding to the static analysis results and the scenario test results.

5. An electronic device, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory, causing the processor to perform the script testing method as described in any one of claims 1 to 3.

6. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the script testing method as described in any one of claims 1 to 3.

7. A computer program product, characterized in that, It includes a computer program that implements the script testing method as described in any one of claims 1 to 3.

Citation Information

Patent Citations

  • Static inspection method based on xml test script code

    CN115437923A

  • Method and system for generating interface automation test case

    CN117251384A