CN113760702A - Unit testing method and device for small program - Google Patents

Unit testing method and device for small program Download PDF

Info

Publication number
CN113760702A
CN113760702A CN202010827049.XA CN202010827049A CN113760702A CN 113760702 A CN113760702 A CN 113760702A CN 202010827049 A CN202010827049 A CN 202010827049A CN 113760702 A CN113760702 A CN 113760702A
Authority
CN
China
Prior art keywords
format
code
format code
unit test
target node
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.)
Pending
Application number
CN202010827049.XA
Other languages
Chinese (zh)
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.)
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co 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 Beijing Jingdong Century Trading Co Ltd, Beijing Wodong Tianjun Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN202010827049.XA priority Critical patent/CN113760702A/en
Publication of CN113760702A publication Critical patent/CN113760702A/en
Pending legal-status Critical Current

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
    • 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/3692Test management for test results analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/80Information retrieval; Database structures therefor; File system structures therefor of semi-structured data, e.g. markup language structured data such as SGML, XML or HTML
    • G06F16/84Mapping; Conversion
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/37Compiler construction; Parser generation

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Software Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The invention discloses a method and a device for testing units of an applet, and relates to the technical field of computers. One embodiment of the method comprises: acquiring a first format code of the applet, and obtaining a syntactic structure corresponding to the first format code through analysis processing; converting the character string in the grammar structure into a second format code; and placing the second format code into the unit test file, and testing the unit test file by using the test framework to obtain a test result. The implementation mode improves the code quality, improves the safety factor of the small program and the agility in the development process, and also saves the test cost.

Description

Unit testing method and device for small program
Technical Field
The invention relates to the technical field of computers, in particular to a method and a device for testing units of an applet.
Background
A Mini Program (Mini Program) is an application that can be used without downloading and installing, and is a script language with a different format from JavaScript (JS), and has its own syntax. The script language of the small program runs on the view layer, the service data cannot be directly modified, and only the current component can be set. Currently, there is no unit testing framework for code dimension of applet scripting language, and the prior art generally adopts a unit testing tool set (such as miniprogam-library) for component dimension of a custom component to perform corresponding unit testing.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art:
the existing method has no method for carrying out unit test on codes corresponding to the small program scripting language, so that the code quality is poor, the safety coefficient of the small program is low, the agility of small program development is low, and the test cost is high.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for testing a cell of an applet, which can improve code quality, improve security coefficient of the applet and agility in a development process, and also save a large amount of test cost.
To achieve the above object, according to a first aspect of embodiments of the present invention, there is provided a cell test method for an applet, including:
acquiring a first format code of the applet, and obtaining a syntactic structure corresponding to the first format code through analysis processing;
converting the character string in the grammar structure into a second format code;
and placing the second format code into the unit test file, and testing the unit test file by using the test framework to obtain a test result.
Further, the step of converting the character string in the grammar structure into a second format code includes:
and inquiring and determining a target node in the grammar structure, and converting the character string in the target node into a second format code by using a mapping table between the script language corresponding to the first format code and the script language corresponding to the second format code, wherein the target node indicates different grammars between the script language corresponding to the first format code and the script language corresponding to the second format code.
Further, the step of querying and determining the target node in the grammar structure includes:
and traversing the syntactic structure, and determining a target node according to the mapping table.
Further, the step of traversing the syntax structure and determining the target node according to the mapping table further includes:
determining target levels corresponding to different syntaxes between the scripting language corresponding to the first format code and the scripting language corresponding to the second format code according to the mapping table;
and traversing the target level of the grammar structure to determine a target node.
Further, for the non-target nodes in the grammar structure, the method further comprises the following steps: and converting the character strings in the non-target nodes into the second format codes by using a syntax parser of the script language corresponding to the second format codes.
Further, still include: and compiling a script command in the unit test file, and monitoring and acquiring a second format code according to the script command by the unit test file when the unit test file is tested by using the test framework.
According to a second aspect of the embodiments of the present invention, there is provided a unit test apparatus of an applet, including:
the analysis processing module is used for acquiring a first format code of the applet and obtaining a syntactic structure corresponding to the first format code through analysis processing;
the code conversion module is used for converting the character strings in the grammar structure into second format codes;
and the unit test module is used for placing the second format codes into the unit test files and testing the unit test files by using the test framework to obtain test results.
Further, the transcoding module is further configured to: inquiring and determining a target node in a syntactic structure, and converting character strings in the target node into second format codes by using a mapping table between a script language corresponding to the first format codes and a script language corresponding to the second format codes; and for the non-target node in the grammar structure, converting the character strings in the non-target node into second format codes by using a grammar parser of the script language corresponding to the second format codes, wherein the target node indicates different grammars between the script language corresponding to the first format codes and the script language corresponding to the second format codes.
According to a third aspect of embodiments of the present invention, there is provided an electronic apparatus, including:
one or more processors;
a storage device for storing one or more programs,
when the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the unit testing method of any one of the applets as described above.
According to a fourth aspect of embodiments of the present invention, there is provided a computer-readable medium having stored thereon a computer program which, when executed by a processor, implements a unit testing method of any one of the applets described above.
One embodiment of the above invention has the following advantages or benefits: because the first format code of the small program is obtained, the syntactic structure corresponding to the first format code is obtained through analysis processing; converting the character string in the grammar structure into a second format code; the technical means that the second format codes are placed in the unit test file, the unit test file is tested by using the test framework, and the test result is obtained is overcome, so that the technical problems that the method for carrying out unit test on the codes corresponding to the small program scripting language cannot be adopted in the existing method, the derived codes are poor in quality, the safety coefficient of the small program is low, the development agility is low, and the test cost is high are solved, and the technical effects that the code quality is improved, the safety coefficient of the small program and the agility in the development process are improved, and the test cost is saved are achieved.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic diagram of a main flow of a unit test method of an applet provided according to a first embodiment of the present invention;
FIG. 2 is a schematic diagram of a main flow of a unit testing method of an applet provided according to a second embodiment of the present invention;
FIG. 3 is a schematic diagram of the main blocks of a unit test apparatus for an applet provided in accordance with an embodiment of the present invention;
FIG. 4 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 5 is a schematic block diagram of a computer system suitable for use in implementing a terminal device or server of an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
FIG. 1 is a schematic diagram of a main flow of a unit test method of an applet provided according to a first embodiment of the present invention; as shown in fig. 1, the unit testing method for an applet provided in the embodiment of the present invention mainly includes:
step S101, a first format code of the applet is obtained, and a grammar structure corresponding to the first format code is obtained through analysis processing.
Specifically, the first format code refers to a code corresponding to an applet scripting language; the Syntax structure refers to a structure obtained by analyzing the source code, and an AST (Abstract Syntax Tree) is a Tree structure corresponding to the analyzed source code.
And analyzing the first format code by using a grammar analyzer, wherein the returned result after analysis is a grammar structure consisting of a plurality of nodes, and the data in each node is a character string. After the syntactic structure corresponding to the first format code is obtained, the first format code can be subsequently converted into a second format code capable of executing unit test based on codes, and the unit test of the code dimension of the script language corresponding to the second format code is performed by using a unit test framework aiming at the code dimension of the script language corresponding to the second format code, so that the code dimension unit test of the code corresponding to the small program script language is realized, and the technical effect of improving the code quality is achieved.
Step S102, converting the character strings in the grammar structure into second format codes.
The second format code is a code written by a more widely applied scripting language, such as javascript, Python, and the like, and in the prior art, a unit test framework exists for performing unit test on the code of the widely applied scripting language.
Specifically, according to an embodiment of the present invention, the step of converting the character string in the syntax structure into the second format code includes:
and inquiring and determining a target node in the grammar structure, and converting the character string in the target node into a second format code by using a mapping table between the script language corresponding to the first format code and the script language corresponding to the second format code, wherein the target node indicates different grammars between the script language corresponding to the first format code and the script language corresponding to the second format code.
Specifically, according to a specific implementation manner of the embodiment of the present invention, when different grammars are added between two scripting languages, the method further includes: and updating the mapping table.
According to another specific implementation manner of the embodiment of the present invention, in actual application, the scripting language corresponding to the first format code is generally a subset of the second format code, but the scripting language corresponding to the first format code is also partially modified according to its own requirements (such as a customization scheme), so that the two scripting languages always have partially same syntax (a character string corresponding to the same syntax can be directly transcoded by a syntax parser corresponding to the converted scripting language), and partially different syntax (this part needs to be converted according to a mapping table of the two scripting languages), and by the above setting, the transcoding manners in the two cases are separated, which is beneficial to improving transcoding efficiency.
Further, according to an embodiment of the present invention, the step of querying and determining the target node in the syntax structure includes:
and traversing the syntactic structure, and determining a target node according to the mapping table.
Through the setting, different syntaxes between the script languages corresponding to the first format codes and the second format codes in the syntax structure are determined as target nodes by traversing the syntax structure corresponding to the first format codes, and the character strings in the target nodes are converted into the second format codes according to the mapping table.
Preferably, according to an embodiment of the present invention, the step of traversing the syntax structure and determining the target node according to the mapping table further includes:
determining target levels corresponding to different syntaxes between the scripting language corresponding to the first format code and the scripting language corresponding to the second format code according to the mapping table;
and traversing the target level of the grammar structure to determine a target node.
Through the setting, the target level corresponding to different grammars between the two scripting languages is determined through the mapping table, and as the different grammars are only in the identifier level, the whole grammar structure does not need to be traversed in the process of inquiring and determining the target node, and the target structure can be determined only by traversing each node of the identifier level. Through the arrangement, the efficiency of determining the target node is improved, and the code conversion efficiency is further improved.
Preferably, according to an embodiment of the present invention, the foregoing further includes, for the non-target node in the syntax structure: and converting the character strings in the non-target nodes into the second format codes by using a syntax parser of the script language corresponding to the second format codes.
For the same grammar between the two scripting languages, the character strings in the non-target nodes can be converted into the second format codes by directly using the grammar parser of the scripting language corresponding to the second format codes, so that the code conversion efficiency is further improved, and the unit test efficiency of the small program is improved.
Step S103, the second format code is placed into the unit test file, and the unit test file is tested by using the test framework to obtain a test result.
Specifically, the unit test file is written by a tester and contains a test case, the test framework runs the test case in the unit test file, and the test case runs by using the converted second format code.
Because the scripting language corresponding to the second format code has a test framework aiming at the code dimension, the code corresponding to the scripting language of the small program can be directly placed in a written unit test file after being converted into the second format code, the unit test is carried out by using the test framework, and the first format code of the small program is adjusted according to the test result, so that the code quality is improved, the test cost is saved, and the safety coefficient and the agility in the development process of the small program are improved.
Alternatively, according to an embodiment of the present invention, further comprising: and compiling a script command in the unit test file, and monitoring and acquiring a second format code according to the script command by the unit test file when the unit test file is tested by using the test framework.
Through the setting, the script commands such as shell scripts or npm scripts can be compiled, a tester only needs to compile the unit test files according to the test flow, the unit test files monitor and acquire the second format codes of script language code conversion of the small programs, then the unit test is conducted by utilizing the unit test building, through the setting, the tester does not need to pay attention to the code conversion process, namely, the code conversion is not required to be executed through display, the automation degree of the code conversion is improved, and the agility in the development process is further improved.
According to the technical scheme of the embodiment of the invention, the first format code of the applet is obtained, and the syntactic structure corresponding to the first format code is obtained through analysis processing; converting the character string in the grammar structure into a second format code; the technical means that the second format codes are placed in the unit test file, the unit test file is tested by using the test framework, and the test result is obtained is overcome, so that the technical problems that the method for carrying out unit test on the codes corresponding to the small program scripting language cannot be adopted in the existing method, the derived codes are poor in quality, the safety coefficient of the small program is low, the development agility is low, and the test cost is high are solved, and the technical effects that the code quality is improved, the safety coefficient of the small program and the agility in the development process are improved, and the test cost is saved are achieved.
FIG. 2 is a schematic diagram of a main flow of a unit testing method of an applet provided according to a second embodiment of the present invention; an application scenario of the embodiment of the present invention is to perform a unit test based on a code of a scripting language wxs (weixin script) corresponding to a wechat applet, as shown in fig. 2, where the method for unit test of an applet provided in the embodiment of the present invention mainly includes:
step S201, a first format code of the applet is obtained, and a syntax structure corresponding to the first format code is obtained through parsing.
The WXS is a set of scripting Language of the WeChat applet, mainly runs on a view layer, and can be combined with WXML (Weixin Markup Language, which is a set of tag Language for framework design) to construct a page structure. Essentially, WXS is a restricted JavaScript (an transliterated scripting language, JS for short) running in the view layer, that is, WXS belongs to a subset of JS and is partially customized. The two scripting languages are only examples and are not intended to limit the present invention.
Specifically, the parser for parsing the applet may be Esprima, peg. js, acornjs, babel-parser, etc.
In the embodiment of the invention, a grammar structure (such as AST, Abstract Syntax Tree) corresponding to the WXS is obtained by analyzing the first format code of the applet, a character string in the grammar structure is converted into a JS code through subsequent processing, and the unit test frame aiming at the JS code is used for performing unit test, so that the code quality is improved, and the test cost is reduced.
Step S202, traversing the grammar structure, and determining a target node and a non-target node in the grammar structure according to the mapping table. For the target node, performing step S203; for non-target nodes, step S204 is performed.
Specifically, different grammars between the two scripting languages can be determined according to a mapping table between the WXS and the JS, a query rule is formulated (the query rule can obtain the grammars different from the two scripting languages in a grammar tree structure), a grammar structure is traversed according to the query rule, a target node in the grammar structure corresponding to the applet is determined, and the other nodes are non-target nodes.
Further, according to the embodiment of the present invention, the levels of the different syntaxes between the two scripting languages can be determined according to the mapping table between the WXS and the JS, for example, the difference between the existing applet WXS and the JS is mainly the difference between the data type (such as the obtaining manner of the data type object) and the basic class library (such as the global variable and the global method), so that the unused language between the two scripting languages is located at the identifier level. Next, only the identifier hierarchy in the grammar structure needs to be traversed to determine the target node, and the whole grammar structure does not need to be traversed, so that the efficiency of determining the target node is further improved, and the code conversion efficiency is further improved.
Preferably, according to the embodiment of the present invention, for a case where different syntax is added in two scripting languages, the method further includes: the mapping table is updated.
Step S203, converting the character string in the target node into the second format code by using the mapping table between the script language corresponding to the first format code and the script language corresponding to the second format code.
According to the embodiment of the present invention, since the scripting language corresponding to the first format code is generally a subset of the second format code, but the scripting language corresponding to the first format code is also partially modified (such as a customized scheme) according to its own requirements, the two scripting languages often have partially same syntax (the character string corresponding to the same syntax can be directly transcoded by the parser corresponding to the converted scripting language), and partially different syntax (this part needs to be converted with respect to the mapping tables of the two scripting languages).
And step S204, converting the character strings in the non-target nodes into second format codes by using a syntax parser of the scripting language corresponding to the second format codes.
For the same grammar between the two scripting languages, the character strings in the non-target nodes can be converted into the second format codes by directly using the grammar parser of the scripting language corresponding to the second format codes, so that the code conversion efficiency is further improved, and the unit test efficiency of the small program is improved.
Step S205, placing the second format code in the target folder.
According to the embodiment of the invention, after the two types of character strings in the grammar structure are converted into the JS codes (namely, the second format codes), the JS codes are placed in the target folder (the target folder is specified by a tester, and the JS codes can be acquired from the target folder by using the unit test file subsequently to perform unit test). The JS code in the target folder may also be multiplexed.
Step S206, writing a script command in the unit test file, and monitoring and acquiring a second format code according to the script command when the unit test file is tested by using the test framework.
Specifically, according to the embodiment of the invention, script commands such as shell scripts or npm scripts can be written in the unit test file, a tester only needs to write the unit test file according to the test flow, the unit test file monitors and acquires the second format codes of script language code conversion of the applet, then the unit test is built by using the unit test to perform the unit test, and through the setting, the tester does not need to pay attention to the code conversion process, namely, does not need to display to execute the code conversion, so that the automation degree of the code conversion is improved, the agile type and the Continuous Integration/Continuous Deployment (CI/CO, representing the Continuous Integration/Continuous Deployment, representing the Continuous Deployment) of the applet development are facilitated, and the agility in the development process is improved.
Step S207, the unit test file is tested by using a test frame (such as jest) to obtain a test result.
And debugging and modifying the WXS code according to the test result, thereby improving the code quality and improving the safety factor of the small program version.
According to the technical scheme of the embodiment of the invention, the first format code of the applet is obtained, and the syntactic structure corresponding to the first format code is obtained through analysis processing; converting the character string in the grammar structure into a second format code; the technical means that the second format codes are placed in the unit test file, the unit test file is tested by using the test framework, and the test result is obtained is overcome, so that the technical problems that the method for carrying out unit test on the codes corresponding to the small program scripting language cannot be adopted in the existing method, the derived codes are poor in quality, the safety coefficient of the small program is low, the development agility is low, and the test cost is high are solved, and the technical effects that the code quality is improved, the safety coefficient of the small program and the agility in the development process are improved, and the test cost is saved are achieved.
FIG. 3 is a schematic diagram of the main blocks of a unit test apparatus for an applet provided in accordance with an embodiment of the present invention; as shown in fig. 3, the unit testing apparatus 300 according to the embodiment of the present invention mainly includes:
the parsing module 301 is configured to obtain a first format code of the applet, and obtain a syntax structure corresponding to the first format code through parsing.
Specifically, the first format code refers to a code corresponding to an applet scripting language; the grammar structure is a structure obtained by analyzing the source code.
And analyzing the first format code by using a grammar analyzer, wherein the returned result after analysis is a grammar structure consisting of a plurality of nodes, and the data in each node is a character string. After the syntactic structure corresponding to the first format code is obtained, the first format code can be subsequently converted into a second format code capable of executing unit test based on codes, and the unit test of the code dimension of the script language corresponding to the second format code is performed by using a unit test framework aiming at the code dimension of the script language corresponding to the second format code, so that the code dimension unit test of the code corresponding to the small program script language is realized, and the technical effect of improving the code quality is achieved.
A code conversion module 302, configured to convert the character string in the syntax structure into a second format code.
The second format code is a code written by using a script language with wider application, and a unit test framework for performing unit test on the code of the script language with wider application exists in the prior art.
Specifically, according to an embodiment of the present invention, the transcoding module 302 is further configured to: and inquiring and determining a target node in the grammar structure, and converting the character string in the target node into a second format code by using a mapping table between the script language corresponding to the first format code and the script language corresponding to the second format code, wherein the target node indicates different grammars between the script language corresponding to the first format code and the script language corresponding to the second format code.
Specifically, according to a specific implementation manner of the embodiment of the present invention, when a different syntax is added between two scripting languages, the unit testing apparatus 300 further includes a mapping table updating module, configured to: and updating the mapping table.
According to another specific implementation manner of the embodiment of the present invention, in actual application, the scripting language corresponding to the first format code is generally a subset of the second format code, but the scripting language corresponding to the first format code is also partially modified according to its own requirements (such as a customization scheme), so that the two scripting languages always have partially same syntax (a character string corresponding to the same syntax can be directly transcoded by a syntax parser corresponding to the converted scripting language), and partially different syntax (this part needs to be converted according to a mapping table of the two scripting languages), and by the above setting, the transcoding manners in the two cases are separated, which is beneficial to improving transcoding efficiency.
Further, according to an embodiment of the present invention, the code conversion module 302 is further configured to: and traversing the syntactic structure, and determining a target node according to the mapping table.
Through the setting, different syntaxes between the script languages corresponding to the first format codes and the second format codes in the syntax structure are determined as target nodes by traversing the syntax structure corresponding to the first format codes, and the character strings in the target nodes are converted into the second format codes according to the mapping table.
Preferably, according to the embodiment of the present invention, the code conversion module 302 is further configured to: determining target levels corresponding to different syntaxes between the scripting language corresponding to the first format code and the scripting language corresponding to the second format code according to the mapping table; and traversing the target level of the grammar structure to determine a target node.
Through the setting, the target level corresponding to different grammars between the two scripting languages is determined through the mapping table, and as the different grammars are only in the identifier level, the whole grammar structure does not need to be traversed in the process of inquiring and determining the target node, and the target structure can be determined only by traversing each node of the identifier level. Through the arrangement, the efficiency of determining the target node is improved, and the code conversion efficiency is further improved.
Preferably, for non-target nodes in the syntax structure, the transcoding module 302 is further configured to: and converting the character strings in the non-target nodes into the second format codes by using a syntax parser of the script language corresponding to the second format codes.
For the same grammar between the two scripting languages, the character strings in the non-target nodes can be converted into the second format codes by directly using the grammar parser of the scripting language corresponding to the second format codes, so that the code conversion efficiency is further improved, and the unit test efficiency of the small program is improved.
The unit test module 303 is configured to put the second format code into the unit test file, and test the unit test file by using the test frame to obtain a test result.
Because the scripting language corresponding to the second format code has a test framework aiming at the code dimension, the code corresponding to the scripting language of the small program can be directly placed in a written unit test file after being converted into the second format code, the unit test is carried out by using the test framework, and the first format code of the small program is adjusted according to the test result, so that the code quality is improved, the test cost is saved, and the safety coefficient and the agility in the development process of the small program are improved.
Alternatively, according to an embodiment of the present invention, the unit test module 303 may be further configured to: and compiling a script command in the unit test file, and monitoring and acquiring a second format code according to the script command by the unit test file when the unit test file is tested by using the test framework.
By compiling the script command, a tester only needs to compile the unit test file according to the test flow, the unit test file monitors and acquires the second format codes of the script language code conversion of the small program, and then the unit test is carried out by utilizing the unit test set.
According to the technical scheme of the embodiment of the invention, the first format code of the applet is obtained, and the syntactic structure corresponding to the first format code is obtained through analysis processing; converting the character string in the grammar structure into a second format code; the technical means that the second format codes are placed in the unit test file, the unit test file is tested by using the test framework, and the test result is obtained is overcome, so that the technical problems that the method for carrying out unit test on the codes corresponding to the small program scripting language cannot be adopted in the existing method, the derived codes are poor in quality, the safety coefficient of the small program is low, the development agility is low, and the test cost is high are solved, and the technical effects that the code quality is improved, the safety coefficient of the small program and the agility in the development process are improved, and the test cost is saved are achieved.
Fig. 4 shows an exemplary system architecture 400 of a unit test method of an applet or a unit test apparatus of an applet to which embodiments of the present invention may be applied.
As shown in fig. 4, the system architecture 400 may include terminal devices 401, 402, 403, a network 404, and a server 405 (this architecture is merely an example, and the components included in a particular architecture may be adapted according to application specific circumstances). The network 404 serves as a medium for providing communication links between the terminal devices 401, 402, 403 and the server 405. Network 404 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use terminal devices 401, 402, 403 to interact with a server 405 over a network 404 to receive or send messages or the like. The terminal devices 401, 402, 403 may have installed thereon various communication client applications, such as shopping-like applications, web browser applications, search-like applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only).
The terminal devices 401, 402, 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 405 may be a server providing various services, such as a background management server (for example only) providing support for shopping websites browsed by users using the terminal devices 401, 402, 403. The backend management server may analyze and perform other processing on the received data such as the first format code, and feed back a processing result (e.g., a syntax structure, a target node, a test result, which is merely an example) to the terminal device.
It should be noted that the unit testing method for the applet provided in the embodiment of the present invention is generally executed by the server 405, and accordingly, the unit testing apparatus for the applet is generally disposed in the server 405.
It should be understood that the number of terminal devices, networks, and servers in fig. 4 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 5, shown is a block diagram of a computer system 500 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 5 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 5, the computer system 500 includes a Central Processing Unit (CPU)501 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)502 or a program loaded from a storage section 508 into a Random Access Memory (RAM) 503. In the RAM 503, various programs and data necessary for the operation of the system 500 are also stored. The CPU 501, ROM 502, and RAM 503 are connected to each other via a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
The following components are connected to the I/O interface 505: an input portion 506 including a keyboard, a mouse, and the like; an output portion 507 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 508 including a hard disk and the like; and a communication section 509 including a network interface card such as a LAN card, a modem, or the like. The communication section 509 performs communication processing via a network such as the internet. The driver 510 is also connected to the I/O interface 505 as necessary. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as necessary, so that a computer program read out therefrom is mounted into the storage section 508 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 509, and/or installed from the removable medium 511. The computer program performs the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 501.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes a parsing processing module, a transcoding module, and a unit testing module. The names of the modules do not limit the modules themselves in some cases, for example, the parsing module may also be described as "a module for acquiring a first format code of an applet and obtaining a syntax structure corresponding to the first format code through parsing".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: acquiring a first format code of the applet, and obtaining a syntactic structure corresponding to the first format code through analysis processing; converting the character string in the grammar structure into a second format code; and placing the second format code into the unit test file, and testing the unit test file by using the test framework to obtain a test result.
According to the technical scheme of the embodiment of the invention, the first format code of the applet is obtained, and the syntactic structure corresponding to the first format code is obtained through analysis processing; converting the character string in the grammar structure into a second format code; the technical means that the second format codes are placed in the unit test file, the unit test file is tested by using the test framework, and the test result is obtained is overcome, so that the technical problems that the method for carrying out unit test on the codes corresponding to the small program scripting language cannot be adopted in the existing method, the derived codes are poor in quality, the safety coefficient of the small program is low, the development agility is low, and the test cost is high are solved, and the technical effects that the code quality is improved, the safety coefficient of the small program and the agility in the development process are improved, and the test cost is saved are achieved.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1. A method for cell testing of an applet, comprising:
acquiring a first format code of an applet, and obtaining a syntactic structure corresponding to the first format code through analysis processing;
converting the character string in the grammar structure into a second format code;
and placing the second format code into a unit test file, and testing the unit test file by using a test frame to obtain a test result.
2. The method for unit testing of an applet according to claim 1, wherein the step of converting the character strings in the grammar structure into a second format code comprises:
and inquiring and determining a target node in the grammar structure, and converting the character string in the target node into a second format code by using a mapping table between the script language corresponding to the first format code and the script language corresponding to the second format code, wherein the target node indicates different grammars between the script language corresponding to the first format code and the script language corresponding to the second format code.
3. The method for unit testing of applets of claim 2 wherein said step of querying and determining a target node in said grammar structure comprises:
and traversing the syntactic structure, and determining the target node according to the mapping table.
4. The method for unit testing of applets of claim 3, wherein said step of traversing said syntax structure to determine said target node from said mapping table further comprises:
determining a target level corresponding to different syntaxes between the scripting language corresponding to the first format code and the scripting language corresponding to the second format code according to the mapping table;
and traversing a target level of the grammar structure to determine the target node.
5. The applet unit test method according to claim 2, further comprising, for non-target nodes in the grammar structure: and converting the character strings in the non-target nodes into second format codes by using a syntax parser of the scripting language corresponding to the second format codes.
6. The applet unit test method according to claim 1, further comprising: and compiling a script command in the unit test file, and monitoring and acquiring the second format code according to the script command by the unit test file when the unit test file is tested by using a test frame.
7. An applet cell test apparatus, comprising:
the analysis processing module is used for acquiring a first format code of the applet and obtaining a syntactic structure corresponding to the first format code through analysis processing;
the code conversion module is used for converting the character strings in the grammar structure into second format codes;
and the unit test module is used for placing the second format codes into a unit test file, and testing the unit test file by using a test frame to obtain a test result.
8. The applet unit test apparatus according to claim 7, wherein the code conversion module is further adapted to: inquiring and determining a target node in the syntactic structure, and converting character strings in the target node into second format codes by using a mapping table between the script language corresponding to the first format codes and the script language corresponding to the second format codes; for a non-target node in the grammar structure, converting the character string in the non-target node into a second format code by using a grammar parser of a script language corresponding to the second format code, wherein the target node indicates different grammars between the script language corresponding to the first format code and the script language corresponding to the second format code.
9. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-6.
10. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-6.
CN202010827049.XA 2020-08-17 2020-08-17 Unit testing method and device for small program Pending CN113760702A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010827049.XA CN113760702A (en) 2020-08-17 2020-08-17 Unit testing method and device for small program

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010827049.XA CN113760702A (en) 2020-08-17 2020-08-17 Unit testing method and device for small program

Publications (1)

Publication Number Publication Date
CN113760702A true CN113760702A (en) 2021-12-07

Family

ID=78785588

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010827049.XA Pending CN113760702A (en) 2020-08-17 2020-08-17 Unit testing method and device for small program

Country Status (1)

Country Link
CN (1) CN113760702A (en)

Similar Documents

Publication Publication Date Title
CN112104709B (en) Intelligent contract processing method, device, medium and electronic equipment
CN110688096B (en) Method and device for constructing application program containing plug-in, medium and electronic equipment
CN110780874B (en) Method and device for generating information
US11934287B2 (en) Method, electronic device and computer program product for processing data
CN113760729A (en) Code detection method and device
CN113010405A (en) Application program testing method and device
CN111309304B (en) Method, device, medium and electronic equipment for generating IDL file
CN113778897B (en) Automatic test method, device and equipment for interface and storage medium
CN113419740A (en) Program data stream analysis method and device, electronic device and readable storage medium
CN112559024A (en) Method and device for generating transaction code change list
CN113138767B (en) Code language conversion method, device, electronic equipment and storage medium
CN112346774A (en) Method and device for generating application installation package
CN113760702A (en) Unit testing method and device for small program
CN113515306B (en) System transplanting method and device
CN110806967A (en) Unit testing method and device
CN115640279A (en) Method and device for constructing data blood relationship
CN113760274B (en) Front-end assembly logic injection method and device
CN114625373A (en) Application conversion method and device, electronic equipment and storage medium
CN112988583A (en) Method and device for testing syntax compatibility of database
CN113779018A (en) Data processing method and device
CN113760698A (en) Method and device for converting test case file data
CN113342633B (en) Performance test method and device
CN112965747B (en) Method, apparatus, device and computer readable medium for mining code loopholes
CN112287097B (en) Method and device for analyzing markup language text, storage medium and electronic equipment
CN113110947B (en) Program call chain generation method, system, electronic device and medium

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