CN114528218A - Test program generation method, test program generation device, storage medium, and electronic device - Google Patents

Test program generation method, test program generation device, storage medium, and electronic device Download PDF

Info

Publication number
CN114528218A
CN114528218A CN202210163875.8A CN202210163875A CN114528218A CN 114528218 A CN114528218 A CN 114528218A CN 202210163875 A CN202210163875 A CN 202210163875A CN 114528218 A CN114528218 A CN 114528218A
Authority
CN
China
Prior art keywords
test
syntax tree
character string
abstract syntax
tree
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
CN202210163875.8A
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.)
Industrial and Commercial Bank of China Ltd ICBC
Original Assignee
Industrial and Commercial Bank of China Ltd ICBC
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 Industrial and Commercial Bank of China Ltd ICBC filed Critical Industrial and Commercial Bank of China Ltd ICBC
Priority to CN202210163875.8A priority Critical patent/CN114528218A/en
Publication of CN114528218A publication Critical patent/CN114528218A/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/3684Test management for test design, e.g. generating new test cases
    • 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
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/253Grammatical analysis; Style critique
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/279Recognition of textual entities
    • G06F40/289Phrasal analysis, e.g. finite state techniques or chunking

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Quality & Reliability (AREA)
  • Computer Hardware Design (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Machine Translation (AREA)

Abstract

The invention discloses a test program generation method and device, a storage medium and electronic equipment. Wherein, the method comprises the following steps: acquiring test execution action information uploaded by a client; performing language analysis on the natural description sentences in the test execution action information to obtain a character string set; carrying out syntax analysis on the character string set to obtain an abstract syntax tree; traversing the abstract syntax tree, and respectively executing corresponding test actions according to the tree node types of the abstract syntax tree in the traversing process to obtain test results; and if the test result meets the preset test requirement, generating a target executive program according to the abstract syntax tree. The invention solves the technical problems of low test efficiency, high test cost and complex operation process of the system test method in the prior art.

Description

Test program generation method, test program generation device, storage medium, and electronic device
Technical Field
The invention relates to the technical field of financial science and technology, in particular to the technical field of system testing, and specifically relates to a method and a device for generating a test program, a storage medium and electronic equipment.
Background
The system of the current B/S architecture is generally tested in the following manner during the functional test stage: one is a manual testing mode, a tester manually executes a corresponding service function according to the description of the requirement, and verifies whether the function is correct by observing page output, checking database records and the like; the other is an automatic test mode, a UI test framework is used for writing codes for driving the page to execute, and the correctness of the function is verified through mechanisms such as assertion and the like.
The above test method has at least the following disadvantages: 1) the manual test is limited by the capability of a tester, so that the whole project period is uncontrollable, test cases cannot be reused, and the test results have inconsistent results due to subjective judgment factors; 2) the requirement on the comprehensive skills of testers is high, the service requirement needs to be understood, the capability of programming and verifying a test scene by writing a use frame is also needed, and the learning cost of new members is high; 3) the test assets are usually test codes which are highly coupled with system interfaces, and the test assets are difficult for unfamiliar testers to master and are not beneficial to sediment reuse of the test assets.
In view of the above problems, no effective solution has been proposed.
Disclosure of Invention
The embodiment of the invention provides a method, a device, a storage medium and electronic equipment for generating a test program, which are used for at least solving the technical problems of low test efficiency, high test cost and complex operation process of a system test method in the prior art.
According to an aspect of the embodiments of the present invention, there is provided a method for generating a test program, including: acquiring test execution action information uploaded by a client; performing language analysis on the natural description sentences in the test execution action information to obtain a character string set; carrying out grammar analysis on the character string set to obtain an abstract grammar tree; traversing the abstract syntax tree, and respectively executing corresponding test actions according to the tree node types of the abstract syntax tree in the traversing process to obtain test results; and if the test result meets the preset test requirement, generating a target executive program according to the abstract syntax tree.
Optionally, after obtaining the test execution action information uploaded by the client, the method further includes: detecting whether a natural description statement is adopted to describe a described entity in the test execution action information; if the described entity is not described by the natural description sentence, the auxiliary information of the described entity is acquired, and the auxiliary information is temporarily removed after the position of the auxiliary information is recorded.
Optionally, the performing language analysis on the natural description sentence in the test execution action information to obtain a character string set includes: performing text word segmentation on the natural description sentences in the test execution action information by adopting a word segmentation device based on a dictionary to obtain word segmentation results; and obtaining the character string set according to the word segmentation result.
Optionally, the performing a text word segmentation process on the natural description sentence in the test execution action information by using a word segmentation device based on a dictionary to obtain a word segmentation result includes: performing text word segmentation on the natural description sentence by adopting a built-in word segmentation dictionary of the word segmentation device to obtain a first word segmentation result; and adjusting the first segmentation result by adopting a user-defined segmentation dictionary to obtain a second segmentation result, wherein the user-defined segmentation dictionary is used for adjusting the first segmentation result to output the second segmentation result which accords with a syntax tree construction rule, and the syntax tree construction rule is used for determining how to construct the abstract syntax tree.
Optionally, after the text word segmentation processing is performed on the natural description sentence in the test execution action information by using the dictionary-based word segmenter to obtain a word segmentation result, the method further includes: detecting whether a character string subsequence incapable of being subjected to grammar analysis exists in the word segmentation result; if the character string subsequence exists, performing subsequent processing on an effective sequence in the character string subsequence, discarding an invalid sequence in the character string subsequence, and adding auxiliary information corresponding to the invalid sequence to a character string set corresponding to the invalid sequence, wherein the subsequent processing comprises: merging or conversion processes.
Optionally, parsing the character string set to obtain an abstract syntax tree includes: and a grammar parser is adopted to parse the character string set to obtain the abstract grammar tree.
Optionally, in the traversal process, corresponding test actions are respectively executed according to the tree node types of the abstract syntax tree, so as to obtain test results, where the test actions include: reading the context information of the execution environment in the traversal process, wherein the context information of the execution environment comprises: auxiliary information required for executing the test action; determining the traversed tree node type of the abstract syntax tree; executing corresponding test actions according to the tree node types respectively to obtain test results, wherein each tree node type corresponds to one test action, and the test actions comprise: mouse actions, keyboard actions, script actions, check actions.
Optionally, generating the target executive program according to the abstract syntax tree includes: and converting the abstract syntax tree into a corresponding test code, and establishing a mapping relation between the natural description statement and the test code to obtain the target executive program.
According to another aspect of the embodiments of the present invention, there is also provided a test program generating apparatus, including: the first acquisition unit is used for acquiring test execution action information uploaded by the client; the first analysis unit is used for carrying out language analysis on the natural description sentences in the test execution action information to obtain a character string set; the second parsing unit is used for parsing the grammar of the character string set to obtain an abstract grammar tree; the second acquisition unit is used for traversing the abstract syntax tree and respectively executing corresponding test actions according to the tree node types of the abstract syntax tree in the traversing process to obtain test results; and the generating unit is used for generating a target executive program according to the abstract syntax tree if the test result meets the preset test requirement.
According to another aspect of the embodiments of the present invention, there is also provided a non-volatile storage medium, in which a plurality of instructions are stored, and the instructions are adapted to be loaded by a processor and to execute any one of the above test program generation methods.
According to another aspect of the embodiments of the present invention, there is also provided an electronic device, including a memory and a processor, where the memory stores a computer program, and the processor is configured to execute the computer program to perform any one of the above test program generation methods.
In the embodiment of the invention, a test program generation mode is adopted, and test execution action information uploaded by a client is acquired; performing language analysis on the natural description sentences in the test execution action information to obtain a character string set; carrying out grammar analysis on the character string set to obtain an abstract grammar tree; traversing the abstract syntax tree, and respectively executing corresponding test actions according to the tree node types of the abstract syntax tree in the traversing process to obtain test results; if the test result meets the preset test requirement, the target executive program is generated according to the abstract syntax tree, and the purpose of automatically generating the test program according to the natural description statement is achieved, so that the technical effects of improving the test program generation efficiency and the system test efficiency, simplifying the test process and reducing the test cost are achieved, and the technical problems of low test efficiency, high test cost and complex operation process of the system test method in the prior art are solved.
Drawings
The accompanying drawings, which are included to provide a further understanding of the invention and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the invention and together with the description serve to explain the invention without limiting the invention. In the drawings:
FIG. 1 is a flow chart of a method of generating a test program according to an embodiment of the invention;
FIG. 2 is a flow chart of an alternative test program generation method according to an embodiment of the present invention;
FIG. 3 is a flow chart of an alternative test program generation method according to an embodiment of the present invention;
FIG. 4 is a flow chart of an alternative test program generation method according to an embodiment of the present invention;
FIG. 5 is a flow chart of another alternative test program generation method according to an embodiment of the invention
FIG. 6 is a flow chart of another alternative test program generation method according to an embodiment of the invention
Fig. 7 is a schematic structural diagram of a test program generation apparatus according to an embodiment of the present invention;
fig. 8 is a schematic structural diagram of an electronic device for implementing the generation method of the test program according to an embodiment of the present invention.
Detailed Description
In order to make the technical solutions of the present invention better understood, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be noted that the terms "first," "second," and the like in the description and claims of the present invention and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the invention described herein are capable of operation in sequences other than those illustrated or described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
First, in order to facilitate understanding of the embodiments of the present invention, some terms or nouns referred to in the present invention will be explained as follows:
token stream: when an input text is analyzed, one or a plurality of continuous characters in an original character stream are combined according to a certain lexical rule to generate a combined character set (namely character strings), and extra category attributes are added to the character strings, wherein the continuous character string set is a Token stream.
Example 1
In accordance with an embodiment of the present invention, there is provided a method embodiment of test program generation, it being noted that the steps illustrated in the flowchart of the figure may be performed in a computer system such as a set of computer-executable instructions and that, although a logical order is illustrated in the flowchart, in some cases the steps illustrated or described may be performed in an order different than here.
Fig. 1 is a flowchart of a method for generating a test program according to an embodiment of the present invention, and as shown in fig. 1, the method includes the following steps:
step S102, obtaining test execution action information uploaded by a client;
step S104, carrying out language analysis on the natural description sentences in the test execution action information to obtain a character string set;
step S106, carrying out grammar analysis on the character string set to obtain an abstract grammar tree;
step S108, traversing the abstract syntax tree, and respectively executing corresponding test actions according to the tree node types of the abstract syntax tree in the traversing process to obtain test results;
step S110, if the test result meets a predetermined test requirement, generating a target execution program according to the abstract syntax tree.
Optionally, the language parsing may be, but not limited to, performing chinese word segmentation processing and part-of-speech tagging processing on the natural description sentences in the test execution action information to obtain a preliminarily parsed character string set, where the character string set may be a Token stream.
Optionally, a syntax parser is used to parse the character string set (e.g., Token stream) to obtain an abstract syntax tree AST, where the syntax parser may be, but is not limited to, an LL syntax parser, an LR syntax parser, an LALR syntax parser, and the like.
Alternatively, the test actions may be, but are not limited to, mouse actions, keyboard actions, script actions, check actions, and the like.
Optionally, the target execution program is a source code of an execution code corresponding to the test action.
In the embodiment of the invention, a test program generation mode is adopted, and test execution action information uploaded by a client is acquired; performing language analysis on the natural description sentences in the test execution action information to obtain a character string set; carrying out grammar analysis on the character string set to obtain an abstract grammar tree; traversing the abstract syntax tree, and respectively executing corresponding test actions according to the tree node types of the abstract syntax tree in the traversing process to obtain test results; if the test result meets the preset test requirement, the target executive program is generated according to the abstract syntax tree, and the purpose of automatically generating the test program according to the natural description statement is achieved, so that the technical effects of improving the test program generation efficiency and the system test efficiency, simplifying the test process and reducing the test cost are achieved, and the technical problems of low test efficiency, high test cost and complex operation process of the system test method in the prior art are solved.
As an alternative embodiment, fig. 2 is a flowchart of an alternative test program generation method according to an embodiment of the present invention, and as shown in fig. 2, the method includes the following steps:
step S1, the user logs in the front page of the language analysis module and inputs the test execution action information which the system is expected to execute in the operation interface;
step S2, the language analysis module receives the natural description sentence in the test execution action information input by the user, calls the natural language analysis submodule arranged in the module, and carries out Chinese word segmentation processing and part-of-speech tagging processing on the natural description sentence to obtain a primarily analyzed Token stream;
step S3, the Token stream processing submodule of the language parsing module preprocesses the Token stream generated in step S3 to form a Token stream which can be identified by the grammar parsing submodule;
step S4, the grammar parsing submodule of the action execution module receives the Token stream, and parses the Token stream into an abstract grammar tree AST by using an LL (#) grammar parser generated according to the grammar file;
step S5, the AST interpretation execution sub-module traverses the abstract syntax tree AST generated in the step S4, and executes corresponding actions according to tree node types in the process of traversing the tree structure;
step S6, the user judges whether the expectation is reached according to the execution result, if so, the system generates and saves the source code (i.e. target executive program) of the execution code equivalent to the step S5 according to the abstract syntax tree AST and the relevant information;
in step S7, if the user requirement is not satisfied, the process returns to step S1 to be executed again.
It should be noted that, in the embodiment of the present invention, the input text is analyzed and processed, and finally converted into a specific executable UI test program and executed on the remote client, so that the user can observe the execution action of the program and the page output result in real time to determine whether the program has reached the expected target of the statement description; in addition, by using a client/server architecture mode and a real-time compiling and running technology, a user can describe a test behavior and develop a test case compiling work by using a natural language only by knowing business field knowledge and basic program language concepts, the compiling difficulty of a functional test program is effectively reduced, the whole period of a test stage is shortened, a test description statement compiled by the user naturally has a self-description capacity, and the time for a subsequent tester to be familiar with inventory test assets is shortened.
In an optional embodiment, after obtaining the test execution action information uploaded by the client, the method further includes:
step S202, detecting whether a natural description statement is adopted to describe the described entity in the test execution action information;
step S204, if it is detected that the described entity is not described by the natural description sentence, acquiring auxiliary information of the described entity, and temporarily removing the auxiliary information after recording the location of the auxiliary information.
It should be noted that the embodiment of the present invention may use a description manner similar to natural language to describe the test action, such as the following statements may describe the behavior that the user wishes to perform: "open http:// example. com"; "enter abc in text box"; "select the first item in xxx pulldown box"; "click query button", etc
Optionally, the auxiliary information may be, but is not limited to, an external data source, measured system parameter information, and the like.
It should be noted that, for an entity that is difficult to be clearly described directly by a natural description sentence, a description of auxiliary information of the described entity is obtained, for example, in "click button [ id ] okBtn ]", [ ] the text in the text is the auxiliary information, and the text is used for understanding the characteristics of the current node in the execution stage of the syntax tree, so as to record the position of the auxiliary information, and temporarily remove the auxiliary information after recording the position of the auxiliary information.
In an optional embodiment, the performing language parsing on the natural description statement in the test execution action information to obtain a character string set includes:
step S302, a word segmentation device based on a dictionary is adopted to carry out text word segmentation processing on the natural description sentences in the test execution action information to obtain word segmentation results;
step S304, obtaining the character string set according to the word segmentation result.
Optionally, the word segmentation unit may, but is not limited to, perform text word segmentation on the natural description sentence in the test execution action information by using any method: forward longest match, reverse longest match, and bidirectional longest match. For example, a two-way longest matching method is used to perform text word segmentation on the natural description sentence in the test execution action information.
Optionally, the method includes performing text segmentation on the natural description sentence through a built-in segmentation dictionary of the segmenter to obtain a first segmentation result, adjusting the first segmentation result by using a user-defined segmentation dictionary to obtain a second segmentation result, and obtaining the character string set (i.e., Token stream) based on the second acne result.
In an optional embodiment, the performing a text segmentation process on the natural description sentence in the test execution action information by using a dictionary-based segmenter to obtain a segmentation result includes:
step S402, carrying out text word segmentation on the natural description sentence by adopting the built-in word segmentation dictionary of the word segmenter to obtain a first word segmentation result;
step S404, adjusting the first segmentation result by using a customized segmentation dictionary to obtain a second segmentation result, where the customized segmentation dictionary is used to adjust the first segmentation result to output the second segmentation result meeting a syntax tree construction rule, and the syntax tree construction rule is used to determine how to construct the abstract syntax tree.
Optionally, the method includes performing text segmentation on a natural description sentence through a built-in segmentation dictionary of the segmenter to obtain a first segmentation result, and then adjusting the first segmentation result by using a user-defined segmentation dictionary to obtain a second segmentation result, so that Token segmentation (i.e., the second segmentation result) meeting a subsequent syntax tree construction rule is output, for example, loading the following user-defined dictionary custom _ dit.txt: a drop-down frame n 200; a radio box n 200; for a statement: "the radio box [ label ═ read ]", the result after word segmentation (i.e. the second word segmentation result) is: < check, v, 50>, < radio box, n,200 >.
In an optional embodiment, after the text segmentation processing is performed on the natural description sentence in the test execution action information by using the dictionary-based tokenizer to obtain a segmentation result, the method further includes:
step S502, detecting whether a character string subsequence which can not be subjected to grammar analysis exists in the word segmentation result;
step S504, if the character string subsequence exists, performing subsequent processing on an effective sequence in the character string subsequence, discarding an invalid sequence in the character string subsequence, and appending auxiliary information corresponding to the invalid sequence to a character string set corresponding to the invalid sequence, where the subsequent processing includes: merging or conversion processes.
It should be noted that, for the character string set (i.e. Token stream) after word segmentation, there may still be a sequence that cannot be parsed, and at this time, whether there is a character string subsequence that cannot be parsed is detected in the word segmentation result; if the character string subsequence exists, carrying out subsequent processing on an effective sequence in the character string subsequence, discarding an invalid sequence in the character string subsequence, processing the character string subsequence (namely, Token subsequence) which can be merged and converted in a mode of adding auxiliary information corresponding to the invalid sequence to a character string set corresponding to the invalid sequence, discarding a character string subsequence which cannot be analyzed, and adding extracted auxiliary information to a character string set corresponding to the character string subsequence.
As an alternative embodiment, fig. 3 is a flowchart of another alternative test program generation method according to an embodiment of the present invention, and as shown in fig. 3, the method includes: acquiring text information input by a user, and preprocessing the text information to obtain processed text information; the method comprises the steps of carrying out text word segmentation on a natural description sentence by adopting a built-in word segmentation dictionary of a word segmentation device and a self-defined word segmentation dictionary to obtain a word segmentation result (namely word segmentation data), and carrying out character string Token merging processing, character string Token position conversion processing and invalid character string Token deletion on the word segmentation result in sequence to obtain a processed Token stream, namely a character string set.
In an optional embodiment, parsing the character string set to obtain an abstract syntax tree includes:
step S602, a syntax parser is used to parse the character string set to obtain the abstract syntax tree.
Alternatively, the parser may be, but not limited to, LL parser, LR parser, and LALR parser. For example, after receiving the Token stream, the LL parser is used to perform a parsing process on the Token stream to obtain an abstract syntax tree AST.
Optionally, the syntax parser generation framework of the Antlr4 is adopted to read a corresponding code generated by the syntax parser based on a predefined BNF-format action syntax rule file, and syntax rules in the following format may be set for the syntax parser:
Figure BDA0003515232550000091
it should be noted that, because the user input content is a natural language, and the lexical rule may have a situation that all words cannot be covered, the embodiment of the present invention extends the default TokenStream type of Antlr, and can map any participle Token stream generated by the language parsing module to the Token type of the Antlr lexical analyzer, thereby improving the flexibility of language support.
As an alternative embodiment, fig. 4 is a flowchart of another alternative test program generating method according to an embodiment of the present invention, and as shown in fig. 4, in the traversal process, corresponding test actions are respectively executed according to tree node types of the abstract syntax tree, so as to obtain test results, where the method includes:
step S702, reading the execution environment context information in the traversal process, wherein the execution environment context information includes: auxiliary information required for executing the test action;
step S704, determining the tree node type of the traversed abstract syntax tree;
step S706, respectively executing corresponding test actions according to the tree node types to obtain test results, where each tree node type corresponds to one test action.
Optionally, after the test action is finished, updating the context information of the execution environment; the auxiliary information may be, but not limited to, an external data source, measured system parameter information, and the like; the test actions include: mouse actions, keyboard actions, script actions, check actions.
As an alternative embodiment, fig. 5 is a flowchart of another alternative test program generation method according to an embodiment of the present invention, and as shown in fig. 5, the method includes: firstly, reading context information of an execution environment in a traversal process, wherein the information is auxiliary information (such as an external data source, parameter information of a system to be tested and the like) required by executing an action; different types of abstract syntax trees AST correspond to different resolvers, an entrance parser is assigned to corresponding sub-parsers to parse and execute the AST, different testing actions are executed through the different parsers, a mouse action parser is adopted to parse to obtain a mouse action, a keyboard action parser is adopted to parse to obtain a keyboard action, a script action parser is adopted to parse to obtain a script action, a checking action parser is adopted to parse to obtain a checking action, and the like; during the parsing execution, the context of the environment may change, and the context information needs to be updated after the execution is finished.
In an alternative embodiment, generating the target executive according to the abstract syntax tree includes:
step S802, converting the abstract syntax tree into a corresponding test code, and establishing a mapping relationship between the natural description statement and the test code to obtain the target executive program.
Optionally, as shown in fig. 6, if it is checked by the user that the result of the interpretation and execution of the abstract syntax tree AST is expected, the abstract syntax tree AST is converted into an equivalent test code by setting a code generation module in combination with the context information of the execution environment, and a mapping relationship between the natural description statement and the execution code is established.
The embodiment of the invention at least has the following advantages: the system establishes an end-to-end mapping relation from a source statement to an execution code by appointing an API (application programming interface) and a data format of each execution link, can realize the non-inductive upgrade optimization of each link of the system on a user side, shields the coding details of a test framework at the bottom layer of the user, and effectively avoids the problem of test code failure possibly caused by system upgrade; the development efficiency is high, a user only needs to provide descriptive statements, and the result can be obtained through the real-time compiling execution capacity provided by the system, so that the verification period is greatly shortened compared with the traditional compiling-deploying-running mode; the case has self-description ability, the case described by the natural language can be rapidly transferred among different testers, the learning cost is low, and the efficiency of the functional test is effectively improved.
It should be noted that, for simplicity of description, the above-mentioned method embodiments are described as a series of acts or combination of acts, but those skilled in the art will recognize that the present invention is not limited by the order of acts, as some steps may occur in other orders or concurrently in accordance with the invention. Further, those skilled in the art should also appreciate that the embodiments described in the specification are preferred embodiments and that the acts and modules referred to are not necessarily required by the invention.
Through the above description of the embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but the former is a better implementation mode in many cases. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present invention.
Example 3
In this embodiment, a device for generating a test program is further provided, where the device is used to implement the foregoing embodiments and preferred embodiments, and details are not repeated for what has been described. As used hereinafter, the terms "unit" and "means" may be a combination of software and/or hardware that implements the intended function. Although the means described in the embodiments below are preferably implemented in software, an implementation in hardware, or a combination of software and hardware is also possible and contemplated.
According to an embodiment of the present invention, an embodiment of an apparatus for implementing the method for generating the test program is further provided, fig. 7 is a schematic structural diagram of an apparatus for generating a test program according to an embodiment of the present invention, and as shown in fig. 7, the apparatus for generating a test program includes: a first obtaining unit 40, a first analyzing unit 42, a second analyzing unit 44, a second obtaining unit 46, and a generating unit 48, wherein:
the first obtaining unit 40 is configured to obtain test execution action information uploaded by the client;
the first parsing unit 42 is configured to perform language parsing on the natural description sentences in the test execution action information to obtain a character string set;
the second parsing unit 44 is configured to parse the character string set to obtain an abstract syntax tree;
the second obtaining unit 46 is configured to traverse the abstract syntax tree, and execute corresponding test actions according to tree node types of the abstract syntax tree in the traversal process, so as to obtain a test result;
the generating unit 48 is configured to generate a target executive program according to the abstract syntax tree if the test result satisfies a predetermined test requirement.
It should be noted that the above units can be implemented by software or hardware, for example, for the latter, the following manner can be implemented: the units may be located in the same processor; alternatively, the units may be located in different processors in any combination.
It should be noted that the first acquiring unit 40, the first analyzing unit 42, the second analyzing unit 44, the second acquiring unit 46, and the generating unit 48 correspond to steps S102 to S110 in embodiment 1, and the above units are the same as the corresponding steps in the implementation example and the application scenario, but are not limited to the disclosure in embodiment 1. It should be noted that the above units may be operated in a computer terminal as part of the apparatus.
It should be noted that, reference may be made to the relevant description in embodiment 1 for alternative or preferred embodiments of this embodiment, and details are not described here again.
The above-mentioned generating device of the test program may further include a processor and a memory, the above-mentioned first obtaining unit 40, the first analyzing unit 42, the second analyzing unit 44, the second obtaining unit 46, the generating unit 48, etc. are all stored in the memory as program units, and the processor executes the above-mentioned program units stored in the memory to implement the corresponding functions.
The processor comprises a kernel, and the kernel calls a corresponding program unit from the memory, wherein one or more than one kernel can be arranged. The memory may include volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM), including at least one memory chip.
According to an embodiment of the present application, there is also provided an embodiment of a non-volatile storage medium. Optionally, in this embodiment, the nonvolatile storage medium includes a stored program, and the device where the nonvolatile storage medium is located is controlled to execute the method for generating any test program when the program runs.
Optionally, in this embodiment, the nonvolatile storage medium may be located in any one of computer terminals in a computer terminal group in a computer network, or in any one of mobile terminals in a mobile terminal group, and the nonvolatile storage medium includes a stored program.
Optionally, the device in which the non-volatile storage medium is controlled to execute the following functions when the program runs: acquiring test execution action information uploaded by a client; performing language analysis on the natural description sentences in the test execution action information to obtain a character string set; carrying out grammar analysis on the character string set to obtain an abstract grammar tree; traversing the abstract syntax tree, and respectively executing corresponding test actions according to the tree node types of the abstract syntax tree in the traversing process to obtain test results; and if the test result meets the preset test requirement, generating a target executive program according to the abstract syntax tree.
Optionally, the device in which the non-volatile storage medium is controlled to execute the following functions when the program runs: detecting whether a natural description statement is adopted to describe a described entity in the test execution action information; if the described entity is not described by the natural description sentence, acquiring auxiliary information of the described entity, and temporarily removing the auxiliary information after recording the position of the auxiliary information.
Optionally, the device in which the non-volatile storage medium is controlled to execute the following functions when the program runs: performing text word segmentation on the natural description sentences in the test execution action information by adopting a word segmentation device based on a dictionary to obtain word segmentation results; and obtaining the character string set according to the word segmentation result.
Optionally, the device in which the non-volatile storage medium is controlled to execute the following functions when the program runs: performing text word segmentation on the natural description sentence by adopting a built-in word segmentation dictionary of the word segmentation device to obtain a first word segmentation result; and adjusting the first segmentation result by adopting a user-defined segmentation dictionary to obtain a second segmentation result, wherein the user-defined segmentation dictionary is used for adjusting the first segmentation result to output the second segmentation result which accords with a syntax tree construction rule, and the syntax tree construction rule is used for determining how to construct the abstract syntax tree.
Optionally, the device in which the nonvolatile storage medium is controlled to execute the following functions during program execution: detecting whether a character string subsequence incapable of being subjected to grammar analysis exists in the word segmentation result; if the character string subsequence exists, performing subsequent processing on an effective sequence in the character string subsequence, discarding an invalid sequence in the character string subsequence, and adding auxiliary information corresponding to the invalid sequence to a character string set corresponding to the invalid sequence, wherein the subsequent processing comprises: merging or conversion processes.
Optionally, the device in which the non-volatile storage medium is controlled to execute the following functions when the program runs: and a grammar parser is adopted to parse the character string set to obtain the abstract grammar tree.
Optionally, the device in which the nonvolatile storage medium is controlled to execute the following functions during program execution: reading the context information of the execution environment in the traversal process, wherein the context information of the execution environment comprises: auxiliary information required for executing the test action; determining the traversed tree node type of the abstract syntax tree; executing corresponding test actions according to the tree node types respectively to obtain test results, wherein each tree node type corresponds to one test action, and the test actions comprise: mouse actions, keyboard actions, script actions, check actions.
Optionally, the device in which the non-volatile storage medium is controlled to execute the following functions when the program runs: and converting the abstract syntax tree into corresponding test codes, and establishing a mapping relation between the natural description statement and the test codes to obtain the target executive program.
According to an embodiment of the present application, there is also provided an embodiment of a processor. Optionally, in this embodiment, the processor is configured to execute a program, where the program executes the method for generating any test program.
According to an embodiment of the application, there is further provided an embodiment of a computer program product, which, when executed on a data processing device, is adapted to execute a program initialized with the steps of the generation method of the test program of any of the above.
Optionally, the computer program product is adapted to perform a program for initializing the following method steps when executed on a data processing device: acquiring test execution action information uploaded by a client; performing language analysis on the natural description sentences in the test execution action information to obtain a character string set; carrying out grammar analysis on the character string set to obtain an abstract grammar tree; traversing the abstract syntax tree, and respectively executing corresponding test actions according to the tree node types of the abstract syntax tree in the traversing process to obtain test results; and if the test result meets the preset test requirement, generating a target executive program according to the abstract syntax tree.
According to an embodiment of the present application, there is also provided an embodiment of an electronic device, as shown in fig. 8, the electronic device 10 includes a processor, a memory, and a program stored in the memory and executable on the processor, and the processor executes the program to implement the following steps: acquiring test execution action information uploaded by a client; performing language analysis on the natural description sentences in the test execution action information to obtain a character string set; carrying out grammar analysis on the character string set to obtain an abstract grammar tree; traversing the abstract syntax tree, and respectively executing corresponding test actions according to the tree node types of the abstract syntax tree in the traversing process to obtain test results; and if the test result meets the preset test requirement, generating a target executive program according to the abstract syntax tree.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
In the above embodiments of the present invention, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
In the embodiments provided in the present application, it should be understood that the disclosed technology can be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units may be a logical division, and in actual implementation, there may be another division, for example, multiple units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, units or modules, and may be in an electrical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable non-volatile storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a non-volatile storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to perform all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned nonvolatile storage medium includes: a U-disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic or optical disk, and other various media capable of storing program codes.
The foregoing is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, various modifications and decorations can be made without departing from the principle of the present invention, and these modifications and decorations should also be regarded as the protection scope of the present invention.

Claims (11)

1. A method for generating a test program, comprising:
acquiring test execution action information uploaded by a client;
performing language analysis on the natural description sentences in the test execution action information to obtain a character string set;
carrying out syntax analysis on the character string set to obtain an abstract syntax tree;
traversing the abstract syntax tree, and respectively executing corresponding test actions according to the tree node types of the abstract syntax tree in the traversing process to obtain test results;
and if the test result meets the preset test requirement, generating a target executive program according to the abstract syntax tree.
2. The method of claim 1, wherein after obtaining the test execution action information uploaded by the client, the method further comprises:
detecting whether a natural description statement is adopted to describe the described entity in the test execution action information;
and if the described entity is not described by the natural description sentence, acquiring auxiliary information of the described entity, and temporarily removing the auxiliary information after recording the position of the auxiliary information.
3. The method of claim 1, wherein the performing language parsing on the natural description sentence in the test execution action information to obtain a string set comprises:
performing text word segmentation on the natural description sentences in the test execution action information by adopting a word segmentation device based on a dictionary to obtain word segmentation results;
and obtaining the character string set according to the word segmentation result.
4. The method according to claim 3, wherein the performing, by using a dictionary-based tokenizer, text tokenization processing on the natural description sentence in the test execution action information to obtain a tokenization result comprises:
adopting a built-in word segmentation dictionary of the word segmentation device to perform text word segmentation on the natural description sentence to obtain a first word segmentation result;
and adjusting the first segmentation result by adopting a user-defined segmentation dictionary to obtain a second segmentation result, wherein the user-defined segmentation dictionary is used for adjusting the first segmentation result so as to output the second segmentation result which accords with a syntax tree construction rule, and the syntax tree construction rule is used for determining how to construct the abstract syntax tree.
5. The method of claim 3, wherein after the text segmentation processing is performed on the natural description sentences in the test execution action information by using a dictionary-based segmenter to obtain segmentation results, the method further comprises:
detecting whether a character string subsequence incapable of being subjected to grammar analysis exists in the word segmentation result;
if the character string subsequence exists, performing subsequent processing on an effective sequence in the character string subsequence, discarding an invalid sequence in the character string subsequence, and appending auxiliary information corresponding to the invalid sequence to a character string set corresponding to the invalid sequence, wherein the subsequent processing comprises: merging or conversion processes.
6. The method of claim 3, wherein parsing the set of strings to obtain an abstract syntax tree comprises:
and adopting a grammar parser to perform grammar parsing on the character string set to obtain the abstract grammar tree.
7. The method of claim 1, wherein performing corresponding test actions according to the tree node types of the abstract syntax tree during the traversal process to obtain test results comprises:
reading execution environment context information in a traversal process, wherein the execution environment context information comprises: auxiliary information required when the test action is executed;
determining a tree node type of the traversed abstract syntax tree;
executing corresponding test actions according to the tree node types respectively to obtain test results, wherein each tree node type corresponds to one test action, and the test actions comprise: mouse actions, keyboard actions, script actions, check actions.
8. The method of claim 1, wherein generating a target executive from the abstract syntax tree comprises:
and converting the abstract syntax tree into a corresponding test code, and establishing a mapping relation between the natural description statement and the test code to obtain the target executive program.
9. An apparatus for generating a test program, comprising:
the first acquisition unit is used for acquiring test execution action information uploaded by the client;
the first analysis unit is used for carrying out language analysis on the natural description sentences in the test execution action information to obtain a character string set;
the second analysis unit is used for carrying out syntactic analysis on the character string set to obtain an abstract syntactic tree;
the second acquisition unit is used for traversing the abstract syntax tree and respectively executing corresponding test actions according to the tree node types of the abstract syntax tree in the traversing process to obtain test results;
and the generating unit is used for generating a target executive program according to the abstract syntax tree if the test result meets the preset test requirement.
10. A non-volatile storage medium, characterized in that it stores a plurality of instructions adapted to be loaded by a processor and to perform the method of generating a test program according to any one of claims 1 to 8.
11. An electronic device comprising a memory and a processor, wherein the memory has stored therein a computer program, and the processor is configured to execute the computer program to perform the test program generation method of any one of claims 1 to 8.
CN202210163875.8A 2022-02-22 2022-02-22 Test program generation method, test program generation device, storage medium, and electronic device Pending CN114528218A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210163875.8A CN114528218A (en) 2022-02-22 2022-02-22 Test program generation method, test program generation device, storage medium, and electronic device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210163875.8A CN114528218A (en) 2022-02-22 2022-02-22 Test program generation method, test program generation device, storage medium, and electronic device

Publications (1)

Publication Number Publication Date
CN114528218A true CN114528218A (en) 2022-05-24

Family

ID=81625558

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210163875.8A Pending CN114528218A (en) 2022-02-22 2022-02-22 Test program generation method, test program generation device, storage medium, and electronic device

Country Status (1)

Country Link
CN (1) CN114528218A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115221061A (en) * 2022-07-22 2022-10-21 中国电信股份有限公司 Test code generation method and device, storage medium and electronic equipment

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115221061A (en) * 2022-07-22 2022-10-21 中国电信股份有限公司 Test code generation method and device, storage medium and electronic equipment
CN115221061B (en) * 2022-07-22 2024-03-22 中国电信股份有限公司 Test code generation method and device, storage medium and electronic equipment

Similar Documents

Publication Publication Date Title
US12032475B2 (en) Automating identification of test cases for library suggestion models
US11093240B2 (en) Automating identification of code snippets for library suggestion models
US11494181B2 (en) Automating generation of library suggestion engine models
US10732966B2 (en) Library model addition
CN110018955A (en) Automatic test script is generated by conversion manual test use-case
CN110688307B (en) JavaScript code detection method, device, equipment and storage medium
CN109857641A (en) The method and device of defects detection is carried out to program source file
CN101751281A (en) System and method for generating compiler
CN118245050B (en) Front end frame assembly automatic conversion method, system, electronic device and storage medium
CN114528218A (en) Test program generation method, test program generation device, storage medium, and electronic device
US9529573B2 (en) Graphical user interface generation through use of a binary file
CN110928535B (en) Derived variable deployment method, device, equipment and readable storage medium
CN116610558A (en) Code detection method, device, electronic equipment and computer readable storage medium
CN111078529A (en) Client write-in module testing method and device and electronic equipment
CN113590453B (en) Method and device for generating test case and storage medium
CN117971308A (en) Interface document generation method, device, storage medium and computer equipment
CN112965851A (en) Memory overflow processing method and device, electronic equipment and storage medium
CN116320060A (en) Message conversion method and device, electronic equipment and storage medium
CN117493161A (en) Interface testing method and device, electronic equipment and storage medium
CN117421222A (en) Interface automatic test method, device, equipment and storage medium
CN116521179A (en) Reconstruction method and device for financial item, electronic equipment and storage medium
CN118445198A (en) Empty judgment detection method and device, terminal equipment and storage medium
CN115391369A (en) Operation method, device and equipment of data engine and storage medium
CN117076297A (en) Automatic test method, device, equipment and storage medium
CN117539752A (en) Difference generation method, display method, device, equipment and storage 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