CN113434435A - Test case logic automatic generation method and device - Google Patents

Test case logic automatic generation method and device Download PDF

Info

Publication number
CN113434435A
CN113434435A CN202110830165.1A CN202110830165A CN113434435A CN 113434435 A CN113434435 A CN 113434435A CN 202110830165 A CN202110830165 A CN 202110830165A CN 113434435 A CN113434435 A CN 113434435A
Authority
CN
China
Prior art keywords
test
logic
test case
program
data
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
CN202110830165.1A
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 CN202110830165.1A priority Critical patent/CN113434435A/en
Publication of CN113434435A publication Critical patent/CN113434435A/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
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/166Editing, e.g. inserting or deleting
    • G06F40/186Templates

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)
  • Debugging And Monitoring (AREA)

Abstract

The invention provides a test case logic automatic generation method and a device, which can be used in the technical field of big data, and the method comprises the following steps: determining a corresponding test case template according to a test request transmitted by a user; determining test data and test logic according to the test request; according to the test logic, the test data are filled into the test case template to form the test case corresponding to the test logic.

Description

Test case logic automatic generation method and device
Technical Field
The invention relates to the technical field of computer software testing, in particular to the technical field of big data, and particularly relates to a method and a device for automatically generating logic of a test case.
Background
In the existing automatic test of computer software, a program is biased to a white box, mainly faces to developers, and utilizes a TESTING or JUNIT framework to compile automatic test scripts in a code form for case data, scheduling initiation, assertion judgment on return and the like; a biased black box mainly faces to business testers, only needs to write test cases of test data combinations and other contents, and scheduling initiation and assertion judgment are packaged by various frameworks. The former has the advantages of flexibility and strong functions, but has a certain technical threshold; the latter has the advantage of simplicity and ease of use, but basically has a sequential structure, and it is difficult to implement functions of program logic such as a loop structure and a branch structure.
Disclosure of Invention
The invention aims to provide a logic automatic generation method of a test case, which realizes the purpose of generating the test case based on logic automation and improves the automatic test function of black box test. Another object of the present invention is to provide an apparatus for automatically generating test case logic. It is a further object of this invention to provide such a computer apparatus. It is a further object of this invention to provide such a readable medium.
In order to achieve the above object, the present invention discloses a method for automatically generating test case logic, which comprises:
determining a corresponding test case template according to a test request transmitted by a user;
determining test data and test logic according to the test request;
and filling the test data into the test case template according to the test logic to form a test case corresponding to the test logic.
Preferably, the method further comprises the step of pre-forming the test case template:
acquiring parameter information of an input/output field of a program to be tested;
generating a test case program in an EXCEL format according to the program to be tested;
and generating a default value of the input and output field, and filling the default value into the test case program to obtain the test case template.
Preferably, the acquiring the parameter information of the input/output field of the program to be tested specifically includes:
obtaining a MAP file of an input/output message of an interface of a program to be tested;
determining whether the input and output field has program definition, if not, determining the parameter information of the input and output field according to the MAP file;
if yes, analyzing the definition class defined by the program through JAVA reflection to obtain the parameter information of the input and output field.
Preferably, the generating of the test case program in the EXCEL format according to the program to be tested specifically includes:
carrying out syntactic analysis on the program to be tested to obtain a syntactic tree;
determining whether the program to be tested has branch logic according to the syntax tree;
and if so, forming an EXCEL format test case program comprising branch logic according to the syntax tree, and if not, forming the EXCEL format test case program according to the syntax tree.
Preferably, the method further comprises the following steps:
if the program to be tested has branch logic;
determining whether the branch predicates of the branches of the branch logic have corresponding packaged common functions and/or JAVA programs;
if yes, writing the calling information of the public function and/or JAVA program into the branch assertion so as to call the public function and/or JAVA program to judge the branch assertion through the calling information.
Preferably, the generating of the default value of the input/output field specifically includes:
acquiring a transaction log of an interface according to a parameter transmission interface of a preset program to be tested;
analyzing the transaction log to obtain transaction success data of the interface;
and determining whether the transaction success data matched with the input and output field exists in the transaction success data, if so, taking the transaction success data of the input and output field obtained by matching as a default value, and if not, setting the default value for the input and output field with unsuccessful matching.
Preferably, the filling the test data into the test case template according to the test logic to form a test case corresponding to the test logic specifically includes:
determining a logic type of the test logic, and if the logic type is a cycle logic, determining test case data corresponding to each cycle test of the cycle logic in the test data;
and respectively replacing default data in the test case template with the test case data corresponding to each cycle test to obtain the test case.
Preferably, the filling the test data into the test case template according to the test logic to form a test case corresponding to the test logic specifically includes:
determining a logic type of the test logic, and if the logic type is a branch logic, determining a branch assertion corresponding to each branch of the branch logic in the test data;
and respectively replacing default data in the test case template with the branch assertions corresponding to each branch to obtain a test case.
The invention also discloses a logic automatic generation device for the test case, which comprises:
the template determining module is used for determining a corresponding test case template according to the test request transmitted by the user;
the request analysis module is used for determining test data and test logic according to the test request;
and the test case generation module is used for filling the test data into the test case template according to the test logic to form a test case corresponding to the test logic.
The invention also discloses a computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor,
the processor, when executing the program, implements the method as described above.
The invention also discloses a computer-readable medium, having stored thereon a computer program,
which when executed by a processor implements the method as described above.
The test case logic automatic generation method determines a corresponding test case template according to a test request transmitted by a user, determines test data and test logic according to the test request, and fills the test data into the test case template according to the test logic to form a test case corresponding to the test logic. Therefore, the test case generates the test request allowing the user to transmit the test logic and the test data, automatically analyzes the test logic according to the test logic and the test data transmitted by the user, and fills the test data into the test case template according to the test logic to form the test case corresponding to the test logic. Therefore, the invention can automatically generate the test cases according to the test logic transmitted by the user without setting each test case by the user, thereby not only maintaining the advantages of simple and easy development of the black box test cases, reducing the technical threshold of the program case test and improving the automatic test function of the black box test.
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.
FIG. 1 is a block diagram illustrating an exemplary embodiment of a test case logic automated generation system in accordance with the present invention;
FIG. 2 is a flow diagram illustrating a method for automated generation of test case logic according to an embodiment of the present invention;
FIG. 3 is a flow chart of a specific embodiment S000 of the test case logic automated generation method of the present invention;
FIG. 4 is a flowchart of a method for automatically generating test case logic according to an embodiment S010 of the present invention;
FIG. 5 is a flowchart of a specific embodiment S020 of the method for automatically generating test case logic according to the invention;
FIG. 6 is a diagram illustrating a branch logic syntax tree for an embodiment of the test case logic automation generation method of the present invention;
FIG. 7 is a flow chart of a specific embodiment of a test case logic automated generation method S400 of the present invention;
FIG. 8 is a flowchart of a specific embodiment S030 of a test case logic automated generation method of the invention;
FIG. 9 is a flowchart of a test case logic automated generation method embodiment S300 of the present invention;
FIG. 10 is a schematic diagram of a loop logic syntax tree in accordance with an embodiment of the test case logic automated generation method of the present invention;
FIG. 11 is a schematic diagram illustrating the judgment of the cyclic logic syntax tree in accordance with the exemplary embodiment of the test case logic automated generation method of the present invention; (ii) a
FIG. 12 is a second flowchart of a test case logic automated generation method S300 according to an embodiment of the present invention;
FIG. 13 is a block diagram illustrating an exemplary embodiment of a test case logic automation generation apparatus of the present invention;
FIG. 14 illustrates a schematic block diagram of a computer device suitable for use in implementing embodiments of the present invention.
Detailed Description
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 method and the device for automatically generating the test case logic disclosed in the present application can be used in the field of big data technology, and can also be used in any field except the field of big data technology.
In order to facilitate understanding of the technical solutions provided in the present application, the following first describes relevant contents of the technical solutions in the present application. The method for automatically generating the logic of the test case can automatically generate the test case according to the test logic transmitted by the user without setting each test case by the user, thereby not only maintaining the advantages of simple development and easy use of the black box test case, reducing the technical threshold of the test of the program case and improving the automatic test function of the black box test.
Fig. 1 is a schematic structural diagram of a test case logic automatic generation system according to an embodiment of the present invention, and as shown in fig. 1, the test case logic automatic generation system according to the embodiment of the present invention includes a user terminal 1 and a test case logic automatic generation device 2.
The user terminal 1 may form a test request according to the test logic and the test data transmitted by the user, and transmit the test request to the test case logic automatic generation apparatus 2.
The automatic test case logic generation device 2 determines a corresponding test case template according to a test request transmitted by a user, determines test data and test logic according to the test request, and fills the test data into the test case template according to the test logic to form a test case corresponding to the test logic.
It should be noted that, in the present embodiment, the test case logic automatic generation apparatus 2 receives the test request transmitted by the user terminal 1, and in other embodiments, the user may also directly input the test request on the test case logic automatic generation apparatus 2. For example, for a test case in EXCEL format, the test case logic automation generation apparatus 2 may provide an input interface in EXCEL form, and the user may simply input a test request through an input box of the EXCEL form.
The following describes an implementation process of the test case logic automatic generation method provided by the embodiment of the present invention, taking the test case logic automatic generation apparatus 2 as an execution subject. It can be understood that the execution subject of the test case logic automatic generation method provided by the embodiment of the present invention includes, but is not limited to, the test case logic automatic generation apparatus 2.
According to one aspect of the invention, the embodiment discloses a method for automatically generating test case logic. As shown in fig. 2, in this embodiment, the method includes:
s100: and determining a corresponding test case template according to the test request transmitted by the user.
Specifically, the test request transmitted by the user may include related information of the program to be tested, for example, related information such as a name of the program to be tested. Therefore, the test request is analyzed to determine the relevant information of the program to be tested of the user, and the test case template corresponding to the program to be tested is determined from the pre-stored test case templates according to the relevant information of the program to be tested. In other embodiments, if the test case template is determined or designated in advance, the determined or designated test case template may be directly obtained when the test request transmitted by the user is received, so as to form the test case by using the determined or designated test case template.
S200: and determining test data and test logic according to the test request.
Specifically, the test request transmitted by the user includes test data and test logic, and the test data and the test logic can be obtained by analyzing the content of the test request. For example, for a test case in the EXCEL format, an input interface in the form of an EXCEL table may be provided to a user, identification flags of different test logics may be preset, and when the identification flags are included in the test logic of a test request input by the user, the logic type of the test logic may be determined. In other embodiments, the test logic corresponding to each input interface may be predetermined, and when the user inputs the test data at the input interface, the test request may be automatically formed according to the predetermined test logic and the test data input by the user. It should be noted that the test logic may include at least one of logic types such as loop logic and branch logic.
S300: and filling the test data into the test case template according to the test logic to form a test case corresponding to the test logic.
Specifically, the test data in the test request transmitted by the user corresponds to the test logic, for example, for the test logic with the logic type being the cyclic logic, the test data needs to include the test data of each cycle of the cyclic logic; for test logic with a logic type of branch logic, test data for forming a branch predicate needs to be included in the test data. Therefore, the test data can be analyzed according to the test logic, and the test data is filled in the corresponding position of the test case template to form the test case.
The test case logic automatic generation method determines a corresponding test case template according to a test request transmitted by a user, determines test data and test logic according to the test request, and fills the test data into the test case template according to the test logic to form a test case corresponding to the test logic. Therefore, the test case generates the test request allowing the user to transmit the test logic and the test data, automatically analyzes the test logic according to the test logic and the test data transmitted by the user, and fills the test data into the test case template according to the test logic to form the test case corresponding to the test logic. Therefore, the invention can automatically generate the test cases according to the test logic transmitted by the user without setting each test case by the user, thereby not only maintaining the advantages of simple and easy development of the black box test cases, reducing the technical threshold of the program case test and improving the automatic test function of the black box test.
In a preferred embodiment, as shown in fig. 3, the method further includes a step S000 of pre-forming the test case template:
s010: and acquiring the parameter information of the input and output field of the program to be tested.
S020: and generating a test case program in an EXCEL format according to the program to be tested.
S030: and generating a default value of the input and output field, and filling the default value into the test case program to obtain the test case template.
It can be understood that, in order to automatically generate the test cases, the program to be tested needs to be analyzed and a test case template of the program to be tested needs to be automatically generated. Specifically, in the preferred embodiment, first, parameter information of an input/output field of the program to be tested is obtained, where the parameter information may include a field name and an attribute of the input/output field. Then, the program to be tested is automatically obtained, the program to be tested can be analyzed to generate the test case program in the EXCEL format,
in a preferred embodiment, as shown in fig. 4, the acquiring, by the S010, the parameter information of the input/output field of the program to be tested specifically includes:
s011: and obtaining the MAP file of the input and output message of the interface of the program to be tested.
S012: and determining whether the input and output field has program definition, if not, determining the parameter information of the input and output field according to the MAP file.
S013: if yes, analyzing the definition class defined by the program through JAVA reflection to obtain the parameter information of the input and output field.
It will be appreciated that in the preferred embodiment, the parameter information associated with the input and output fields of the interface of the program to be tested may be automatically obtained and analyzed. The field names and the parameter information of the attributes of the input and output fields can be obtained through input and output messages MAP of the interface, so that the corresponding test case template in the EXCEL format is automatically generated. Specifically, the definitions of the input and output fields of the program interface to be tested can be automatically analyzed and obtained, the message MAP definitions of the input and output of the interface are obtained, and the complete definitions of all the input and output fields of the functions of the interface are recorded, including the names and types of the fields, whether the fields are necessary to be input or not, the maximum length and other attributes.
In a specific example, if a program has a program definition for Input fields and Output fields of Output Ouput, and a program definition class of Input and Output of the Input and Output fields is obtained, the program definition class of Input and Output can be analyzed in a JAVA reflection manner to obtain field names and parameter information of attributes of all fields of Input and Output, and the field names and the parameter information are recorded in a Map format.
If the tested program does not Input program definition classes of Input and Output, but directly uses MAP call and return, all fields using GET function for Input reference MAP in the program are obtained by using a static code analysis mode, all effective Input fields are obtained, all fields using PUT function for return MAP in the program are obtained in the same way, all effective Output fields are obtained, and therefore complete field definition of Input and Output is obtained.
And automatically generating a corresponding test case template in the EXCEL format according to the input and output message MAP definition obtained by analysis, and the obtained input and output field name and the attribute thereof.
In a preferred embodiment, as shown in fig. 5, the step S020 of generating a test case program in an EXCEL format according to a program to be tested specifically includes:
s021: and carrying out syntactic analysis on the program to be tested to obtain a syntactic tree.
S022: and determining whether the program to be tested has branch logic according to the syntax tree.
S023: and if so, forming an EXCEL format test case program comprising branch logic according to the syntax tree, and if not, forming the EXCEL format test case program according to the syntax tree.
Specifically, in the preferred embodiment, in order to realize automatic generation of the test case program, the program to be tested is automatically acquired, and whether branch logic exists in the program to be tested is analyzed in a syntax analysis manner, and if branch logic exists, the test case program including the branch logic needs to be formed. Taking the transaction of "commission charge collection mode" as an example, one of the input fields is "payflag commission charge payment mode", assuming that the transaction process is judged and returned according to the commission charge payment mode, the code segments are as follows:
Figure BDA0003175180230000081
the syntax analysis is performed on the program under test to obtain the syntax tree shown in fig. 6.
The analysis finds that the ReturnStatement node of the first returned result is a child node of the first IfStatement node, returns TRUE If the condition of If (payflag ═ 1) is met, and returns FALSE If the other returned node ReturnStatement node is also a child node of the IfStatement node, and meets the condition of If (payflag ═ 0).
Therefore, in order to enable the test case to automatically determine the returned result covering the tested program, the automatically generated test case automatically generates the case of program logic for making different assertion determinations according to different branches, and the example of the case is shown in table 1.
TABLE 1
Figure BDA0003175180230000082
Figure BDA0003175180230000091
In a preferred embodiment, as shown in fig. 7, the method further includes S400:
s041: if the program to be tested has branch logic.
S042: determining whether a corresponding packaged common function and/or JAVA program exists in the branch assertion of each branch of the branch logic.
S043: if yes, writing the calling information of the public function and/or JAVA program into the branch assertion so as to call the public function and/or JAVA program to judge the branch assertion through the calling information.
Specifically, when branch logic exists in the program to be tested, each branch of the branch logic needs to set a branch assertion to determine the program to be run next. The method comprises the steps that for some specific branch assertions, preset packaged public functions and/or JAVA programs exist, the packaged public functions and/or JAVA programs can be directly called to judge the branch assertions, and if the balance assertions are packaged, the balance asserted public functions can be called in deposit transactions. When the directly-called JAVA program exists, the full path name of the JAVA program to be called can be preset, and the JAVA program is obtained and operated in a reflection mode to carry out branch assertion judgment.
In a specific example, the test case supports direct call of the packaged public function, and if the balance assertion is packaged, the balance assertion public function can be called in the deposit transaction as follows: in the operation process of the test case, a balance inquiry is automatically made before the deposit transaction to obtain a value A, a balance inquiry is made after the deposit transaction is completed to obtain a value B, and then, the sum of A + C and B is automatically asserted to judge whether the sum of A + C and B is true or not according to the sum of C of the current deposit transaction.
The test case, besides supporting the call of the public function, also supports the direct call of the JAVA program function, as can be called in the deposit transaction, as shown in table 2, the JAVA program can be called by setting the path:
TABLE 2
Case name Assertion
Debit card deposit # JAVA call { com
When the test case runs, analyzing and finding that a JAVA program with a full path designation of com.icbc.gz.checklog needs to run when the test case needs to be predicated, the JAVA program is obtained and run in a reflection mode, whether corresponding log records are carried out in the current transaction is judged, and the predicated predication is carried out according to a return result of the JAVA program.
In a preferred embodiment, as shown in fig. 8, the generating of the default value of the input/output field by S030 specifically includes:
s031: and acquiring a transaction log of an interface according to a parameter transmission interface of a preset program to be tested.
S032: and analyzing the transaction log to obtain the transaction success data of the interface.
S033: and determining whether the transaction success data matched with the input and output field exists in the transaction success data, if so, taking the transaction success data of the input and output field obtained by matching as a default value, and if not, setting the default value for the input and output field with unsuccessful matching.
Specifically, according to the name of the program interface to be tested, the transaction log of the interface, which is stored in the transaction gateway and other systems before, is automatically acquired, the latest successful transaction data is obtained through analysis, and the value of each input field is filled into the field corresponding to the test case to be used as the default value. And if the fields without default values still exist, assigning initial values, and setting default values for input and output fields with unsuccessful matching, wherein the default value of the int type is 0, the default value of the bootean is true, the default value of the Date type is Date, value of ('2020-08-08'), and the like. Further, for data to be changed for a transaction, such as working DATE, working TIME, etc., the defined internal variables such as WORK _ DATE, WORK _ TIME, etc. are used. For example, table 3 below shows that a test case fragment is the data assignment of the automatically generated partial fields, where the assignments of the two fields of WORK _ DATE and real _ TIME are the built-in variables { WORK _ DATE } and { WORK _ TIME } respectively, and the assignment of the id _ code field is the identity number used in the last transaction.
TABLE 3
Input field Input valuation
work_date {WORK_DATE}
real_time {WORK_TIME}
id_cide 450521199212010029
In a preferred embodiment, as shown in fig. 9, the step S300 of filling the test data into the test case template according to the test logic to form a test case corresponding to the test logic specifically includes:
s311: and determining the logic type of the test logic, and if the logic type is the cycle logic, determining test case data corresponding to each cycle test of the cycle logic in the test data.
S312: and respectively replacing default data in the test case template with the test case data corresponding to each cycle test to obtain the test case.
It will be appreciated that in the preferred embodiment, a program logic framework of a loop structure of automated test cases may be automatically generated, enabling complex case data combinations prior to initiating a transaction test. Specifically, a loop logic framework in the form of # loop { } can be automatically generated in the case, and the tester can supplement the data of the loop condition as required. For example, in the same case, a test scenario with three different card types is executed, and the tester only needs to fill three card number data in the # cycle { }.
To determine whether a field has loop logic, a syntax tree as shown in FIG. 10 can be obtained by parsing the program to be tested. Through a syntax tree, it can be found that all three IfStatement nodes perform equivalence judgment (equivalence expression) on the variable of the payflag, where the value of the payflag is judged to be 1 for the first time, as shown in fig. 11, the value of the payflag is judged to be 2 for the second time, and the value of the payflag is judged to be 3 for the third time.
In order to enable the test case program to cover the three branches of the program to be tested, the payflag field is automatically assigned as a logic of a loop structure in the automatically generated test case, and example cases are shown in table 4:
TABLE 4
Figure BDA0003175180230000111
Taking the transaction of 'commission charge' as an example, one of the input fields is 'payflag commission payment mode', and the transaction procedure judges the commission payment mode:
Figure BDA0003175180230000112
therefore, a program logic framework of a loop structure of the automatic test case can be automatically generated, and complex case data combination before transaction test is initiated is realized. The content of the part belongs to the instruction area of logic, and the value is the actual value or variable value enclosed by the # loop { }.
In one embodiment, the data may be automatically combined to form a virtual test case for actual operation according to the cycle condition data filled by the tester. If the tester fills A, B, C card number data in the # cycle { }, three virtual cases to be actually run are automatically generated, the data of the card number fields of the three cases are A, B, C in sequence, and the other field values are kept unchanged. Taking a bank card deposit transaction as an example, if the current test needs to cover three different card types, namely a first type card, a second type card and a third type card, only one row of test cases needs to be compiled, and only in a deposit card number field, a # cycle is defined as follows, which shows that the row of cases actually needs to be executed in a cycle three times, wherein the first time uses a card with a mantissa 6884, the second time uses a card with a mantissa 7317, and the third time uses a card with a mantissa 0526, as shown in table 5.
TABLE 5
Figure BDA0003175180230000121
This loop structure, with the data used therein, also supports the variable form enclosed by braces { }, as shown in table 6:
TABLE 6
Case name Card number
Debit card deposit Cycle # cycle { { first type card }, { second type card }, { third type card }
In a preferred embodiment, as shown in fig. 12, the step S300 of filling the test data into the test case template according to the test logic to form a test case corresponding to the test logic specifically includes:
s321: and determining the logic type of the test logic, and if the logic type is a branch logic, determining a branch assertion corresponding to each branch of the branch logic in the test data.
S322: and respectively replacing default data in the test case template with the branch assertions corresponding to each branch to obtain a test case.
It will be appreciated that in the preferred embodiment, a program logic framework of the branch structure of the automated test case may be automatically generated, enabling complex assertion decisions after initiating the transaction test. Specifically, a branch logic framework in the form of a # branch { } is automatically generated in the assertion part of the case, and the tester supplements the judgment condition of the branch as required. For example, if the associated assertion is to determine that the bank card subscription agreement is successful, the bank card can be written in the # branch { } as an un-subscribed card. And then, according to the branch conditions filled by the tester, firstly, executing corresponding assertion judgment on the premise that the branch conditions are met and are true, and otherwise, automatically skipping the corresponding assertion judgment.
Taking a local RMB fixed-activity protocol signing transaction as an example, after a transaction test is initiated, if the card for test is an unsigned card, the transaction return result should be successful signing, and if the card for test is a signed card, the transaction return result should be refused signing. However, in the automatic test process, the card may be randomly used in the data pool, or the data in the loop structure may be used, and it is not possible to determine whether the card used at the time has been signed up before, so that the value form surrounded by the # branch { } may be used as follows, and different assertion branches may be taken by determining the type of cardtype. If the # branch { cardtype ═ no signed card } is TRUE, making assertion judgment of the host table a. field B ═ TRUE; if the # branch { cardtype ═ signed card } is true, an assertion judgment is made for the host table a. field B ═ FALSE, as shown in table 7.
TABLE 7
Figure BDA0003175180230000131
The invention will be further illustrated by means of a specific example. In this particular example, the workflow of the test case logic automation generation method is as follows. The whole is divided into two parts, the first part is a test case preparation stage, which is mainly responsible for generating test cases with program logic functions, and comprises steps S01 to S04; the second part is the test case operation stage, which is mainly responsible for the combination, initiation and result judgment of test cases with program logic functions, including steps S05 to S09.
Step S01: and automatically analyzing and acquiring the definition of the input and output fields of the interface to be tested to obtain the definition of the detailed information of each field of the input and output message of the interface.
Step S02: and automatically generating a corresponding test case template in the EXCEL format according to the input and output field names and the attributes of the interfaces to be tested.
Step S03: and automatically generating and filling default test data of the automatic test case according to the transaction log analysis, the default initial value and the mode of the built-in variable.
Step S04: and automatically generating a loop logic framework in the form of # loop { } and a branch logic framework in the form of # branch { } for the automatic test cases.
Step S05: and analyzing the circulation condition data of the circulation logic actually supplemented by the tester in the automatic test case.
Step S06: and automatically combining the data to form a virtual test case which actually runs according to the circulation condition data supplemented by the testers.
Step S07: in the test process, the test case directly and dynamically calls the packaged public function and the JAVA program.
Step S08: and analyzing the branch conditions of the branch logic actually supplemented by the tester in the automatic test case.
Step S09: according to the branch conditions filled by the tester, corresponding assertion judgment is executed only on the premise that the branch conditions are met.
The invention provides an automatic test system and method for program logicalization of test cases, which automatically generate cases with program logicalization for test cases in a black box form according to source code analysis of a tested program, simultaneously support program logic functions of a branch structure and a loop structure, and realize dynamic calling of public functions and JAVA programs. The method has the following advantages:
1. the advantages of simplicity and easiness in use of black box test case development are kept, and the technical threshold is reduced.
2. The advantage of program logic is fully exerted, and the automatic test function of the test case is improved.
3. By utilizing the circulation logic function, the tester can automatically combine data to form a virtual test case which actually runs only by filling in circulation condition data, and the repeated work of compiling the test case by the tester is reduced.
4. By utilizing the branch logic function, a tester can automatically perform corresponding assertion judgment on the premise of meeting the branch condition only by filling the branch judgment condition, so that the success rate of assertion judgment of the automatic test is improved.
5. The common function and the JAVA program can be dynamically called in the running process of the test case, the assertion module can be independent, the data and assertion of the test case can be separated, the test case only needs to be associated with the corresponding test data and assertion function like a building block, and the realization of the automatic test case is improved.
Based on the same principle, the embodiment also discloses a test case logic automatic generation device. As shown in fig. 13, in the present embodiment, the apparatus includes a template determination module 11, a request analysis module 12, and a test case generation module 13.
The template determining module 11 is configured to determine a corresponding test case template according to a test request transmitted by a user.
The request analysis module 12 is configured to determine test data and test logic according to the test request.
The test case generating module 13 is configured to fill the test data into the test case template according to the test logic to form a test case corresponding to the test logic.
The test case logic automatic generation method determines a corresponding test case template according to a test request transmitted by a user, determines test data and test logic according to the test request, and fills the test data into the test case template according to the test logic to form a test case corresponding to the test logic. Therefore, the test case generates the test request allowing the user to transmit the test logic and the test data, automatically analyzes the test logic according to the test logic and the test data transmitted by the user, and fills the test data into the test case template according to the test logic to form the test case corresponding to the test logic. Therefore, the invention can automatically generate the test cases according to the test logic transmitted by the user without setting each test case by the user, thereby not only maintaining the advantages of simple and easy development of the black box test cases, reducing the technical threshold of the program case test and improving the automatic test function of the black box test.
Since the principle of the device for solving the problems is similar to the method, the implementation of the device can refer to the implementation of the method, and the detailed description is omitted here.
The systems, devices, modules or units illustrated in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions. A typical implementation device is a computer device, which may be, for example, a personal computer, a laptop computer, a cellular telephone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
In a typical example, the computer device specifically comprises a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the method performed by the client as described above when executing the program, or the processor implementing the method performed by the server as described above when executing the program.
Referring now to FIG. 14, shown is a schematic block diagram of a computer device 600 suitable for use in implementing embodiments of the present application.
As shown in fig. 14, the computer apparatus 600 includes a Central Processing Unit (CPU)601 which can perform various appropriate works and processes according to a program stored in a Read Only Memory (ROM)602 or a program loaded from a storage section 608 into a Random Access Memory (RAM)) 603. In the RAM603, various programs and data necessary for the operation of the system 600 are also stored. The CPU601, ROM602, and RAM603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
The following components are connected to the I/O interface 605: an input portion 606 including a keyboard, a mouse, and the like; an output section 607 including a Cathode Ray Tube (CRT), a liquid crystal feedback (LCD), and the like, and a speaker and the like; a storage section 608 including a hard disk and the like; and a communication section 609 including a network interface card such as a LAN card, a modem, or the like. The communication section 609 performs communication processing via a network such as the internet. The driver 610 is also connected to the I/O interface 606 as needed. A removable medium 611 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 610 as necessary, so that a computer program read out therefrom is mounted as necessary on the storage section 608.
In particular, according to an embodiment of the present invention, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the invention include a computer program product comprising a computer program tangibly embodied on a machine-readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 609, and/or installed from the removable medium 611.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
For convenience of description, the above devices are described as being divided into various units by function, and are described separately. Of course, the functionality of the units may be implemented in one or more software and/or hardware when implementing the present application.
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.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application 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 application may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The application may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
The above description is only an example of the present application and is not intended to limit the present application. Various modifications and changes may occur to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.

Claims (11)

1. A method for automatically generating test case logic is characterized by comprising the following steps:
determining a corresponding test case template according to a test request transmitted by a user;
determining test data and test logic according to the test request;
and filling the test data into the test case template according to the test logic to form a test case corresponding to the test logic.
2. The method of automated test case logic generation of claim 1, further comprising the step of pre-forming the test case template:
acquiring parameter information of an input/output field of a program to be tested;
generating a test case program in an EXCEL format according to the program to be tested;
and generating a default value of the input and output field, and filling the default value into the test case program to obtain the test case template.
3. The method as claimed in claim 2, wherein the obtaining parameter information of the input/output field of the program to be tested specifically comprises:
obtaining a MAP file of an input/output message of an interface of a program to be tested;
determining whether the input and output field has program definition, if not, determining the parameter information of the input and output field according to the MAP file;
if yes, analyzing the definition class defined by the program through JAVA reflection to obtain the parameter information of the input and output field.
4. The automated test case logic generation method of claim 2, wherein generating the test case program in the EXCEL format from the program to be tested specifically comprises:
carrying out syntactic analysis on the program to be tested to obtain a syntactic tree;
determining whether the program to be tested has branch logic according to the syntax tree;
and if so, forming an EXCEL format test case program comprising branch logic according to the syntax tree, and if not, forming the EXCEL format test case program according to the syntax tree.
5. The method for automated test case logic generation according to claim 2, further comprising:
if the program to be tested has branch logic;
determining whether the branch predicates of the branches of the branch logic have corresponding packaged common functions and/or JAVA programs;
if yes, writing the calling information of the public function and/or JAVA program into the branch assertion so as to call the public function and/or JAVA program to judge the branch assertion through the calling information.
6. The automated test case logic generation method of claim 2, wherein the generating default values for the input-output fields specifically comprises:
acquiring a transaction log of an interface according to a parameter transmission interface of a preset program to be tested;
analyzing the transaction log to obtain transaction success data of the interface;
and determining whether the transaction success data matched with the input and output field exists in the transaction success data, if so, taking the transaction success data of the input and output field obtained by matching as a default value, and if not, setting the default value for the input and output field with unsuccessful matching.
7. The method of claim 1, wherein the filling the test data into the test case template according to the test logic to form a test case corresponding to the test logic specifically comprises:
determining a logic type of the test logic, and if the logic type is a cycle logic, determining test case data corresponding to each cycle test of the cycle logic in the test data;
and respectively replacing default data in the test case template with the test case data corresponding to each cycle test to obtain the test case.
8. The method of claim 1, wherein the filling the test data into the test case template according to the test logic to form a test case corresponding to the test logic specifically comprises:
determining a logic type of the test logic, and if the logic type is a branch logic, determining a branch assertion corresponding to each branch of the branch logic in the test data;
and respectively replacing default data in the test case template with the branch assertions corresponding to each branch to obtain a test case.
9. An apparatus for automated generation of test case logic, comprising:
the template determining module is used for determining a corresponding test case template according to the test request transmitted by the user;
the request analysis module is used for determining test data and test logic according to the test request;
and the test case generation module is used for filling the test data into the test case template according to the test logic to form a test case corresponding to the test logic.
10. A computer device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor,
the processor, when executing the program, implements the method of any of claims 1-8.
11. A computer-readable medium, having stored thereon a computer program,
the program when executed by a processor implementing the method according to any one of claims 1-8.
CN202110830165.1A 2021-07-22 2021-07-22 Test case logic automatic generation method and device Pending CN113434435A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110830165.1A CN113434435A (en) 2021-07-22 2021-07-22 Test case logic automatic generation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110830165.1A CN113434435A (en) 2021-07-22 2021-07-22 Test case logic automatic generation method and device

Publications (1)

Publication Number Publication Date
CN113434435A true CN113434435A (en) 2021-09-24

Family

ID=77761372

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110830165.1A Pending CN113434435A (en) 2021-07-22 2021-07-22 Test case logic automatic generation method and device

Country Status (1)

Country Link
CN (1) CN113434435A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115543775A (en) * 2022-08-17 2022-12-30 睿智合创(北京)科技有限公司 Automatic test case generation method

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115543775A (en) * 2022-08-17 2022-12-30 睿智合创(北京)科技有限公司 Automatic test case generation method

Similar Documents

Publication Publication Date Title
US20190324772A1 (en) Method and device for processing smart contracts
CN110597730B (en) Automatic test case generation method and system based on scene method
CN113079198B (en) Method and device for converting cloud platform interface protocol
CN110933095A (en) Message parsing method and device
US9063753B2 (en) Scripting framework for business objects
CN114138674A (en) Automatic testing method and device and computer equipment
CN111078573A (en) Test message generation method and device
CN113434435A (en) Test case logic automatic generation method and device
CN114356341A (en) Data processing method, device, equipment, storage medium and product
CN111949543B (en) Test method and device based on distributed platform, electronic equipment and storage medium
CN114327405A (en) Data processing method, device, equipment and storage medium
CN114202419A (en) Message generation method, device, equipment, storage medium and program product
CN112561690A (en) Method, system, equipment and storage medium for testing credit card staging service interface
CN115511644A (en) Processing method for target policy, electronic device and readable storage medium
CN115701591A (en) Business process testing method, device, medium and electronic equipment
CN111309319A (en) Inheritable office data dynamic page configuration method and device
CN113807969A (en) Parallel verification method for service system and related equipment
CN112363700A (en) Cooperative creation method and device of intelligent contract, computer equipment and storage medium
CN111949259A (en) Risk decision configuration method, system, electronic equipment and storage medium
CN112328503A (en) Task acceptance method for software development working platform
CN112182083A (en) File generation method, device, equipment and storage medium
CN111160403A (en) Method and device for multiplexing and discovering API (application program interface)
CN111401020A (en) Interface loading method and system and computing equipment
CN111506301B (en) Method for bypassing system restriction reflection call and related equipment
CN114944998B (en) Internet of things system testing method and device based on simulator

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