CN113448874A - Method and device for generating unit test script - Google Patents

Method and device for generating unit test script Download PDF

Info

Publication number
CN113448874A
CN113448874A CN202110843856.5A CN202110843856A CN113448874A CN 113448874 A CN113448874 A CN 113448874A CN 202110843856 A CN202110843856 A CN 202110843856A CN 113448874 A CN113448874 A CN 113448874A
Authority
CN
China
Prior art keywords
unit test
source code
target source
generating
test script
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
CN202110843856.5A
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 CN202110843856.5A priority Critical patent/CN113448874A/en
Publication of CN113448874A publication Critical patent/CN113448874A/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

Landscapes

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

Abstract

The invention provides a method and a device for generating a unit test script, which can be used in the financial field or other technical fields. The method comprises the following steps: importing a design case developed by a unit test driver, wherein the design case developed by the unit test driver is generated in advance; acquiring a target source code, and converting the target source code into an abstract syntax tree; and generating a unit test script according to the design case developed by the unit test driver and the abstract syntax tree of the target source code. The device is used for executing the method. The method and the device for generating the unit test script improve the coverage rate and effectiveness of the unit test script.

Description

Method and device for generating unit test script
Technical Field
The invention relates to the technical field of computers, in particular to a method and a device for generating a unit test script.
Background
Unit Test Drive Development (UTDD) is core practice and technology in agile Development, and the principle is that Unit Test case codes are written before functional codes are developed, so that the method has the advantages of reducing the burden of developers, realizing quick feedback and the like.
In the prior art, an algorithm and a tool of a unit test script are mainly based on analysis of a source code, the script is generated by adopting a natural language processing mode or the unit test script is generated by adopting a full simulation (Mock) mode, the readability and maintainability of the script automatically analyzed by the source code are poor, and if a program is complex, only abnormal branches can be covered, and valuable service codes cannot be covered. Therefore, how to generate the unit test script by the UTDD method becomes an important issue to be solved in the art.
Disclosure of Invention
To solve the problems in the prior art, embodiments of the present invention provide a method and an apparatus for generating a unit test script, which can at least partially solve the problems in the prior art.
In one aspect, the present invention provides a method for generating a unit test script, including:
importing a design case developed by a unit test driver, wherein the design case developed by the unit test driver is generated in advance;
acquiring a target source code, and converting the target source code into an abstract syntax tree;
and generating a unit test script according to the design case developed by the unit test driver and the abstract syntax tree of the target source code.
Furthermore, the design case developed by the unit test driver adopts a preset template to describe the service function, and comprises at least one expression statement; correspondingly, the generating a unit test script according to the design case developed by the unit test driver and the abstract syntax tree of the target source code includes:
a corresponding method name is created for each expression statement, and each expression statement is used as an annotation of the corresponding method name.
Further, the method for generating the unit test script further comprises:
and supplementing case design description for the method name corresponding to each expression statement.
Further, the converting the target source code into an abstract syntax tree includes:
and analyzing the class, the method and the member variable of the target source code to obtain an abstract syntax tree of the target source code.
Further, the member variables include external member variables; correspondingly, the generating a unit test script according to the design case developed by the unit test driver and the abstract syntax tree of the target source code includes:
and generating a simulation statement according to the external member variable, and declaring the external member variable.
Further, the method for generating the unit test script further comprises:
and generating a unit test drive development rechecking document according to the unit test script.
In another aspect, the present invention provides an apparatus for generating a unit test script, including:
the system comprises an importing module, a test module and a test module, wherein the importing module is used for importing a design case developed by a unit test driver, and the design case developed by the unit test driver is generated in advance;
the conversion module is used for acquiring a target source code and converting the target source code into an abstract syntax tree;
and the generating module is used for generating a unit test script according to the design case developed by the unit test driver and the abstract syntax tree of the target source code.
Furthermore, the design case developed by the unit test driver adopts a preset template to describe the service function, and comprises at least one expression statement; correspondingly, the generating module is specifically configured to:
a corresponding method name is created for each expression statement, and each expression statement is used as an annotation of the corresponding method name.
In another aspect, the present invention provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor executes the computer program to implement the steps of the method for generating a unit test script according to any one of the above embodiments.
In yet another aspect, the present invention provides a computer-readable storage medium, on which a computer program is stored, the computer program, when being executed by a processor, implementing the steps of the method for generating a unit test script according to any one of the above embodiments.
The method and the device for generating the unit test script provided by the embodiment of the invention can introduce a pre-generated design case developed by the unit test driver, acquire the target source code, convert the target source code into the abstract syntax tree, and generate the unit test script according to the design case developed by the unit test driver and the abstract syntax tree of the target source code, thereby covering the service function and improving the coverage rate and the effectiveness of the unit test script.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts. In the drawings:
fig. 1 is a flowchart illustrating a method for generating a unit test script according to an embodiment of the present invention.
Fig. 2 is a schematic structural diagram of a device for generating a unit test script according to an embodiment of the present invention.
Fig. 3 is a schematic structural diagram of a device for generating a unit test script according to another embodiment of the present invention.
Fig. 4 is a schematic structural diagram of a device for generating a unit test script according to yet another embodiment of the present invention.
Fig. 5 is a schematic physical structure diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the embodiments of the present invention are further described in detail below with reference to the accompanying drawings. The exemplary embodiments and descriptions of the present invention are provided to explain the present invention, but not to limit the present invention. It should be noted that the embodiments and features of the embodiments in the present application may be arbitrarily combined with each other without conflict.
In order to facilitate understanding of the technical solutions provided in the present application, the following briefly describes the research background of the technical solutions in the present application. In the prior art, a unit test script generated based on a source code can only cover an abnormal branch and cannot cover a valuable service code, so that the coverage rate is high and the effectiveness is low. The method for generating the unit test script provided by the embodiment of the invention generates the unit test script based on the UTDD design case, so that the test can cover the service code, and the coverage rate and the effectiveness of the unit test script are improved.
Fig. 1 is a flowchart illustrating a method for generating a unit test script according to an embodiment of the present invention, where as shown in fig. 1, the method for generating a unit test script according to an embodiment of the present invention includes:
s101, importing a design case developed by a unit test driver, wherein the design case developed by the unit test driver is generated in advance;
specifically, a developer combs service requirements in a program design stage in a UTDD case design mode, describes service functions to complete case design, generates and stores a UTDD design case. The computer can import the UTDD design case. When the design case of the UTDD is imported, an htll tag may be added to the annotation of the design case. The execution body of the unit test script generation method provided by the embodiment of the invention comprises but is not limited to a computer.
For example, a developer completes case design based on methods such as an equivalence class, a boundary value, a path method and the like in a program design stage, case design can be performed in a UTDD case design mode, service requirements are combed, service functions can be described through a GIVEN-WHEN-THEN expression, and a UTDD design case is generated. The generated design case of the UTDD may include an expression statement of GIVEN-WHEN-THEN, and corresponding annotations. The generated UTDD design case can be stored in the form of EXCEL, and the computer can read the EXCEL file storing the UTDD design case to realize the import of the UTDD design case.
The GIVEN-WHEN-THEN can become a formula or a template, and the GIVEN-WHEN-WHRN template is adopted to guide a developer to write a test case in a user story mode. Where GIVEN specifies a context, test preset, WHEN directs a series of operations, i.e., execution methods, and THEN specifies a series of observable results, i.e., test assertions.
For example, a computer may import a design case for UTDD via the Intellij IDEA plug-in.
S102, acquiring a target source code, and converting the target source code into an abstract syntax tree;
specifically, after the computer imports the design case of the UTDD, the computer acquires the target source code, and then converts the target source code into an abstract syntax tree of the target source code, where the abstract syntax tree includes classes, methods, and member variables. Wherein the target source code may be the source code currently being edited. In the embodiment of the present invention, the target source code is a program framework, and may include a declaration of a class, names of methods to be called by the class, declarations of member variables, and the like, and may not include specific executable code. The target source code is set according to actual needs, and the embodiment of the present invention is not limited.
S103, generating a unit test script according to the design case developed by the unit test driver and the abstract syntax tree of the target source code.
Specifically, the computer completes the preliminary construction of the unit test script based on the abstract syntax tree of the target source code, then adds the design case developed by the unit test driver to the preliminarily constructed unit test script, and generates the unit test script, wherein the generated unit test script is a standardized UTDD script.
For example, the abstract syntax tree of the target source code a includes class a, method b and method c called by class a, and member variable d, the design case of the UTDD includes expression statement X and expression statement Y, and when the computer generates a unit test script, the unit test script preliminarily constructed according to class a, method b called by class a, and method c is represented as follows:
Figure BDA0003179820170000051
the computer adds the expression statement X and the expression statement Y into the preliminarily constructed unit test script, and the obtained unit test script is as follows:
Figure BDA0003179820170000052
the method X in the unit test script corresponds to the expression statement X, and the expression statement X can be used as the annotation of the method X; the method Y in the unit test script corresponds to the expression statement Y, and the expression statement Y can be used as a comment of the method Y.
The method for generating the unit test script provided by the embodiment of the invention can introduce the design case generated in advance by the unit test driver, acquire the target source code, convert the target source code into the abstract syntax tree, and generate the unit test script according to the design case developed by the unit test driver and the abstract syntax tree of the target source code, so that the unit test script can cover the service function, and the coverage rate and the effectiveness of the unit test script are improved. Due to the fact that the coverage rate of the unit test scripts is improved, the test objects can be tested more comprehensively, and the risk that the follow-up test objects have problems is reduced.
On the basis of the above embodiments, further, the design case developed by the unit test driver adopts a preset template to describe the service function, including at least one expression statement; correspondingly, the generating a unit test script according to the design case developed by the unit test driver and the abstract syntax tree of the target source code includes:
a corresponding method name is created for each expression statement, and each expression statement is used as an annotation of the corresponding method name.
Specifically, when a developer performs case design, the developer can describe service functions through a preset template, so that the generated UTDD design case includes at least one expression statement. The preset template can adopt a GIVEN-WHEN-THEN expression template, and is set according to actual needs, and the embodiment of the invention is not limited.
When the computer generates the unit test script, a method name is created for each expression statement in the UTDD design case, and then the expression statement is used as an annotation of the corresponding method name.
For example, a method name corresponding to the expression statement may be created in a should + expression manner. The expression statement is given by given xxx where xxx then xxx, and the corresponding method is named should _ [ given _ xxx _ while _ then _ xxx ].
On the basis of the foregoing embodiments, further, the method for generating a unit test script according to an embodiment of the present invention further includes:
and supplementing case design description for the method name corresponding to each expression statement.
Specifically, the design case of the UTDD includes at least one expression statement, and each expression statement corresponds to a comment, which is a natural language explanation added by the developer for the expression statement. After the computer creates a corresponding method name for each expression statement, the computer obtains the annotation corresponding to each expression statement as the case design description of the method name corresponding to each expression statement.
On the basis of the foregoing embodiments, further, the converting the target source code into an abstract syntax tree includes:
and analyzing the class, the method and the member variable of the target source code to obtain an abstract syntax tree of the target source code.
Specifically, the computer may parse the class, the method, and the member variable of the target source code through a syntax analysis tool to obtain an abstract syntax tree of the target source code, where the abstract syntax tree includes a class name, at least one method name, and at least one member variable name.
For example, the target source code is written in the Java language, and the target source code can be analyzed by a Java Compiler (JAVACC) tool to generate an abstract syntax tree of the target source code.
On the basis of the above embodiments, further, the member variable includes an external member variable; correspondingly, the generating a unit test script according to the design case developed by the unit test driver and the abstract syntax tree of the target source code includes:
generating a simulation statement for the external member variable and declaring the external member variable.
Specifically, the member variables include external member variables, which are used to make calls to external classes or methods, whereas the test scripts of UTDD are not really making calls to external member variables. When the computer generates the unit test script, a simulation (mock) statement is generated for the external member variable, mock dependent on the outside is realized, and the external member variable is declared.
For example, the abstract syntax tree of the target source code a also includes an external member variable e, then the preliminarily constructed unit test script is represented as follows:
Figure BDA0003179820170000071
on the basis of the foregoing embodiments, further, the method for generating a unit test script according to an embodiment of the present invention further includes:
and generating a unit test drive development rechecking document according to the unit test script.
Specifically, after the computer generates the unit test script, a unit test driver development Review (Review) document may be generated according to the unit test script, that is, information such as method definitions and comments in the unit test script is summarized and stored in the UTDD Review document, so that a tester can conveniently view the information.
The UTDD Review document is an extension of the code Review, and a tester conducts Review on a UTDD script written by a developer before functional test so as to quickly confirm whether a corresponding unit test script is measurable or not and evaluate the quality of the developed unit test script.
For example, the method definitions and comments in the unit test script can be summarized into an HTML file to form a UTDD Review document for the convenience of the tester.
Fig. 2 is a schematic structural diagram of a device for generating a unit test script according to an embodiment of the present invention, and as shown in fig. 2, the device for generating a unit test script according to an embodiment of the present invention includes an importing module 201, a converting module 202, and a generating module 203, where:
the importing module 201 is configured to import a design case for unit test driver development, where the design case for unit test driver development is generated in advance; the conversion module 202 is configured to obtain a target source code and convert the target source code into an abstract syntax tree; the generating module 203 is configured to generate a unit test script according to the design case developed by the unit test driver and the abstract syntax tree of the target source code.
Specifically, a developer combs service requirements in a program design stage in a UTDD case design mode, describes service functions to complete case design, generates and stores a UTDD design case. The import module 201 can import the design case of UTDD. When the design case of the UTDD is imported, an htll tag may be added to the annotation of the design case.
After importing the design case of the UTDD, the conversion module 202 obtains the target source code and then converts the target source code into an abstract syntax tree of the target source code, where the abstract syntax tree includes classes, methods, and member variables. Wherein the target source code may be the source code currently being edited. In the embodiment of the present invention, the target source code is a program framework, and may include a declaration of a class, names of methods to be called by the class, declarations of member variables, and the like, and may not include specific executable code. The target source code is set according to actual needs, and the embodiment of the present invention is not limited.
The generating module 203 completes the preliminary construction of the unit test script based on the abstract syntax tree of the target source code, and then adds the design case developed by the unit test driver to the preliminarily constructed unit test script to generate the unit test script, wherein the generated unit test script is a standardized UTDD script.
The device for generating the unit test script provided by the embodiment of the invention can introduce a pre-generated design case developed by the unit test driver, obtain the target source code, convert the target source code into the abstract syntax tree, and generate the unit test script according to the design case developed by the unit test driver and the abstract syntax tree of the target source code, so that the unit test script can cover the service function, and the coverage rate and the effectiveness of the unit test script are improved. Due to the fact that the coverage rate of the unit test scripts is improved, the test objects can be tested more comprehensively, and the risk that the follow-up test objects have problems is reduced.
On the basis of the above embodiments, further, the design case developed by the unit test driver adopts a preset template to describe the service function, including at least one expression statement; accordingly, the generating module 203 is specifically configured to:
a corresponding method name is created for each expression statement, and each expression statement is used as an annotation of the corresponding method name.
Specifically, when a developer performs case design, the developer can describe service functions through a preset template, so that the generated UTDD design case includes at least one expression statement. The preset template can adopt a GIVEN-WHEN-THEN expression template, and is set according to actual needs, and the embodiment of the invention is not limited.
When generating the unit test script, the generating module 203 creates a method name for each expression statement in the design case of the UTDD, and then takes the expression statement as an annotation of the corresponding method name.
Fig. 3 is a schematic structural diagram of a device for generating a unit test script according to another embodiment of the present invention, and as shown in fig. 3, on the basis of the foregoing embodiments, the device for generating a unit test script according to an embodiment of the present invention further includes a supplementary module 204, where:
the supplement module 204 is configured to supplement the case design description for the method name corresponding to each expression statement.
Specifically, the design case of the UTDD includes at least one expression statement, and each expression statement corresponds to a comment, which is a natural language explanation added by the developer for the expression statement. After creating a corresponding method name for each expression statement, the supplement module 204 obtains the annotation corresponding to each expression statement as a case design description of the method name corresponding to each expression statement.
On the basis of the foregoing embodiments, further, the conversion module 202 is specifically configured to:
and analyzing the class, the method and the member variable of the target source code to obtain an abstract syntax tree of the target source code.
Specifically, the conversion module 202 may parse the class, the method, and the member variable of the target source code through a syntax analysis tool, so as to obtain an abstract syntax tree of the target source code, where the abstract syntax tree includes a class name, at least one method name, and at least one member variable name.
On the basis of the above embodiments, further, the member variable includes an external member variable; accordingly, the generating module 203 is specifically configured to:
and generating a simulation statement according to the external member variable, and declaring the external member variable.
Specifically, the member variables include external member variables, which are used to make calls to external classes or methods, whereas the test scripts of UTDD are not really making calls to external member variables. The generating module 203 generates a simulation (mock) statement for the external member variable when generating the unit test script, realizes a mock dependent on the outside, and declares the external member variable.
Fig. 4 is a schematic structural diagram of a device for generating a unit test script according to yet another embodiment of the present invention, and as shown in fig. 4, on the basis of the foregoing embodiments, the device for generating a unit test script according to an embodiment of the present invention further includes a document generating module 205, where:
the document generating module 205 is configured to generate a unit test driver development review document according to the unit test script.
Specifically, after the unit test script is generated, the document generation module 205 may generate a UTDD Review document according to the unit test script, that is, information such as method definition and comments in the unit test script is summarized and stored in the UTDD Review document, so that a tester can conveniently view the information.
The embodiment of the apparatus provided in the embodiment of the present invention may be specifically configured to execute the processing flows of the above method embodiments, and the functions of the apparatus are not described herein again, and refer to the detailed description of the above method embodiments.
It should be noted that the method and apparatus for generating a unit test script provided in the embodiments of the present invention may be used in the financial field, and may also be used in any technical field other than the financial field.
Fig. 5 is a schematic physical structure diagram of an electronic device according to an embodiment of the present invention, and as shown in fig. 5, the electronic device may include: a processor (processor)501, a communication Interface (Communications Interface)502, a memory (memory)503, and a communication bus 504, wherein the processor 501, the communication Interface 502, and the memory 503 are configured to communicate with each other via the communication bus 504. The processor 501 may call logic instructions in the memory 503 to perform the following method: importing a design case developed by a unit test driver, wherein the design case developed by the unit test driver is generated in advance; acquiring a target source code, and converting the target source code into an abstract syntax tree; and generating a unit test script according to the design case developed by the unit test driver and the abstract syntax tree of the target source code.
In addition, the logic instructions in the memory 503 may be implemented in the form of software functional units and stored in a computer readable storage medium when the logic instructions are sold or used as independent products. 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 storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The present embodiment discloses a computer program product comprising a computer program stored on a non-transitory computer readable storage medium, the computer program comprising program instructions which, when executed by a computer, enable the computer to perform the method provided by the above-mentioned method embodiments, for example, comprising: importing a design case developed by a unit test driver, wherein the design case developed by the unit test driver is generated in advance; acquiring a target source code, and converting the target source code into an abstract syntax tree; and generating a unit test script according to the design case developed by the unit test driver and the abstract syntax tree of the target source code.
The present embodiment provides a computer-readable storage medium, which stores a computer program, where the computer program causes the computer to execute the method provided by the above method embodiments, for example, the method includes: importing a design case developed by a unit test driver, wherein the design case developed by the unit test driver is generated in advance; acquiring a target source code, and converting the target source code into an abstract syntax tree; and generating a unit test script according to the design case developed by the unit test driver and the abstract syntax tree of the target source code.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In the description herein, reference to the description of the terms "one embodiment," "a particular embodiment," "some embodiments," "for example," "an example," "a particular example," or "some examples," etc., means that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the invention. In this specification, the schematic representations of the terms used above do not necessarily refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
The above-mentioned embodiments are intended to illustrate the objects, technical solutions and advantages of the present invention in further detail, and it should be understood that the above-mentioned embodiments are only exemplary embodiments of the present invention, and are not intended to limit the scope of the present invention, and any modifications, equivalent substitutions, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.

Claims (10)

1. A method for generating a unit test script, comprising:
importing a design case developed by a unit test driver, wherein the design case developed by the unit test driver is generated in advance;
acquiring a target source code, and converting the target source code into an abstract syntax tree;
and generating a unit test script according to the design case developed by the unit test driver and the abstract syntax tree of the target source code.
2. The method of claim 1, wherein the design case developed by the unit test driver adopts a preset template to describe the business functions, including at least one expression statement; correspondingly, the generating a unit test script according to the design case developed by the unit test driver and the abstract syntax tree of the target source code includes:
a corresponding method name is created for each expression statement, and each expression statement is used as an annotation of the corresponding method name.
3. The method of claim 2, further comprising:
and supplementing case design description for the method name corresponding to each expression statement.
4. The method of claim 1, wherein converting the target source code into an abstract syntax tree comprises:
and analyzing the class, the method and the member variable of the target source code to obtain an abstract syntax tree of the target source code.
5. The method of claim 4, wherein the member variables include external member variables; correspondingly, the generating a unit test script according to the design case developed by the unit test driver and the abstract syntax tree of the target source code includes:
and generating a simulation statement according to the external member variable, and declaring the external member variable.
6. The method of any of claims 1 to 5, further comprising:
and generating a unit test drive development rechecking document according to the unit test script.
7. An apparatus for generating a unit test script, comprising:
the system comprises an importing module, a test module and a test module, wherein the importing module is used for importing a design case developed by a unit test driver, and the design case developed by the unit test driver is generated in advance;
the conversion module is used for acquiring a target source code and converting the target source code into an abstract syntax tree;
and the generating module is used for generating a unit test script according to the design case developed by the unit test driver and the abstract syntax tree of the target source code.
8. The apparatus of claim 7, wherein the design case developed by the unit test driver adopts a preset template to describe the business functions, and includes at least one expression statement; correspondingly, the generating module is specifically configured to:
a corresponding method name is created for each expression statement, and each expression statement is used as an annotation of the corresponding method name.
9. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the steps of the method of any of claims 1 to 6 are implemented when the computer program is executed by the processor.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 6.
CN202110843856.5A 2021-07-26 2021-07-26 Method and device for generating unit test script Pending CN113448874A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110843856.5A CN113448874A (en) 2021-07-26 2021-07-26 Method and device for generating unit test script

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110843856.5A CN113448874A (en) 2021-07-26 2021-07-26 Method and device for generating unit test script

Publications (1)

Publication Number Publication Date
CN113448874A true CN113448874A (en) 2021-09-28

Family

ID=77817180

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110843856.5A Pending CN113448874A (en) 2021-07-26 2021-07-26 Method and device for generating unit test script

Country Status (1)

Country Link
CN (1) CN113448874A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114265776A (en) * 2021-12-22 2022-04-01 浙江时空道宇科技有限公司 Unit test code generation method, apparatus, device, medium, and program product

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114265776A (en) * 2021-12-22 2022-04-01 浙江时空道宇科技有限公司 Unit test code generation method, apparatus, device, medium, and program product
CN114265776B (en) * 2021-12-22 2023-03-14 浙江时空道宇科技有限公司 Unit test code generation method, device, equipment and medium

Similar Documents

Publication Publication Date Title
US20090313613A1 (en) Methods and Apparatus for Automatic Translation of a Computer Program Language Code
US6874140B1 (en) Debug annotations
CN110941427B (en) Code generation method and code generator
US20090328016A1 (en) Generalized expression trees
CN113031932B (en) Project development method, apparatus, electronic device and storage medium
WO2023035563A1 (en) Applet cross-application migration method, device, terminal, system and storage medium
US8930923B2 (en) Generating debugging extension source code utilizing debugging information
Schmitt et al. An evaluation of domain-specific language technologies for code generation
CN115639980A (en) Draggable front-end logic arrangement method and device for low-code platform
EP2626784A1 (en) Method and apparatus for automated MATLAB interfacing
CN113448874A (en) Method and device for generating unit test script
CN111190585B (en) Method for realizing JAVA mode matching characteristic based on byte code enhancement technology
CN112632333A (en) Query statement generation method, device, equipment and computer readable storage medium
CN109359055B (en) Data testing method and device
Attallah et al. Towards a COSMIC FSM Programming Language Compiler.
CN113885841A (en) Script generation method and device, electronic equipment and readable medium
Neukirchen et al. Quality assurance for TTCN‐3 test specifications
CN112596737A (en) Method, system, equipment and storage medium for scanning function call relation
Westrup et al. Using the go programming language in practice
US11650802B2 (en) Idiomatic source code generation
Kara Design and implementation of the modelicaml code generator using acceleo 3. x
CN113703769B (en) CLI command execution method and related device
Blunk et al. Efficient Development of Domain-Specific Simulation Modelling Languages and Tools
Lin et al. Towards verifying VDM using SPIN
Singh PyKaldi: A Kaldi Wrapper in Python

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