A unit testing method and device for applets

By parsing the first format code of the applet, converting it to the second format code, and testing it in the unit test file, the problem of lack of small program scripting language code unit testing in the existing technology is solved, and the effect of improving code quality and saving testing costs is achieved.

CN113760702BActive Publication Date: 2025-06-17BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202010827049.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-08-17
Publication Date
2025-06-17
Estimated Expiration
2040-08-17

AI Technical Summary

Technical Problem

There is a lack of methods for unit testing of code in the mini-program scripting language in the prior art, resulting in poor code quality, low security factor of mini-programs, low development agility and high testing costs.

Method used

By obtaining the first format code of the applet, the parsing process obtains the syntax structure, converting the strings in the syntax structure into the second format code, and putting them into the unit test file, and testing is performed using the test framework to obtain the test results.

Benefits of technology

Improves code quality, improves the security factor of the applet and agility in the development process, and saves testing costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113760702B_ABST
    Figure CN113760702B_ABST
Patent Text Reader

Abstract

The present invention discloses a unit testing method and device for applets, relating to the field of computer technology. A specific implementation of the method includes: obtaining the first-format code of the applet, and obtaining the syntax structure corresponding to the first-format code through parsing; converting the strings in the syntax structure into second-format code; placing the second-format code into a unit test file, and using a test framework to test the unit test file to obtain a test result. This implementation improves the code quality, enhances the security factor of the applet and the agility in the development process, and also saves the test cost.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a unit testing method and device for a small program. Background Art

[0002] Mini Program is an application that can be used without downloading and installing. It is a scripting language with a different format from JavaScript (a translated scripting language, referred to as JS) and has its own syntax. The scripting language of the mini program runs in the view layer and cannot directly modify business data. It can only set the current component. At present, there is no unit testing framework for the code dimension of the mini program scripting language. The existing technology generally uses a unit testing tool set (such as miniprogram-simulate) for the component dimension of custom components to perform corresponding unit testing.

[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:

[0004] There is no method for unit testing the code corresponding to the mini-program scripting language in the existing methods, resulting in poor code quality, low mini-program security factor, low agility of mini-program development, and high testing costs. Summary of the invention

[0005] In view of this, an embodiment of the present invention provides a unit testing method and device for a mini-program, which can improve code quality, increase the safety factor of the mini-program and the agility of the development process, and save a lot of testing costs.

[0006] To achieve the above object, according to a first aspect of an embodiment of the present invention, a unit testing method for an applet is provided, comprising:

[0007] Obtaining a first format code of the mini-program, and obtaining a grammatical structure corresponding to the first format code through parsing;

[0008] Convert the string in the syntax structure to the second format code;

[0009] The second format code is placed into a unit test file, and the unit test file is tested using a test framework to obtain a test result.

[0010] Furthermore, the step of converting the character string in the grammatical structure into a second format code includes:

[0011] Query and determine the target node in the syntax structure, and use the mapping table between the scripting language corresponding to the first format code and the scripting language corresponding to the second format code to convert the string within the target node into the second format code, where the target node indicates the different syntax between the scripting language corresponding to the first format code and the scripting language corresponding to the second format code.

[0012] Further, the steps of querying and determining the target node in the syntax structure include:

[0013] Traverse the syntax structure and determine the target node according to the mapping table.

[0014] Further, the steps of traversing the syntax structure and determining the target node according to the mapping table further include:

[0015] Determine the target level corresponding to the different syntax 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;

[0016] Traverse the target level of the syntax structure to determine the target node.

[0017] Further, for non-target nodes in the syntax structure, it further includes: using the syntax parser of the scripting language corresponding to the second format code to convert the string within the non-target node into the second format code.

[0018] Further, it further includes: writing script commands in the unit test file, and when using the test framework to test the unit test file, the unit test file listens for and obtains the second format code according to the script commands.

[0019] According to the second aspect of the embodiments of the present invention, a unit test device for a mini-program is provided, including:

[0020] A parsing and processing module, configured to obtain the first format code of the mini-program and obtain the syntax structure corresponding to the first format code through parsing and processing;

[0021] A code conversion module, configured to convert the string within the syntax structure into the second format code;

[0022] A unit test module, configured to place the second format code into the unit test file and use the test framework to test the unit test file to obtain a test result.

[0023] Further, the code conversion module is further configured to: query and determine a target node in the syntax structure, and convert the string in the target node into the second format code by using a mapping table between the scripting language corresponding to the first format code and the scripting language corresponding to the second format code; for non-target nodes in the syntax structure, use the syntax parser of the scripting language corresponding to the second format code to convert the string in the non-target node into the second format code, where the target node indicates different syntaxes between the scripting language corresponding to the first format code and the scripting language corresponding to the second format code.

[0024] According to a third aspect of the embodiments of the present invention, there is provided an electronic device, including:

[0025] One or more processors;

[0026] A storage device for storing one or more programs,

[0027] When the one or more programs are executed by the one or more processors, the one or more processors implement the unit test method of any one of the above small programs.

[0028] According to a fourth aspect of the embodiments of the present invention, there is provided a computer-readable medium, on which a computer program is stored, and when the program is executed by a processor, the unit test method of any one of the above small programs is implemented.

[0029] One embodiment of the above invention has the following advantages or beneficial effects: Because the technical means of obtaining the first format code of the small program, obtaining the syntax structure corresponding to the first format code through parsing and processing; converting the string in the syntax structure into the second format code; placing the second format code into the unit test file, and using the test framework to test the unit test file to obtain the test result are adopted, the technical problems of poor code quality, low security factor of the small program, low development agility, and high test cost in the existing methods are overcome, and further the technical effects of improving the code quality, increasing the security factor of the small program and the agility in the development process, and saving the test cost are achieved.

[0030] The further effects of the above non-conventional optional manners will be described in conjunction with specific embodiments below. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] The drawings are used to better understand the present invention and do not constitute an improper limitation to the present invention. Among them:

[0032] Figure 1 is a schematic diagram of the main process of the unit test method of the small program according to the first embodiment of the present invention;

[0033] Figure 2 It is a schematic diagram of the main process of the unit test method for the mini program provided in the second embodiment of the present invention;

[0034] Figure 3 It is a schematic diagram of the main modules of the unit test device for the mini program provided in the embodiment of the present invention;

[0035] Figure 4 It is an exemplary system architecture diagram to which the embodiments of the present invention can be applied;

[0036] Figure 5 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing the embodiments of the present invention. Detailed implementation manners

[0037] The following describes exemplary embodiments of the present invention with reference to the accompanying drawings. Various details of the embodiments of the present invention are included to facilitate understanding, and they should be considered merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0038] Figure 1 It is a schematic diagram of the main process of the unit test method for the mini program provided in the first embodiment of the present invention; as Figure 1 shown, the unit test method for the mini program provided in the embodiment of the present invention mainly includes:

[0039] Step S101, obtain the first-format code of the mini program, and obtain the syntax structure corresponding to the first-format code through parsing.

[0040] Specifically, the first-format code refers to the code corresponding to the mini program scripting language; the syntax structure refers to the structure obtained after parsing the source code. For example, the AST (Abstract Syntax Tree) is the tree-like structure corresponding to the parsed source code.

[0041] Use a syntax parser to parse the first-format code. The result returned after parsing is the syntax structure composed of multiple nodes, where the data in each node is a string. After obtaining the syntax structure corresponding to the first-format code, the first-format code can be subsequently converted into a second-format code that can perform unit tests based on the code. Use a unit test framework for the code dimension of the scripting language corresponding to the second-format code to perform unit tests on the second-format code, thereby implementing unit tests on the code corresponding to the mini program scripting language and achieving the technical effect of improving code quality.

[0042] Step S102, convert the string within the syntax structure into the second format code.

[0043] The second format code is code written in a more widely used scripting language, such as JavaScript, Python, etc. In the prior art, there is a unit test framework for unit testing the code of such widely used scripting languages.

[0044] Specifically, according to an embodiment of the present invention, the above step of converting the string within the syntax structure into the second format code includes:

[0045] Query and determine the target node in the syntax structure, and convert the string within the target node into the second format code by using the mapping table between the scripting language corresponding to the first format code and the scripting language corresponding to the second format code, where the target node indicates different grammars between the scripting language corresponding to the first format code and the scripting language corresponding to the second format code.

[0046] Specifically, according to a specific implementation manner of an embodiment of the present invention, when there are newly added different grammars between the two scripting languages, it further includes: updating the above mapping table.

[0047] According to another specific implementation manner of an 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 has also been partially modified for its own needs (such as a customized solution). Therefore, the two scripting languages often have some identical grammars (the strings corresponding to the identical grammars can be directly converted by the syntax parser corresponding to the converted scripting language), and some different grammars (this part needs to be converted according to the mapping table between the two scripting languages). Through the above settings, separating the code conversion methods for the two situations is beneficial to improving the code conversion efficiency.

[0048] Further, according to an embodiment of the present invention, the above step of querying and determining the target node in the syntax structure includes:

[0049] Traverse the syntax structure and determine the target node according to the mapping table.

[0050] Through the above settings, by traversing the syntax structure corresponding to the first format code, the different grammars between the first format code and the scripting language corresponding to the second format code in the syntax structure are determined as the target nodes, and the strings within the target nodes are converted into the second format code according to the mapping table.

[0051] Preferably, according to an embodiment of the present invention, the above step of traversing the syntax structure and determining the target node according to the mapping table further includes:

[0052] Determine the target level corresponding to the different grammars 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;

[0053] Traverse the target level of the grammar structure to determine the target node.

[0054] Through the above settings, first determine the target level corresponding to the different grammars between the two scripting languages according to the mapping table. If the above different grammars are only at the identifier level, then in the process of querying and determining the target node, it is not necessary to traverse the entire grammar structure. Only by traversing the nodes at the identifier level can the target structure be determined. Through the above settings, the efficiency of determining the target node is improved, and thus the code conversion efficiency is enhanced.

[0055] Preferably, according to the embodiments of the present invention, for the non-target nodes in the grammar structure, it further includes: using the grammar parser of the scripting language corresponding to the second format code to convert the string in the non-target node into the second format code.

[0056] For the same grammar between the two scripting languages, directly using the grammar parser of the scripting language corresponding to the second format code can convert the string in the non-target node into the second format code, further enhancing the code conversion efficiency, and thus enhancing the unit test efficiency of the applet.

[0057] Step S103, place the second format code into the unit test file, and use the test framework to test the unit test file to obtain the test result.

[0058] Specifically, the unit test file is a unit test file written by the tester and containing test cases. The test framework runs the test cases in the unit test file, and the running of the test cases will use the converted second format code.

[0059] Since the scripting language corresponding to the second format code has a test framework for the code dimension, after converting the code corresponding to the scripting language of the applet into the second format code, it can be directly placed into the written unit test file, and the unit test is performed using the test framework. According to the test result, the first format code of the applet is adjusted to improve the code quality, save the test cost, and improve the security factor and agility in the development process of the applet.

[0060] Alternatively, according to the embodiments of the present invention, it further includes: writing a script command in the unit test file. When using the test framework to test the unit test file, the unit test file listens for and obtains the second format code according to the script command.

[0061] Through the above settings, by writing shell scripts or npm scripts and other script commands, testers only need to write unit test files according to the test process. The unit test files listen to and obtain the second format code converted from the script language code of the mini program, and then use the unit test component to perform unit testing. Through the above settings, testers do not need to pay attention to the code conversion process, that is, there is no need to explicitly perform code conversion, which improves the degree of automation of code conversion and further improves the agility of the development process.

[0062] According to the technical solution of the embodiment of the present invention, the first format code of the mini-program is obtained, and the grammatical structure corresponding to the first format code is obtained through parsing; the character string in the grammatical structure is converted into a second format code; the second format code is placed in a unit test file, and the unit test file is tested using a test framework to obtain a test result. Therefore, the technical problems of the existing method that is unable to perform unit testing on the code corresponding to the mini-program script language, resulting in poor code quality, low mini-program security factor, low development agility, and high testing cost are overcome, thereby achieving the technical effect of improving code quality, improving the security factor of the mini-program and the agility of the development process, and saving testing costs.

[0063] Figure 2 is a schematic diagram of the main process of the unit testing method of the mini program provided according to the second embodiment of the present invention; an application scenario of the embodiment of the present invention is to perform unit testing based on the code of the scripting language WXS (WeiXin Script) corresponding to the WeChat mini program, such as Figure 2 As shown, the unit testing method of the mini-program provided by the embodiment of the present invention mainly includes:

[0064] Step S201, obtaining a first format code of the mini program, and obtaining a grammatical structure corresponding to the first format code through parsing.

[0065] WXS is a scripting language for WeChat applets, which mainly runs in the view layer. It can build page structures in combination with WXML (WeiXinMarkup Language, a set of tag languages ​​designed for frameworks). In essence, WXS is a restricted JavaScript (a literal scripting language, JS for short) that runs in the view layer, that is, WXS is a subset of JS and has been partially customized. The above two scripting languages ​​are only examples and are not intended to limit the present invention.

[0066] Specifically, the syntax parser for parsing the mini program may be Esprima, PEG.js, acornjs, babel-parser, etc.

[0067] In the prior art, there is no unit test framework for WXS code. In the embodiments of the present invention, the first format code of the applet is parsed to obtain the syntax structure corresponding to WXS (such as AST, Abstract Syntax Tree, abstract syntax tree), and the strings in the syntax structure are converted into JS code through subsequent processing, and the unit test framework for JS code is used for unit testing to improve the code quality and reduce the test cost.

[0068] Step S202: Traverse the syntax structure, and determine the target nodes and non-target nodes in the syntax structure according to the mapping table. For the target nodes, execute step S203; for the non-target nodes, execute step S204.

[0069] Specifically, the different grammars between the two scripting languages can be determined according to the mapping table between WXS and JS, and a query rule can be formulated (the query rule can obtain the different grammars of the two scripting languages in the syntax tree structure). According to this query rule, traverse the syntax structure to determine the target nodes in the syntax structure corresponding to the applet, and the remaining nodes are non-target nodes.

[0070] Further, according to the embodiments of the present invention, the level where the different grammars between the two scripting languages are located can also be determined first according to the mapping table between WXS and JS. For example, the current differences between applet WXS and JS are mainly in data types (such as the acquisition method of data type objects, etc.) and basic class libraries (such as global variables and global methods, etc.), so the different languages between the two scripting languages are at the identifier level. Next, only need to traverse the identifier level in the syntax structure to determine the target nodes, and there is no need to traverse the entire syntax structure, which further improves the efficiency of determining the target nodes and thus improves the code conversion efficiency.

[0071] Preferably, according to the embodiments of the present invention, for the case where new different grammars are added in the two scripting languages, it further includes: updating the mapping table.

[0072] Step S203: Use the mapping table between the scripting language corresponding to the first format code and the scripting language corresponding to the second format code to convert the strings in the target nodes into the second format code.

[0073] According to an 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 has also been partially modified for its own needs (such as a customization solution), therefore, the two scripting languages often have some identical grammars (strings corresponding to the identical grammar compositions can be directly code-converted through the grammar parser corresponding to the converted scripting language), and some different grammars (this part needs to be converted according to the mapping table of the two scripting languages). Through the above settings, separating the code conversion methods for the two situations is beneficial to improving the code conversion efficiency.

[0074] Step S204, use the grammar parser of the scripting language corresponding to the second format code to convert the string within the non-target node into the second format code.

[0075] For the identical grammars between the two scripting languages, the grammar parser of the scripting language corresponding to the second format code can directly convert the string within the non-target node into the second format code, further improving the code conversion efficiency, and thus improving the unit test efficiency of the applet.

[0076] Step S205, place the second format code in the target folder.

[0077] According to an embodiment of the present invention, after converting the two types of strings in the grammar structure into JS code (i.e., the second format code), place the JS code in the target folder (the target folder is specified by the tester, and subsequently, the unit test file can obtain the JS code from the target folder for unit testing). The JS code in this target folder can also be reused.

[0078] Step S206, write a script command in the unit test file. When using the test framework to test the unit test file, the unit test file listens for and obtains the second format code according to the script command.

[0079] Specifically, according to an embodiment of the present invention, a shell script or an npm script, etc., can be written in the unit test file. The tester only needs to write the unit test file according to the test process. The unit test file listens for and obtains the second format code converted from the scripting language code of the applet, and then uses the unit test component to perform unit testing. Through the above settings, the tester does not need to pay attention to the code conversion process, that is, there is no need to explicitly execute the code conversion, improving the automation degree of code conversion, which is beneficial to the agile transformation and continuous integration / continuous deployment (CI / CD, Continuous Integration represents continuous integration / Continuous Deployment represents continuous deployment) of applet development, and improving the agility during the development process.

[0080] Step S207: Use a test framework (such as jest) to test the unit test file and obtain the test results.

[0081] Based on the test results, the WXS code can be debugged and modified, thereby improving the code quality and enhancing the security factor of the applet version.

[0082] According to the technical solution of the embodiment of the present invention, by adopting the technical means of obtaining the first-format code of the applet, parsing and processing to obtain the syntax structure corresponding to the first-format code; converting the strings in the syntax structure into the second-format code; placing the second-format code into the unit test file, and using the test framework to test the unit test file to obtain the test results, it overcomes the technical problems in the existing methods, such as the inability to perform unit tests on the code corresponding to the applet scripting language, resulting in poor code quality, low security factor of the applet, low development agility, and high test cost. Furthermore, it achieves the technical effects of improving the code quality, enhancing the security factor and development agility during the development process of the applet, and saving the test cost.

[0083] Figure 3 It is a schematic diagram of the main modules of the unit test device for the applet provided by the embodiment of the present invention; as Figure 3 shown, the unit test device 300 provided by the embodiment of the present invention mainly includes:

[0084] The parsing and processing module 301 is used to obtain the first-format code of the applet and obtain the syntax structure corresponding to the first-format code through parsing and processing.

[0085] Specifically, the first-format code refers to the code corresponding to the applet scripting language; the syntax structure refers to the structure obtained after parsing the source code.

[0086] Use a syntax parser to parse and process the first-format code. The result returned after parsing is the syntax structure composed of multiple nodes, where the data in each node is a string. After obtaining the syntax structure corresponding to the first-format code, subsequently, the first-format code can be converted into the second-format code that can perform unit tests based on the code. Use the unit test framework for the code dimension corresponding to the scripting language of the second-format code to perform unit tests on the second-format code, thereby realizing unit tests for the code corresponding to the applet scripting language in terms of code dimension, so as to achieve the technical effect of improving the code quality.

[0087] The code conversion module 302 is used to convert the strings in the syntax structure into the second-format code.

[0088] The second format code is code written in a more widely used scripting language, and there is a unit test framework in the prior art for unit testing the code of this widely used scripting language.

[0089] Specifically, according to an embodiment of the present invention, the code conversion module 302 is further configured to: query and determine a target node in the syntax structure, and convert the string in the target node into the second format code by using a mapping table between the scripting language corresponding to the first format code and the scripting language corresponding to the second format code, where the target node indicates different syntaxes between the scripting language corresponding to the first format code and the scripting language corresponding to the second format code.

[0090] Specifically, according to a specific implementation manner of an embodiment of the present invention, when new different syntaxes are added between two scripting languages, the unit test device 300 further includes a mapping table update module, which is configured to: update the above mapping table.

[0091] According to another specific implementation manner of an 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 has also been partially modified for its own needs (such as a customization solution). Therefore, the two scripting languages often have some identical syntaxes (strings corresponding to the identical syntaxes can be directly converted by the syntax parser corresponding to the converted scripting language), and some different syntaxes (this part requires conversion according to the mapping table between the two scripting languages). Through the above settings, the code conversion methods for the two situations are separated, which is beneficial to improving the code conversion efficiency.

[0092] Further, according to an embodiment of the present invention, the code conversion module 302 is further configured to: traverse the syntax structure and determine the target node according to the mapping table.

[0093] Through the above settings, by traversing the syntax structure corresponding to the first format code, the different syntaxes between the scripting language corresponding to the first format code and the scripting language corresponding to the second format code in this syntax structure are determined as target nodes, and the strings in the target nodes are converted into the second format code according to the mapping table.

[0094] Preferably, according to an embodiment of the present invention, the code conversion module 302 is further configured to: determine the target level corresponding to the 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; traverse the target level of the syntax structure to determine the target node.

[0095] With the above settings, first, the target levels corresponding to different grammars between the two scripting languages are determined through the mapping table. For example, if the different grammars are only at the identifier level as described above, then during the process of querying and determining the target nodes, it is not necessary to traverse the entire grammar structure. Only by traversing the nodes at the identifier level can the target structure be determined. Through the above settings, the efficiency of determining the target nodes is improved, and thus the code conversion efficiency is enhanced.

[0096] Preferably, according to an embodiment of the present invention, for non-target nodes in the grammar structure, the code conversion module 302 is further configured to: use the grammar parser of the scripting language corresponding to the second format code to convert the string within the non-target node into the second format code.

[0097] For the same grammar between the two scripting languages, the grammar parser of the scripting language corresponding to the second format code can directly convert the string within the non-target node into the second format code, further enhancing the code conversion efficiency, and thus improving the unit test efficiency of the applet.

[0098] The unit test module 303 is configured to place the second format code into the unit test file and use the test framework to test the unit test file to obtain the test result.

[0099] Since the scripting language corresponding to the second format code has a test framework for the code dimension, after converting the code corresponding to the scripting language of the applet into the second format code, it can be directly placed into the prepared unit test file and the unit test is performed using the test framework. The first format code of the applet is adjusted according to the test result to improve the code quality, save the test cost, and improve the security factor and agility during the development process of the applet.

[0100] Alternatively, according to an embodiment of the present invention, the unit test module 303 can also be configured to: write script commands in the unit test file, and when using the test framework to test the unit test file, the unit test file listens for and obtains the second format code according to the script commands.

[0101] By writing script commands, the tester only needs to write the unit test file according to the test process. The unit test file listens for and obtains the second format code converted from the scripting language code of the applet, and then uses the unit test component to perform the unit test. Through the above settings, the tester does not need to pay attention to the code conversion process, further enhancing the agility during the development process.

[0102] According to the technical solution of the embodiment of the present invention, by obtaining the first format code of the applet, parsing and processing to obtain the syntax structure corresponding to the first format code; converting the strings in the syntax structure into the second format code; placing the second format code into the unit test file, and using the test framework to test the unit test file to obtain the test result, the technical problems in the existing method, such as the inability to perform unit tests on the code corresponding to the applet scripting language, resulting in poor code quality, low security coefficient of the applet, low development agility, and high test cost, are overcome. Furthermore, the technical effects of improving the code quality, enhancing the security coefficient of the applet and the agility in the development process, and saving the test cost are achieved.

[0103] Figure 4 Fig. 400 shows an exemplary system architecture to which the unit test method of the applet or the unit test device of the applet according to the embodiment of the present invention can be applied.

[0104] As Figure 4 shown, the system architecture 400 may include terminal devices 401, 402, 403, a network 404, and a server 405 (this architecture is only an example, and the components included in the specific architecture can be adjusted according to the specific situation of the application). The network 404 is used to provide a medium for communication links between the terminal devices 401, 402, 403 and the server 405. The network 404 may include various connection types, such as wired, wireless communication links, or fiber optic cables, etc.

[0105] Users can use the terminal devices 401, 402, 403 to interact with the server 405 through the network 404 to receive or send messages, etc. Various communication client applications may be installed on the terminal devices 401, 402, 403, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only examples).

[0106] The terminal devices 401, 402, 403 may be various electronic devices with a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, and desktop computers, etc.

[0107] The server 405 may be a server providing various services, such as a background management server that supports the shopping websites browsed by users using the terminal devices 401, 402, 403 (only an example). The background management server may analyze and process data such as the first format code received, and feedback the processing results (such as syntax structure, target nodes, test results - only examples) to the terminal devices.

[0108] It should be noted that the unit test method for the applet provided by the embodiments of the present invention is generally executed by the server 405. Correspondingly, the unit test device for the applet is generally set in the server 405.

[0109] It should be understood that Figure 4 the number of terminal devices, networks, and servers in

[0110] Next, refer to Figure 5 which shows a schematic structural diagram of a computer system 500 of a terminal device suitable for implementing the embodiments of the present invention. Figure 5 The terminal device shown is only an example and should not impose any limitations on the functions and usage scope of the embodiments of the present invention.

[0111] As Figure 5 shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 502 or the program loaded from the storage section 508 into the random access memory (RAM) 503. In the RAM 503, various programs and data required 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. The input / output (I / O) interface 505 is also connected to the bus 504.

[0112] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, etc.; an output section 507 including, for example, a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN card, a modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 510 as needed so that a computer program read from it can be installed into the storage section 508 as needed.

[0113] In particular, according to the embodiments disclosed in the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed in the present invention include a computer program product that includes a computer program carried on a computer-readable medium, and the computer program includes program code for performing the methods shown in the flowcharts. In such an embodiment, the computer program can be downloaded and installed from the network through the communication section 509 and / or installed from the removable medium 511. When the computer program is executed by the central processing unit (CPU) 501, the above functions defined in the system of the present invention are performed.

[0114] 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. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of the computer-readable storage medium can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, 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 disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, the computer-readable storage medium can be any tangible medium that contains or stores a program, and the program can be used by or in combination with an instruction execution system, apparatus, or device. In the present invention, the computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, which carries the computer-readable program code. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium can also be any computer-readable medium other than the computer-readable storage medium, and the computer-readable medium can send, propagate, or transmit a program for use by or in combination with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted by any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0115] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations 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 diagram may represent a module, a segment of a program, or a portion of code that contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions denoted in the blocks may occur in a different order than that denoted in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram or flowchart, as well as combinations of blocks in the block diagram or flowchart, can be implemented by a dedicated hardware-based system that performs the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.

[0116] The modules described in the embodiments of the present invention can be implemented in software or in hardware. The described modules can also be provided in a processor. For example, it can be described as: a processor includes a parsing and processing module, a code conversion module, and a unit testing module. Among them, the names of these modules do not constitute a limitation to the module itself in some cases. For example, the parsing and processing module can also be described as "a module for obtaining the first format code of a mini-program and obtaining the syntax structure corresponding to the first format code through parsing and processing".

[0117] As another aspect, the present invention also provides a computer-readable medium, which can be included in the device described in the above embodiments; or can exist separately and not be assembled into the device. The above computer-readable medium carries one or more programs. When the one or more programs are executed by a device, the device includes: obtaining the first format code of a mini-program, obtaining the syntax structure corresponding to the first format code through parsing and processing; converting the strings in the syntax structure into the second format code; placing the second format code into a unit test file, and using a test framework to test the unit test file to obtain a test result.

[0118] According to the technical solution of the embodiment of the present invention, by obtaining the first format code of the applet, parsing and processing to obtain the syntax structure corresponding to the first format code; converting the strings in the syntax structure into the second format code; placing the second format code into the unit test file, and using the test framework to test the unit test file to obtain the test result, the technical problems of poor code quality, low security coefficient of the applet, low development agility, and high test cost in the existing methods due to the inability to perform unit tests on the code corresponding to the applet scripting language are overcome. Furthermore, the technical effects of improving the code quality, increasing the security coefficient of the applet and the agility in the development process, and saving the test cost are achieved.

[0119] The above specific implementation manners do not constitute a limitation on the protection scope of the present invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.

Claims

1. A unit testing method for a mini-program, characterized in that, including: Obtain the first - format code of the mini - program, and obtain the syntax structure corresponding to the first - format code through parsing and processing; Convert the strings within the syntax structure into the second - format code; The scripting language corresponding to the second - format code has a test framework for the code dimension; Place the second - format code into a unit - test file, and use the test framework to test the unit - test file to obtain a test result; The step of converting the strings within the syntax structure into the second - format code includes: Determine the target level corresponding to different grammars 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; Traverse the target level of the syntax structure to determine the target nodes; Use the mapping table between the scripting language corresponding to the first - format code and the scripting language corresponding to the second - format code to convert the strings within the target nodes into the second - format code, where the target nodes indicate different grammars between the scripting language corresponding to the first - format code and the scripting language corresponding to the second - format code.

2. The unit testing method for a mini-program according to claim 1, characterized in that, For non - target nodes in the syntax structure, it further includes: Use the syntax parser of the scripting language corresponding to the second - format code to convert the strings within the non - target nodes into the second - format code.

3. The unit testing method for a mini-program according to claim 1, characterized in that, It also includes: Write a script command in the unit - test file. When using the test framework to test the unit - test file, the unit - test file listens for and obtains the second - format code according to the script command.

4. A unit testing device for a mini-program, characterized in that, including: A parsing and processing module, configured to obtain the first - format code of the mini - program and obtain the syntax structure corresponding to the first - format code through parsing and processing; A code - conversion module, configured to convert the strings within the syntax structure into the second - format code; The scripting language corresponding to the second - format code has a test framework for the code dimension; A unit - test module, configured to place the second - format code into a unit - test file and use the test framework to test the unit - test file to obtain a test result; The code - conversion module is further configured to: Determine the target level corresponding to different grammars 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; Traverse the target level of the syntax structure to determine the target nodes; Use the mapping table between the scripting language corresponding to the first - format code and the scripting language corresponding to the second - format code to convert the strings within the target nodes into the second - format code, where the target nodes indicate different grammars between the scripting language corresponding to the first - format code and the scripting language corresponding to the second - format code.

5. The unit testing device for a mini-program according to claim 4, characterized in that, The code - conversion module is further configured to: For non - target nodes in the syntax structure, use the syntax parser of the scripting language corresponding to the second - format code to convert the strings within the non - target nodes into the second - format code.

6. An electronic device, characterized in that, including: One or more processors; A storage device, configured to store one or more programs, When the one or more programs are executed by the one or more processors such that the one or more processors implement the method according to any one of claims 1-3.

7. A computer-readable medium, on which a computer program is stored, characterized in that, When the program is executed by a processor, it implements the method according to any one of claims 1-3.

Citation Information

Patent Citations

  • Test method, device and system

    CN108345531A

  • Conversion method and system for codes between different platforms

    CN110109681A