CN109240923B - Interface test script generation method and computer readable storage medium - Google Patents

Interface test script generation method and computer readable storage medium Download PDF

Info

Publication number
CN109240923B
CN109240923B CN201811009575.4A CN201811009575A CN109240923B CN 109240923 B CN109240923 B CN 109240923B CN 201811009575 A CN201811009575 A CN 201811009575A CN 109240923 B CN109240923 B CN 109240923B
Authority
CN
China
Prior art keywords
interface
tested
vector
library
generating
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201811009575.4A
Other languages
Chinese (zh)
Other versions
CN109240923A (en
Inventor
刘德建
黄彬
黄江涛
赖保宇
林琛
林斯潇
林志宏
潘添松
俞发仁
钟开华
郑碧雅
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Fujian Tianquan Educational Technology Ltd
Original Assignee
Fujian Tianquan Educational Technology Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Fujian Tianquan Educational Technology Ltd filed Critical Fujian Tianquan Educational Technology Ltd
Priority to CN201811009575.4A priority Critical patent/CN109240923B/en
Publication of CN109240923A publication Critical patent/CN109240923A/en
Application granted granted Critical
Publication of CN109240923B publication Critical patent/CN109240923B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention discloses a method for generating an interface test script and a computer readable storage medium, wherein the method comprises the following steps: generating an interface metadata vector of each interface according to the characteristic data of each interface; classifying the interface libraries, and calculating to obtain mean vectors and difference matrixes of the various interface libraries according to interface metadata vectors of the interfaces in the various interface libraries; acquiring and analyzing an interface configuration statement file of an interface to be tested to obtain characteristic data of the interface to be tested; generating an interface metadata vector of the interface to be tested according to the characteristic data; respectively calculating the difference degree of the interface to be tested and each interface library according to the interface metadata vector of the interface to be tested and the mean vector and the difference matrix of each interface library; and generating a test script of the interface to be tested according to the code base corresponding to the interface base with the minimum difference degree with the interface to be tested. The invention can improve the generation efficiency of the interface test script.

Description

Interface test script generation method and computer readable storage medium
Technical Field
The invention relates to the field of software automation test, in particular to a method for generating an interface test script and a computer readable storage medium.
Background
When the interfaces are automatically tested, modules such as request types, parameter structure body assertions, test general configurations and test cases of each interface need to be encoded in advance according to test documents, and then debugging and automatic testing are carried out. However, in the automatic test coding process, the code structure of some modules is relatively fixed, the description of the interface behavior is similar, but due to the differences of the internal definition of the interface, the data transmission method, the request type, the returned data type and the like, many people can think of the mode of automatically generating the code or the script to save a large amount of script writing cost, but the existing code generation mode, such as the Cartesian product, is explosively increased in the number of generated scripts, and a large amount of scripts can be generated again each time the demand is changed, so that the test efficiency is not improved, but is reduced.
In the prior art, a Visual Studio unit testing tool exists, and a method and a flow for realizing unit testing are as follows:
(1) creating interface test engineering
A C # project is opened or created in the Visual Studio, and a 'unit test project' is created in the solution (the unit test project can also be directly created and is determined according to the actual test scenario). Visual Studio creates a "UnitTest 1. cs" module in the unit test project by default, which contains the test case classes and methods required by the test: "TestClass" and "TestMethod".
(2) Adding test code in test class methods
And layering the test engineering structure, and adding modules and codes of a test behavior method, a test configuration and the like of the item to be tested in a corresponding layer. And modifying the automatically created UnitTest1.cs module file into a module name meeting the project test specification, and testing the processing of 'front' and 'rear' in the module file. Test-case code and test assertions are written in "TestMethod".
(3) Performing a test
And sequentially clicking a menu bar (test) of VS (verification for verification. Tests are performed and test results are viewed in a "test resource manager".
However, the above method has the following disadvantages:
disadvantage 1: in the steps (1) and (2), after the unit test items are created, the Visual Studio only generates a simple template file with the file name of 'UnitTest1. cs', and for software testers, the template can only take the reference function when writing test codes and does not reuse the information of any previous interface with similar attributes.
And (2) disadvantage: when a new test automation test is carried out each time, the unit test engineering code needs to be redesigned by referring to the test document, and no unified code development standard exists in the design process. The unit testing tool can only support programming languages contained in Visual Studio, has no reusability for unsupported languages, can only be applied to Windows environment, and has no cross-platform use capability.
Disclosure of Invention
The technical problem to be solved by the invention is as follows: the interface test script generation method and the computer readable storage medium can improve the interface test script generation efficiency and reduce the automatic test cost.
In order to solve the technical problems, the invention adopts the technical scheme that: a method for generating an interface test script comprises the following steps:
generating an interface metadata vector of each interface according to the characteristic data of each interface, wherein the characteristic data comprises a request parameter field type, an associated interface number, an operation step number, a composite structure field number, a method category and a response parameter field type;
classifying the interface libraries, and calculating to obtain mean vectors and difference matrixes of the various interface libraries according to interface metadata vectors of the interfaces in the various interface libraries;
acquiring and analyzing an interface configuration statement file of an interface to be tested to obtain characteristic data of the interface to be tested;
generating an interface metadata vector of the interface to be tested according to the characteristic data;
respectively calculating the difference degree of the interface to be tested and each interface library according to the interface metadata vector of the interface to be tested and the mean vector and the difference matrix of each interface library;
and generating a test script of the interface to be tested according to the code base corresponding to the interface base with the minimum difference degree with the interface to be tested.
The invention also relates to a computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps as described above.
The invention has the beneficial effects that: generating interface metadata vectors of each interface through the characteristic data of each interface, then calculating to obtain mean vectors and difference matrixes of various interface libraries, and subsequently calculating the difference between the interface to be tested and various interface libraries according to the interface metadata vectors of the interface to be tested and the mean vectors and the difference matrixes of various interface libraries to obtain the interface library with the minimum difference, thereby reusing the test data of the existing interface, reducing repeated codes in the interface test process, accelerating the generation efficiency of an interface test script and reducing the cost of the interface test; meanwhile, the difference degree obtained by calculation based on the mean vector and the difference matrix can ensure that the maximum probability obtains an approximate code segment, the generation rate of the test script can be increased, and the test code amount can be controlled.
Drawings
FIG. 1 is a flow chart of a method for generating an interface test script according to the present invention;
fig. 2 is a flowchart of a method according to a first embodiment of the invention.
Detailed Description
In order to explain technical contents, objects and effects of the present invention in detail, the following detailed description is given with reference to the accompanying drawings in conjunction with the embodiments.
The most key concept of the invention is as follows: and calculating the difference degree between the interface to be tested and each interface library according to the mean vector and the difference matrix, and generating a test script according to the code library of the interface library with the minimum difference degree.
The noun explains:
swagger service: an interface document generation framework. The method is used for generating, describing, calling and visualizing RESTful-style Web services, and generating structured swagger json data and interface document files through project interface services which are synchronously developed in real time.
Referring to fig. 1, a method for generating an interface test script includes:
generating an interface metadata vector of each interface according to the characteristic data of each interface, wherein the characteristic data comprises a request parameter field type, an associated interface number, an operation step number, a composite structure field number, a method category and a response parameter field type;
classifying the interface libraries, and calculating to obtain mean vectors and difference matrixes of the various interface libraries according to interface metadata vectors of the interfaces in the various interface libraries;
acquiring and analyzing an interface configuration statement file of an interface to be tested to obtain characteristic data of the interface to be tested;
generating an interface metadata vector of the interface to be tested according to the characteristic data;
respectively calculating the difference degree of the interface to be tested and each interface library according to the interface metadata vector of the interface to be tested and the mean vector and the difference matrix of each interface library;
and generating a test script of the interface to be tested according to the code base corresponding to the interface base with the minimum difference degree with the interface to be tested.
From the above description, the beneficial effects of the present invention are: the generation efficiency of the interface test script can be improved, and the automatic test cost is reduced.
Further, the generating of the interface metadata vector of each interface according to the feature data of each interface specifically includes:
encoding the parameter type;
obtaining a request parameter field type sequence vector of an interface according to a code corresponding to a parameter type received by the interface;
obtaining a response parameter field type sequential vector of the interface according to a code corresponding to a parameter type of interface response;
obtaining the number of the associated interfaces of the interfaces according to the number of the interfaces associated with the interfaces;
obtaining the number of operation steps of the interface according to the number of the operation steps to be completed by the interface;
obtaining the number of the composite structure fields of the interface according to the number of the composite structure fields in the interface;
encoding a method category;
obtaining the method type code of the interface according to the code corresponding to the method type of the interface request;
and generating an interface metadata vector of the interface according to the request parameter field type sequence vector, the number of associated interfaces, the number of operation steps, the number of composite structure fields, the method category code and the response parameter field type sequence vector of the interface.
Further, the calculating to obtain the mean vector and the difference matrix of each interface library according to the interface metadata vector of each interface in each interface library specifically includes:
carrying out average value calculation on the interface metadata vectors of all the interfaces in the first-class interface library to obtain the average value vector of the first-class interface library;
calculating to obtain a difference matrix of the interface library according to a first formula, wherein the first formula is
Figure BDA0001784722760000051
Wherein n is the number of interfaces in the interface library, XiAnd mu is an average value vector of the interface library.
Further, the obtaining and analyzing the interface configuration statement file of the interface to be tested to obtain the feature data of the interface to be tested specifically includes:
acquiring an interface configuration statement file of an interface to be tested, and verifying the legality of the interface configuration statement file;
and if the verification is passed, analyzing the interface configuration statement file to obtain the characteristic data of the interface to be tested.
According to the description, the interface configuration declaration file of the interface to be tested is verified, so that the legality and correctness of the interface configuration declaration file are ensured.
Further, the analyzing the interface configuration statement file to obtain the feature data of the interface to be tested specifically includes:
analyzing the interface configuration statement file to obtain interface parameter data of the interface to be tested, wherein the interface parameter data comprises an interface request parameter, an interface return parameter and an interface definition description;
encoding the parameter type;
acquiring a parameter type received by an interface to be tested according to the interface request parameter, and acquiring a request parameter field type sequence vector of the interface to be tested according to a code corresponding to the received parameter type;
acquiring the parameter type of the interface response to be tested according to the interface return parameter, and acquiring a response parameter field type sequence vector of the interface to be tested according to the code corresponding to the parameter type of the response;
obtaining the number of the composite structure fields of the interface to be tested according to the number of the composite structure fields in the interface request parameters and the interface return parameters;
obtaining the number of the associated interfaces, the number of operation steps and the method types of the interfaces to be tested according to the interface definition description;
encoding a method category;
and obtaining the method type code of the interface to be tested according to the code corresponding to the method type.
Further, the generating an interface metadata vector of the interface to be tested according to the feature data specifically includes:
and generating an interface metadata vector of the interface to be tested according to the request parameter field type sequence vector, the number of associated interfaces, the number of operation steps, the number of composite structure fields, the method category code and the response parameter field type sequence vector of the interface to be tested.
Further, the calculating the difference degree between the interface to be tested and each interface library according to the interface metadata vector of the interface to be tested and the mean vector and the difference matrix of each interface library specifically comprises:
calculating the difference degree between the interface to be tested and the interface library according to a second formula, wherein the second formula is D (Y, G) ═ Y-mu) A-1(Y-μ)TWherein G is the interface library, Y is the interface metadata vector of the interface to be tested, mu is the mean vector of the interface library, A-1Is the inverse of the difference matrix of the class of interface library.
From the above description, it can be known that the maximum probability can be ensured to obtain the approximate code segment based on the difference degree calculated by the mean vector and the difference matrix.
The invention also proposes a computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps as described above.
Example one
Referring to fig. 2, a first embodiment of the present invention is: a method for generating an interface test script comprises the following steps:
s1: classifying the interface library; specifically, the overall class of the interface library may be predefined, and then the interface library may be classified according to a process class, a parameter class, an operation class, and a multi-service tandem class.
S2: and respectively generating an interface metadata vector of each interface according to the characteristic data of each interface, wherein the characteristic data comprises a request parameter field type, an associated interface number, an operation step number, a composite structure field number, a method category and a response parameter field type.
Specifically, first, a parameter type is encoded; preferably, the encoding is started from 0, for example, the encoding can be performed in the following order: int is 0, float is 1, string is 2, list is 4, and dit is 5; then according to the codes corresponding to the parameter types received by the interface, obtaining a request parameter field type sequence vector of the interface; and obtaining a response parameter field type sequence vector of the interface according to the code corresponding to the parameter type of the interface response.
Meanwhile, obtaining the number of the associated interfaces of the interfaces according to the number of the interfaces associated with the interfaces; obtaining the number of operation steps of the interface according to the number of the operation steps to be completed by the interface; and obtaining the number of the composite structure fields of the interface according to the number of the composite structure fields in the interface.
Meanwhile, encoding the method category; for example, GET is 1, POST is 2, PUT is 3, DELETE is 4, PATCH is 5. And then, obtaining the method type code of the interface according to the code corresponding to the method type of the interface request.
Finally, vector x is ordered according to the request parameter field type of the interface1The number x of the associated interfaces2Number of operation steps x3Composite structure field number x4Method class code x5And response parameter field type order vector x6Generating an interface metadata vector X ═ X (X) for the interface1,x2,x3,x4,x5,x6)。
S3: and respectively calculating to obtain the mean vector and the difference matrix of the various interface libraries according to the interface metadata vector of each interface in the various interface libraries.
Specifically, the average value of the interface metadata vectors of the interfaces in the class-I interface library is calculated to obtain the average value vector of the class-I interface library.
Suppose there are n interfaces in a certain kind of interface library, wherein the interface metadata vector of the ith interface is Xi=(xi1,xi2,xi3,xi4,xi5,xi6) (ii) a Calculating an average value for each component of the interface metadata vectors of the n interfaces, e.g. the average value of the first componentIs composed of
Figure BDA0001784722760000071
The mean of the second component is
Figure BDA0001784722760000072
By analogy, after the average value of six components is obtained through calculation, the average value vector of the interface library of the type can be obtained
Figure BDA0001784722760000073
After the mean vector of the interface library is obtained through calculation, calculating to obtain a difference matrix of the interface library according to a first formula, wherein the first formula is
Figure BDA0001784722760000074
Where T denotes transposition.
S4: acquiring an interface configuration statement file of an interface to be tested, carrying out validity verification on the interface configuration statement file, judging whether the verification is passed, if so, executing the step S5, and if not, sending out a corresponding error warning. In this embodiment, the uploaded file is derived from a swagger json file of a swagger service, and interface data content is described in detail in the file in a json format and includes data such as an interface Request type parameter (Method), an interface Request parameter (Request), an interface return parameter (Responses), an interface Request address (API-Path), and a HOST (namely, url of an interface to be tested). Json file, and verifying whether the data contained in the json file, such as Method, Request, Responses, API-Path, HOST, etc., is correct and legal.
S5: and analyzing the interface configuration statement file to obtain the characteristic data of the interface to be tested.
Specifically, the interface configuration statement file is analyzed to obtain interface parameter data of the interface to be tested, where the interface parameter data includes an interface Request parameter (Request), an interface return parameter (Responses), and an interface definition description.
Then, acquiring a parameter type received by an interface to be tested according to the interface request parameter, and acquiring a request parameter field type sequential vector of the interface to be tested according to a code corresponding to the received parameter type; acquiring the parameter type of the interface response to be tested according to the interface return parameter, and acquiring a response parameter field type sequence vector of the interface to be tested according to the code corresponding to the parameter type of the response; in this step, the encoding of the parameter type is the same as that in step S2.
And simultaneously, obtaining the number of the composite structure fields of the interface to be tested according to the number of the composite structure fields in the interface request parameters and the interface return parameters.
Meanwhile, obtaining the number of the associated interfaces, the number of operation steps and the method types of the interfaces to be tested according to the interface definition description; acquiring the number of preset associated interfaces, the number of operation steps and the method type from the interface definition description; and then obtaining the method type code of the interface to be tested according to the code corresponding to the method type. The method type encoding in this step is the same as the method type encoding in step S2.
S6: generating an interface metadata vector of the interface to be tested according to the characteristic data; specifically, according to the request parameter field type sequence vector y of the interface to be tested1The number of associated interfaces y2Number of operation steps y3Composite structure field number y4Method class code y5And response parameter field type order vector y6Generating an interface metadata vector Y ═ Y of the interface to be tested1,y2,y3,y4,y5,y6)。
S7: and respectively calculating the difference degree of the interface to be tested and each interface library according to the interface metadata vector of the interface to be tested and the mean vector and the difference matrix of each interface library.
Specifically, the difference between the interface to be tested and the first-class interface library is calculated according to a second formula, where the second formula is D (Y, G) ═ Y-μ)A-1(Y-μ)TWherein G is the interface library, Y is the interface metadata vector of the interface to be tested, mu is the mean vector of the interface library, A-1T represents a transpose, which is the inverse of the difference matrix of the class of interface libraries.
And according to a second formula, the difference degree between the interface to be tested and each interface library can be respectively calculated.
S8: generating a test script of the interface to be tested according to a code library corresponding to the interface library with the minimum difference degree; the interface library with the minimum difference degree with the interface to be tested is obtained from the various interface libraries, and a test script of the interface to be tested is generated according to codes in the code libraries corresponding to the interface library.
The average vector reflects the overall level of a class of interface libraries, the difference matrix represents the correlation among information in interfaces, when the quantity of the interfaces reaches a certain level, the comparison is time-consuming and unacceptable through simple comparison one by one, similar interface relations can be obtained through the average comparison, but distance measurement differences exist, such as the number of composite structure fields, the variation is possible to be from 100 to 200, the interface method type difference is generally only from 1 to 4, if the two differences calculate the distance, the difference of the interface method type is possibly reduced, but the difference of the composite structure fields is amplified, because the data magnitude is different, the difference matrix is required to be introduced, the difference of the fields is normalized, and the situation that large difference consumes small difference is avoided.
Therefore, the difference degree obtained by calculation based on the mean vector and the difference matrix can ensure that the maximum probability obtains an approximate code segment instead of recalculating each time, so that the code generation rate is increased, the test code amount is controlled, the code generation speed is increased, the codes to be operated are reduced, and the method is effectively simplified compared with the traditional Cartesian product code generation method.
In this embodiment, after the interface configuration declaration file in the specified format is uploaded and the data in the various interface libraries is calculated by the server, the difference degree information between the interface to be tested and the various interface libraries is calculated by combining the mean vector and the difference matrix, so that the test data of the existing interface with the minimum difference degree is multiplexed. The embodiment can reduce repeated coding in the automatic test process to a certain extent, accelerate the generation efficiency of the test script and reduce the automatic test cost.
Example two
The present embodiment is a specific application scenario of the first embodiment. The method of the present embodiment may be based on the B/S architecture design and implementation of python.
Firstly, initializing an automatic test project, and importing basic project structure files, test configuration files, class modules and other files; then, a python code template is configured, and module structures such as an interface definition module, an interface structure definition and object assertion module, a test case module, a test configuration module and the like are preset in the code template.
The interface definition module is used for packaging the tested interface object request action, and the interface definition module comprises the description and definition of all interface request methods in the project. The interface structure definition and object assertion module is used for encapsulating the tested interface parameter structure, wherein the interface parameter structure comprises a description and definition method of request and response data structures of all interfaces in a project and a corresponding structure object assertion method. The test case module is used for storing the test codes of the first-level cases of the tested interface objects, and each file comprises a general first-level test case and an assertion code of a corresponding interface; when testing automation coding is performed, a tester can write other interface automation testing codes by referring to the primary testing case and the assertion codes. The test configuration module is used for defining configurations such as a test environment, a test version, a test set and the like used in the automatic test; the test data is extracted from the interface configuration statement file uploaded by the user and written according to the template format.
In step S8, after generating the test script, the code files in the test script are written into the corresponding modules of the automated testing project according to the test configuration file, so as to generate a complete set of automated testing project. The automated tester may download the designated test modules or complete test engineering packages as needed. And on the basis, writing of the rest test automation codes and executing the automation test are continuously completed.
In the embodiment, the swagger interface document file is uploaded to the analysis service, the engineering file required by the test is directly generated after analysis processing, and codes of the modules do not need to be written or modified manually, so that an automated tester only needs to download the generated test engineering, expand the test case on the basis, directly declare and use the automatically generated code modules in the test case, prepare test data, and directly start the interface test without paying attention to other module contents.
If the project environment changes, for example, the swagger document is not used for describing the tested object, or the language of the automatic test program changes, or the automatic test framework is adjusted, and the like. In the above change, only the code template and part of the logic processing code need to be adjusted, and the new project test environment or the new automatic test programming language can be compatible.
Meanwhile, according to different platform environments, any platform and the language supported by any platform can be freely selected to finish automatic generation of the test, and the universality is high.
EXAMPLE III
The present embodiment is a computer-readable storage medium corresponding to the above-mentioned embodiments, on which a computer program is stored, which when executed by a processor implements the steps of:
generating an interface metadata vector of each interface according to the characteristic data of each interface, wherein the characteristic data comprises a request parameter field type, an associated interface number, an operation step number, a composite structure field number, a method category and a response parameter field type;
classifying the interface libraries, and calculating to obtain mean vectors and difference matrixes of the various interface libraries according to interface metadata vectors of the interfaces in the various interface libraries;
acquiring and analyzing an interface configuration statement file of an interface to be tested to obtain characteristic data of the interface to be tested;
generating an interface metadata vector of the interface to be tested according to the characteristic data;
respectively calculating the difference degree of the interface to be tested and each interface library according to the interface metadata vector of the interface to be tested and the mean vector and the difference matrix of each interface library;
and generating a test script of the interface to be tested according to the code library corresponding to the interface library with the minimum difference degree with the interface to be tested.
Further, the generating of the interface metadata vector of each interface according to the feature data of each interface specifically includes:
encoding the parameter type;
obtaining a request parameter field type sequence vector of an interface according to a code corresponding to a parameter type received by the interface;
obtaining a response parameter field type sequential vector of the interface according to a code corresponding to a parameter type of interface response;
obtaining the number of the associated interfaces of the interfaces according to the number of the interfaces associated with the interfaces;
obtaining the number of operation steps of the interface according to the number of the operation steps to be completed by the interface;
obtaining the number of the composite structure fields of the interface according to the number of the composite structure fields in the interface;
encoding a method category;
obtaining the method type code of the interface according to the code corresponding to the method type of the interface request;
and generating an interface metadata vector of the interface according to the request parameter field type sequence vector, the number of associated interfaces, the number of operation steps, the number of composite structure fields, the method category code and the response parameter field type sequence vector of the interface.
Further, the calculating to obtain the mean vector and the difference matrix of each interface library according to the interface metadata vector of each interface in each interface library specifically includes:
carrying out average value calculation on the interface metadata vectors of all the interfaces in the first-class interface library to obtain the average value vector of the first-class interface library;
calculating to obtain a difference matrix of the interface library according to a first formula, wherein the first formula is
Figure BDA0001784722760000121
Wherein n is the number of interfaces in the interface library, XiAnd mu is an average value vector of the interface library.
Further, the obtaining and analyzing the interface configuration statement file of the interface to be tested to obtain the feature data of the interface to be tested specifically includes:
acquiring an interface configuration statement file of an interface to be tested, and verifying the legality of the interface configuration statement file;
and if the verification is passed, analyzing the interface configuration statement file to obtain the characteristic data of the interface to be tested.
Further, the analyzing the interface configuration statement file to obtain the feature data of the interface to be tested specifically includes:
analyzing the interface configuration statement file to obtain interface parameter data of the interface to be tested, wherein the interface parameter data comprises an interface request parameter, an interface return parameter and an interface definition description;
encoding the parameter type;
acquiring a parameter type received by an interface to be tested according to the interface request parameter, and acquiring a request parameter field type sequence vector of the interface to be tested according to a code corresponding to the received parameter type;
acquiring the parameter type of the interface response to be tested according to the interface return parameter, and acquiring a response parameter field type sequence vector of the interface to be tested according to the code corresponding to the parameter type of the response;
obtaining the number of the composite structure fields of the interface to be tested according to the number of the composite structure fields in the interface request parameters and the interface return parameters;
obtaining the number of the associated interfaces, the number of operation steps and the method types of the interfaces to be tested according to the interface definition description;
encoding a method category;
and obtaining the method type code of the interface to be tested according to the code corresponding to the method type.
Further, the generating an interface metadata vector of the interface to be tested according to the feature data specifically includes:
and generating an interface metadata vector of the interface to be tested according to the request parameter field type sequence vector, the number of associated interfaces, the number of operation steps, the number of composite structure fields, the method category code and the response parameter field type sequence vector of the interface to be tested.
Further, the calculating the difference degree between the interface to be tested and each interface library according to the interface metadata vector of the interface to be tested and the mean vector and the difference matrix of each interface library specifically comprises:
calculating the difference degree between the interface to be tested and the interface library according to a second formula, wherein the second formula is D (Y, G) ═ Y-mu) A-1(Y-μ)TWherein G is the interface library, Y is the interface metadata vector of the interface to be tested, mu is the mean vector of the interface library, A-1Is the inverse of the difference matrix of the class of interface library.
In summary, according to the method for generating an interface test script and the computer-readable storage medium provided by the present invention, the interface metadata vector of each interface is generated according to the feature data of each interface, and then the mean vector and the difference matrix of each interface library are obtained by calculation, and then the difference between the interface to be tested and each interface library is calculated according to the interface metadata vector of the interface to be tested and the mean vector and the difference matrix of each interface library, so that the interface library with the minimum difference can be obtained, thereby reusing the test data of the existing interface, reducing the repetition coding in the interface test process, accelerating the generation efficiency of the interface test script, and reducing the cost of the interface test; meanwhile, the difference degree obtained by calculation based on the mean vector and the difference matrix can ensure that the maximum probability obtains an approximate code segment, the generation rate of the test script can be increased, and the test code amount can be controlled.
The above description is only an embodiment of the present invention, and not intended to limit the scope of the present invention, and all equivalent changes made by using the contents of the present specification and the drawings, or applied directly or indirectly to the related technical fields, are included in the scope of the present invention.

Claims (8)

1. A method for generating an interface test script is characterized by comprising the following steps:
generating an interface metadata vector of each interface according to the characteristic data of each interface, wherein the characteristic data comprises a request parameter field type, an associated interface number, an operation step number, a composite structure field number, a method category and a response parameter field type;
classifying the interface libraries, and calculating to obtain mean vectors and difference matrixes of the various interface libraries according to interface metadata vectors of the interfaces in the various interface libraries;
acquiring and analyzing an interface configuration statement file of an interface to be tested to obtain characteristic data of the interface to be tested;
generating an interface metadata vector of the interface to be tested according to the characteristic data;
respectively calculating the difference degree of the interface to be tested and each interface library according to the interface metadata vector of the interface to be tested and the mean vector and the difference matrix of each interface library;
and generating a test script of the interface to be tested according to the code base corresponding to the interface base with the minimum difference degree with the interface to be tested.
2. The method for generating an interface test script according to claim 1, wherein the generating of the interface metadata vector of each interface according to the feature data of each interface specifically comprises:
encoding the parameter type;
obtaining a request parameter field type sequence vector of an interface according to a code corresponding to a parameter type received by the interface;
obtaining a response parameter field type sequential vector of the interface according to a code corresponding to a parameter type of interface response;
obtaining the number of the associated interfaces of the interfaces according to the number of the interfaces associated with the interfaces;
obtaining the number of operation steps of the interface according to the number of the operation steps to be completed by the interface;
obtaining the number of the composite structure fields of the interface according to the number of the composite structure fields in the interface;
encoding a method category;
obtaining the method type code of the interface according to the code corresponding to the method type of the interface request;
and generating an interface metadata vector of the interface according to the request parameter field type sequence vector, the number of associated interfaces, the number of operation steps, the number of composite structure fields, the method category code and the response parameter field type sequence vector of the interface.
3. The method for generating an interface test script according to claim 1, wherein the calculating the mean vector and the difference matrix of each interface library according to the interface metadata vector of each interface in each interface library respectively is specifically:
carrying out average value calculation on the interface metadata vectors of all the interfaces in the first-class interface library to obtain the average value vector of the first-class interface library;
calculating to obtain a difference matrix of the interface library according to a first formula, wherein the first formula is
Figure FDA0001784722750000021
Wherein n is the number of interfaces in the interface library, XiAnd mu is an average value vector of the interface library.
4. The method for generating an interface test script according to claim 1, wherein the obtaining and analyzing the interface configuration statement file of the interface to be tested to obtain the feature data of the interface to be tested specifically comprises:
acquiring an interface configuration statement file of an interface to be tested, and verifying the legality of the interface configuration statement file;
and if the verification is passed, analyzing the interface configuration statement file to obtain the characteristic data of the interface to be tested.
5. The method for generating an interface test script according to claim 1, wherein the analyzing the interface configuration declaration file to obtain the feature data of the interface to be tested specifically comprises:
analyzing the interface configuration statement file to obtain interface parameter data of the interface to be tested, wherein the interface parameter data comprises an interface request parameter, an interface return parameter and an interface definition description;
encoding the parameter type;
acquiring a parameter type received by an interface to be tested according to the interface request parameter, and acquiring a request parameter field type sequence vector of the interface to be tested according to a code corresponding to the received parameter type;
acquiring the parameter type of the interface response to be tested according to the interface return parameter, and acquiring a response parameter field type sequence vector of the interface to be tested according to the code corresponding to the parameter type of the response;
obtaining the number of the composite structure fields of the interface to be tested according to the number of the composite structure fields in the interface request parameters and the interface return parameters;
obtaining the number of the associated interfaces, the number of operation steps and the method types of the interfaces to be tested according to the interface definition description;
encoding a method category;
and obtaining the method type code of the interface to be tested according to the code corresponding to the method type.
6. The method for generating an interface test script according to claim 1, wherein the generating an interface metadata vector of the interface to be tested according to the feature data specifically comprises:
and generating an interface metadata vector of the interface to be tested according to the request parameter field type sequence vector, the number of associated interfaces, the number of operation steps, the number of composite structure fields, the method category code and the response parameter field type sequence vector of the interface to be tested.
7. The method for generating an interface test script according to claim 1, wherein the step of calculating the difference degree between the interface to be tested and each interface library respectively according to the interface metadata vector of the interface to be tested and the mean vector and the difference matrix of each interface library specifically comprises:
calculating the difference degree between the interface to be tested and the interface library according to a second formula, wherein the second formula is D (Y, G) ═ Y-mu) A-1(Y-μ)TWherein G is the interface library, Y is the interface metadata vector of the interface to be tested, mu is the mean vector of the interface library, A-1Is the inverse of the difference matrix of the class of interface library.
8. A computer-readable storage medium, on which a computer program is stored, which program, when being executed by a processor, carries out the steps of any of claims 1-7.
CN201811009575.4A 2018-08-31 2018-08-31 Interface test script generation method and computer readable storage medium Active CN109240923B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811009575.4A CN109240923B (en) 2018-08-31 2018-08-31 Interface test script generation method and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811009575.4A CN109240923B (en) 2018-08-31 2018-08-31 Interface test script generation method and computer readable storage medium

Publications (2)

Publication Number Publication Date
CN109240923A CN109240923A (en) 2019-01-18
CN109240923B true CN109240923B (en) 2021-06-04

Family

ID=65069267

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811009575.4A Active CN109240923B (en) 2018-08-31 2018-08-31 Interface test script generation method and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN109240923B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111562490B (en) * 2019-02-14 2023-01-20 深圳市汇顶科技股份有限公司 Test method and system
CN110262962A (en) * 2019-05-21 2019-09-20 钛马信息网络技术有限公司 Generate the method and device of test script

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105279090A (en) * 2015-11-17 2016-01-27 中国建设银行股份有限公司 Test script generating method and test script generating device applied in financial field
CN106354648A (en) * 2016-09-06 2017-01-25 深圳市广和通无线股份有限公司 python automatic test framework system and test method
CN107291608A (en) * 2016-03-31 2017-10-24 阿里巴巴集团控股有限公司 The generation method of test script, subscription/register method of interface and device
CN108363599A (en) * 2018-01-12 2018-08-03 深圳壹账通智能科技有限公司 User interface shows recognition methods and terminal device

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9928161B1 (en) * 2016-09-08 2018-03-27 Fmr Llc Automated quality assurance testing of browser-based applications

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105279090A (en) * 2015-11-17 2016-01-27 中国建设银行股份有限公司 Test script generating method and test script generating device applied in financial field
CN107291608A (en) * 2016-03-31 2017-10-24 阿里巴巴集团控股有限公司 The generation method of test script, subscription/register method of interface and device
CN106354648A (en) * 2016-09-06 2017-01-25 深圳市广和通无线股份有限公司 python automatic test framework system and test method
CN108363599A (en) * 2018-01-12 2018-08-03 深圳壹账通智能科技有限公司 User interface shows recognition methods and terminal device

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
Specification-Driven Automated Testing of;M. Assem1等;《IEEE》;20080321;1-5 *
内容与结构相结合的科学元数据相似度计算;王秀慧等;《计算机工程与设计》;20120816;1-5 *
自动生成测试脚本方案浅析;玉婷;《https://www.sohu.com/a/224590187_748431》;20180228;1-12 *

Also Published As

Publication number Publication date
CN109240923A (en) 2019-01-18

Similar Documents

Publication Publication Date Title
US10108535B2 (en) Web application test script generation to test software functionality
CN110716870B (en) Automatic service testing method and device
US7500149B2 (en) Generating finite state machines for software systems with asynchronous callbacks
US7895575B2 (en) Apparatus and method for generating test driver
CN103092751B (en) Web application performance test system based on customer behavior model in cloud environment
CN109815119B (en) APP link channel testing method and device
CN110955409B (en) Method and device for creating resources on cloud platform
US8661414B2 (en) Method and system for testing an order management system
Zhang et al. Environmental modeling for automated cloud application testing
CN111078555A (en) Test file generation method, system, server and storage medium
CN109240923B (en) Interface test script generation method and computer readable storage medium
CN111797020A (en) Mock data method and device based on dynamic bytecode
CN112667242A (en) Method and device for packaging C code into FMU
CN116245074A (en) Chip verification method, device and storage medium
CN108595656B (en) Data processing method and system
CN115470152A (en) Test code generation method, test code generation device, and storage medium
CN115033434A (en) Kernel performance theoretical value calculation method and device and storage medium
CN111625459A (en) Application program testing method and device, computer equipment and storage medium
CN110659215A (en) Open type industrial APP rapid development and test verification method
CN111026631A (en) Automatic interface detection method and device and server
CN116860324B (en) Development data processing method, development data processing apparatus, and readable storage medium
US11914503B2 (en) Automated performance measurement over software lifecycle
Probert et al. Life-cycle E-commerce testing with OO-TTCN-3
CN114116462A (en) Method and device for automatically testing and integrating front end and back end of Web project
CN114490398A (en) Method, device and equipment for testing consumer object

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant