CN114610637A - Test case generation method, device, equipment and medium suitable for front-end project - Google Patents

Test case generation method, device, equipment and medium suitable for front-end project Download PDF

Info

Publication number
CN114610637A
CN114610637A CN202210285461.2A CN202210285461A CN114610637A CN 114610637 A CN114610637 A CN 114610637A CN 202210285461 A CN202210285461 A CN 202210285461A CN 114610637 A CN114610637 A CN 114610637A
Authority
CN
China
Prior art keywords
test case
component
name
code block
jump
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
CN202210285461.2A
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.)
Ping An Puhui Enterprise Management Co Ltd
Original Assignee
Ping An Puhui Enterprise Management Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Puhui Enterprise Management Co Ltd filed Critical Ping An Puhui Enterprise Management Co Ltd
Priority to CN202210285461.2A priority Critical patent/CN114610637A/en
Publication of CN114610637A publication Critical patent/CN114610637A/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/3676Test management for coverage analysis
    • 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

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 application relates to the technical field of testing, and discloses a test case generation method, a device, equipment and a medium suitable for front-end projects, wherein the method comprises the following steps: generating a test case of an interface request in the component initialization process for each Hooks component in the front-end project code file package; generating a testing case triggered by the embedded point in the component initialization process for each Hooks component by adopting a preset embedded point method keyword set; generating a jumping test case triggered by a clicking event for each Hooks component; generating a test case of jump triggered indirectly for each Hooks component; and generating a test case set corresponding to the front-end project code file package according to each test case. The method and the device improve the coverage of the test cases, adopt unified compiling specifications and improve the normalization of the test cases.

Description

Test case generation method, device, equipment and medium suitable for front-end project
Technical Field
The present application relates to the field of testing technologies, and in particular, to a method, an apparatus, a device, and a medium for generating a test case suitable for a front-end project.
Background
At present, a front-end project adopts a tester to compile test cases of a function point to be tested and an associated influence function. Due to the fact that the function points to be tested and the associated influence function points are not comprehensively understood by the testers, the compiled test cases cannot cover all the function points to be tested, the test of the front-end project is incomplete, and the running stability after the front-end project is on line is influenced.
Disclosure of Invention
The application mainly aims to provide a test case generation method, a test case generation device, test case generation equipment and a test case generation medium which are suitable for front-end projects, and aims to solve the technical problem that the written test cases cannot cover all functional points to be tested when testing personnel are used for writing the test cases in the front-end projects at present.
In order to achieve the above object, the present application provides a test case generation method suitable for front-end projects, where the method includes:
acquiring a front-end project code file package, and carrying out Hooks component identification on the front-end project code file package;
generating a test case of an interface request in the component initialization process for each Hooks component to obtain a first initialization test case;
generating a testing case triggered by the embedded point in the component initialization process for each Hooks component by adopting a preset embedded point method keyword set to obtain a second initialization testing case;
generating a jumping test case triggered by a click event for each Hooks component to obtain a first jumping test case;
generating a test case of indirect-triggered jump for each Hooks component to obtain a second jump test case;
and generating a test case set corresponding to the front-end project code file package according to each first initialization test case, each second initialization test case, each first jump test case and each second jump test case.
Further, the step of acquiring the front-end project code file package and performing the Hooks component identification on the front-end project code file package includes:
acquiring development code address configuration data;
acquiring the front-end project code file package from a storage space corresponding to the development code address configuration data;
taking any one front-end project code file in the front-end project code file package as a code file to be analyzed;
judging whether the code file to be analyzed contains a preset first method keyword, wherein the first method keyword is a method keyword for declaring and using a variable;
if yes, judging whether the code file to be analyzed contains a preset second method keyword, wherein the second method keyword is a method keyword simulating a life cycle method;
and if so, determining the code file to be analyzed as the Hooks component.
Further, the step of generating a test case of an interface request in the component initialization process for each Hooks component to obtain a first initialization test case includes:
taking any one of the Hooks components as a first analysis component;
intercepting a component name from the complete file name of the first analysis component as a first component name;
acquiring a method code block corresponding to a preset second method keyword from the first analysis component as a first code block;
searching whether a preset request initiating method keyword exists in a first incoming parameter of the first code block;
if yes, determining a target request mode according to a first keyword behind the keyword of the request initiating method in the first code block;
acquiring a method code block corresponding to the keyword for initiating the request method from the first analysis component as a request method code block;
determining a target request interface address according to a first incoming parameter of the request method code block;
determining target request participation according to a second incoming parameter of the request method code block;
determining a target request callback function according to a third incoming parameter of the request method code block;
taking codes except the request method code block in the first analysis component as codes to be processed;
judging whether the callback field name in the target request callback function exists in the code to be processed or not;
if so, taking each callback field name in the code to be processed as a necessary callback field name set;
and generating the first initialization test case corresponding to the first analysis component according to a preset interface request test case template, the first component name, the target request mode, the target request interface address, the target request entry parameter and the necessary callback field name set.
Further, the step of generating a test case triggered by the embedded point in the component initialization process for each Hooks component by using a preset embedded point method keyword set to obtain a second initialization test case includes:
taking any one of the Hooks components as a second analysis component;
intercepting a component name from the complete file name of the second analysis component as a second component name;
acquiring a method code block corresponding to a preset second method keyword from the second analysis component as a second code block;
judging whether the embedded point method keywords in the embedded point method keyword set exist in the second code block;
if yes, taking each buried point method keyword in the second code block as a hit method keyword;
taking a method code block corresponding to the hit method keyword in the second code block as a hit buried point code block;
taking a first parameter in the hit buried point code block as a buried point identifier;
and generating the second initialization test case corresponding to the second analysis component according to a preset buried point triggering test case template, the second component name and each buried point identifier.
Further, the step of generating a jump test case triggered by a click event for each Hooks component to obtain a first jump test case includes:
taking any one of the Hooks components as a third analysis component;
intercepting a component name from the complete file name of the third analysis component to be used as a third component name;
acquiring a function instantiation code block corresponding to a preset hook function keyword from the third analysis component as a third code block;
acquiring a method name corresponding to a preset component skipping method keyword from the third code block as a skipping method name;
if the name of the skip method is obtained, obtaining a method code block corresponding to a preset return keyword from the third analysis component as a fourth code block;
judging whether the fourth code block has the name of the skip method;
if so, acquiring a display case corresponding to the skipping method name from the third analysis component as a target display case;
acquiring a first parameter transmitted by the skip method name from the third analysis component as a first skip component name;
and triggering a jump test case template, the third component name, the target display file and the first jump component name according to a preset click event to generate the first jump test case corresponding to the third analysis component.
Further, after the step of determining whether the name of the jump method exists in the fourth code block, the method further includes:
if not, acquiring code blocks except the fourth code block from the third analysis component as a fifth code block;
acquiring a method name for referring to the name of the jump method from the fifth code block as a target method name;
according to the fifth code block, calling link data for the target method name generation method;
acquiring a first parameter transmitted by the jump method name from the third analysis component as a second jump component name;
and generating the second jump test case corresponding to the third analysis component according to a preset indirect trigger jump test case template, the third component name, the method call link data and the second jump component name.
Further, after the step of generating the test case set corresponding to the front-end item code file package according to each of the first initialization test case, each of the second initialization test case, each of the first jump test case, and each of the second jump test case, the method includes:
acquiring a historical case set corresponding to the front-end project code file package;
according to the historical case set, acquiring different test cases from the test case set to serve as the latest case;
and marking the test cases corresponding to the latest case in the test case set by adopting a preset label.
The application also provides a test case generation device suitable for the front-end project, the device includes:
the data acquisition module is used for acquiring a front-end project code file package and carrying out Hooks component identification on the front-end project code file package;
the first initialization test case determining module is used for generating a test case of an interface request in the component initialization process for each Hooks component to obtain a first initialization test case;
the second initialization test case determining module is used for generating a test case triggered by the embedded point in the component initialization process for each Hooks component by adopting a preset embedded point method keyword set to obtain a second initialization test case;
the first skip test case determining module is used for generating a skip test case triggered by a click event for each Hooks component to obtain a first skip test case;
the second jump test case determining module is used for generating a jump test case which is indirectly triggered for each Hooks component to obtain a second jump test case;
and the test case set determining module is used for generating a test case set corresponding to the front-end project code file package according to each first initialization test case, each second initialization test case, each first jump test case and each second jump test case.
The present application also proposes a computer device comprising a memory storing a computer program and a processor implementing any of the methods described above when executing the computer program.
The present application also proposes a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the method of any of the above.
The method, the device, the equipment and the medium are suitable for generating the test case of the front-end project, wherein the method obtains a front-end project code file package and carries out Hooks component identification on the front-end project code file package; generating a test case of an interface request in the component initialization process for each Hooks component to obtain a first initialization test case; generating a testing case triggered by the embedded point in the component initialization process for each Hooks component by adopting a preset embedded point method keyword set to obtain a second initialization testing case; generating a jumping test case triggered by a clicking event for each Hooks component to obtain a first jumping test case; generating a test case of indirect-triggered jump for each Hooks component to obtain a second jump test case; and generating a test case set corresponding to the front-end project code file package according to the first initialization test cases, the second initialization test cases, the first jump test cases and the second jump test cases. The identification of the Hooks components and the compiling of the test case of each Hooks component are realized automatically, the compiling efficiency is improved, and the labor cost is reduced; the test cases of the interface requests in the component initialization process, the test cases triggered by the buried points in the initialization process, the jump test cases triggered by the click events and the jump test cases triggered indirectly are automatically compiled for each Hooks component, so that the coverage of the test cases is improved, and the standardization of the test cases is improved by adopting uniform compiling specifications.
Drawings
Fig. 1 is a schematic flowchart of a test case generation method applied to a front-end project according to an embodiment of the present application;
fig. 2 is a schematic flowchart of a Hooks component identification of a test case generation method applicable to a front-end project according to an embodiment of the present application;
fig. 3 is a schematic flowchart illustrating a first initialization test case determination process of a test case generation method for front-end projects according to an embodiment of the present application;
fig. 4 is a schematic flowchart illustrating a second initialization test case determination process of the test case generation method for front-end projects according to an embodiment of the present application;
fig. 5 is a schematic flowchart of determining a first skip test case of the test case generation method for front-end projects according to an embodiment of the present application;
fig. 6 is a schematic flowchart of determining a second skip test case in the test case generation method for front-end projects according to an embodiment of the present application;
fig. 7 is a schematic flowchart of determining a test case set for a test case generation method applied to a front-end project according to an embodiment of the present application;
FIG. 8 is a block diagram illustrating an exemplary structure of a test case generating apparatus for front-end projects according to an embodiment of the present disclosure;
fig. 9 is a block diagram illustrating a structure of a computer device according to an embodiment of the present application.
The implementation, functional features and advantages of the object of the present application will be further explained with reference to the embodiments, and with reference to the accompanying drawings.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
Referring to fig. 1, an embodiment of the present application provides a method for generating test cases suitable for front-end projects, where the method includes the following steps S1-S6:
s1: acquiring a front-end project code file package, and carrying out Hooks component identification on the front-end project code file package;
s2: generating a test case of an interface request in the component initialization process for each Hooks component to obtain a first initialization test case;
s3: generating a testing case triggered by the embedded point in the component initialization process for each Hooks component by adopting a preset embedded point method keyword set to obtain a second initialization testing case;
s4: generating a jumping test case triggered by a click event for each Hooks component to obtain a first jumping test case;
s5: generating a test case of indirect-triggered jump for each Hooks component to obtain a second jump test case;
s6: and generating a test case set corresponding to the front-end project code file package according to the first initialization test cases, the second initialization test cases, the first jump test cases and the second jump test cases.
According to the embodiment, the identification of the Hooks components and the compiling of the test case of each Hooks component are realized automatically, the compiling efficiency is improved, and the labor cost is reduced; the test cases of the interface requests in the component initialization process, the test cases triggered by the buried points in the initialization process, the jump test cases triggered by the click events and the jump test cases triggered indirectly are automatically compiled for each Hooks component, so that the coverage of the test cases is improved, and the standardization of the test cases is improved by adopting uniform compiling specifications.
The method comprises the steps of adopting JavaScript, realizing the application as a toolkit, and then adding the toolkit into a front-end development framework project. And then configuring development code address configuration data and a buried point method keyword set in a configuration file of the front-end development framework project. The development code address configuration data is the address of the folder where the front-end code in the front-end development framework project is located. The set of the key words of the buried point method is a set comprising one or more key words of the buried point method. The buried point method key words are used for identifying codes triggered and executed by the buried points.
JavaScript (JS), is a lightweight, interpreted, or just-in-time programming language with function precedence.
For example, the profile is expressed as: js.
Optionally, the front-end development framework project adopts reach. The fact, which is a JavaScript library for constructing a user interface, originated from an internal project of Facebook, is unsatisfactory to all JavaScript MVC frames in the market, and decides to develop a set of websites for erecting instagrams by self.
For S1, each front-end project code file in the folder in which the front-end project code resides may be obtained from the front-end development framework project to form a front-end project code portfolio.
It can be understood that the front-end project code file package of the present application is a collection of files of code written in the Hooks component notation.
Hooks, a new feature of React V16.8, can use state and other React features without using class components.
And identifying the Hooks component from each front-end project code file in the front-end project code file package. That is, the Hooks component is the front-end project code file.
For S2, during the page initialization process, there are two steps that are commonly performed: a step of requesting an interface to acquire dynamic data required by initialization and a step of triggering a buried point. The step S2 is adopted for writing the test case of the step of requesting the interface to acquire the dynamic data required for initialization, and the step S3 is adopted for writing the test case of the step of triggering the buried point.
And generating a test case of the interface request in the component initialization process for each Hooks component according to a preset interface request test case template, and taking each generated test case as a first initialization test case.
For S3, a preset embedded point method keyword set and a preset embedded point triggering test case template are adopted, a test case triggered by the embedded point in the component initialization process is generated for each Hooks component, and each generated test case is used as a second initialization test case.
And S4, triggering a jump test case template by adopting a preset click event, generating a jump test case triggered by the click event for each Hooks component, and taking each generated test case as a first jump test case.
And S5, generating indirectly triggered jumping test cases for each Hooks component by adopting a preset indirectly triggered jumping test case template, and taking each generated test case as a second jumping test case.
For S6, the first initialization test cases, the second initialization test cases, the first jump test cases, and the second jump test cases are collected, and a set obtained by the collection is used as a test case set corresponding to the front-end project code file package.
Referring to fig. 2, in an embodiment, the step of obtaining the front-end project code file package and performing the Hooks component identification on the front-end project code file package includes the following steps S11-S16:
s11: acquiring development code address configuration data;
s12: acquiring the front-end project code file package from a storage space corresponding to the development code address configuration data;
s13: taking any one front-end project code file in the front-end project code file package as a code file to be analyzed;
s14: judging whether the code file to be analyzed contains a preset first method keyword, wherein the first method keyword is a method keyword for declaring and using a variable;
s15: if yes, judging whether the code file to be analyzed contains a preset second method keyword, wherein the second method keyword is a method keyword simulating a life cycle method;
s16: and if so, determining the code file to be analyzed as the Hooks component.
In the embodiment, whether the front-end project code file in the front-end project code file package is the Hooks component is judged by declaring and using the method keyword of the variable and the method keyword of the life cycle simulation method, so that a basis is provided for automatic generation of the test case based on the Hooks component.
For S11, the development code address configuration data is obtained from the configuration file of the front-end development framework project.
For step S12, front-end project code files are acquired from the storage space corresponding to the development code address configuration data, and each acquired front-end project code file is taken as the front-end project code file package.
For S14, optionally, the first method keyword is expressed as usestat.
And searching character strings in the code file to be analyzed by adopting first method keywords, determining that the code file to be analyzed contains preset first method keywords if the character strings are searched, and determining that the code file to be analyzed does not contain the preset first method keywords if the character strings are not searched.
For S15, optionally, the second method keyword is expressed as useEffect.
If so, that is, the code file to be analyzed contains a preset first method keyword, then a second method keyword is adopted to search a character string in the code file to be analyzed, if the character string is searched, the code file to be analyzed is determined to contain the preset second method keyword, and if the character string is not searched, the code file to be analyzed is determined not to contain the preset second method keyword.
For S16, if yes, that is, the to-be-analyzed code file includes a preset first method keyword and a preset second method keyword, determining that the to-be-analyzed code file is the Hooks component.
Referring to fig. 3, in an embodiment, the step of generating a test case of an interface request in the component initialization process for each of the Hooks components to obtain a first initialization test case includes the following steps S21-S213:
s21: taking any one of the Hooks components as a first analysis component;
s22: intercepting a component name from the complete file name of the first analysis component as a first component name;
s23: acquiring a method code block corresponding to a preset second method keyword from the first analysis component as a first code block;
s24: searching whether a preset request initiating method keyword exists in a first incoming parameter of the first code block;
s25: if yes, determining a target request mode according to a first keyword behind the keyword of the request initiating method in the first code block;
s26: acquiring a method code block corresponding to the keyword for initiating the request method from the first analysis component as a request method code block;
s27: determining a target request interface address according to a first incoming parameter of the request method code block;
s28: determining target request participation according to a second incoming parameter of the request method code block;
s29: determining a target request callback function according to a third incoming parameter of the request method code block;
s210: taking codes except the request method code block in the first analysis component as codes to be processed;
s211: judging whether the callback field name in the target request callback function exists in the code to be processed or not;
s212: if so, taking each callback field name in the code to be processed as a necessary callback field name set;
s213: and generating the first initialization test case corresponding to the first analysis component according to a preset interface request test case template, the first component name, the target request mode, the target request interface address, the target request entry parameter and the necessary callback field name set.
In this embodiment, each parameter required by the interface request test case template is acquired from the first analysis component, then the acquired parameter is added to the interface request test case template, the interface request test case template to which the parameter is added is used as the first initialization test case corresponding to the first analysis component, and a test case of the interface request in the component initialization process is generated for each Hooks component, so that the coverage of the test case of the interface request in the component initialization process is improved, and the standardization of the test case is improved by adopting a uniform writing specification.
For S22, a component name is intercepted from the full file name of the first analysis component, and the intercepted component name is taken as the first component name.
For example, the full file name of the first analysis component is component a.js, and the first component name is component a.
For S23, since the initialization operation of the Hooks component is performed in the simulation lifecycle method (i.e., the useEffect method), a method code block corresponding to the preset second method keyword is obtained from the first analysis component, and the obtained method code block is used as the first code block.
For S24, when the simulation lifecycle method executes, the first incoming parameter of the method is an anonymously executing function within which it can look up whether there is a method key that originated the request. Thus, it is looked up in the first incoming parameter of the first code block whether there is a preset originating request method key.
Optionally, the method keyword for initiating the request is expressed as axios.
The first incoming parameter, i.e. the first parameter that the method is incoming to.
For S25, if yes, that is, a preset initiation request method key exists in the first incoming parameter of the first code block, it means that there is an action of sending an interface request during initialization, and therefore, the first key after the initiation request method key in the first code block is taken as a target request mode.
Get is included in the first code block, and if the first key after the key (i.e., axios) of the request initiating method is get, the target request mode is get.
For S26, a method code block corresponding to the method-of-request-initiating key is obtained from the first analysis component, and the obtained method code block is used as a method-of-request code block.
For S27, the value of the first incoming parameter of the request method code block is taken as the target request interface address.
For S28, the value of the second incoming parameter of the code block is entered as a target request according to the request method.
For S29, the value of the third incoming parameter of the request method code block is taken as the target request callback function.
For S210, since many field values are returned in the target request callback function, but not all field names are used by the first analysis component, it is necessary to determine which fields in the target request callback function are used by the first analysis component, and therefore, codes other than the request method code block in the first analysis component are used as codes to be processed.
For S211, performing a string search on each callback field name in the target request callback function in the code to be processed, and using each callback field name successfully searched as a necessary callback field name.
For S212, if the callback field name in the target request callback function exists in the to-be-processed code, each callback field name existing in the to-be-processed code is used as a necessary callback field name, and each necessary callback field name is used as a necessary callback field name set.
And S213, according to an interface request test case template, performing test case splicing on the first component name, the target request mode, the target request interface address, the target request entry and the necessary callback field name set, and taking the spliced test case as the first initialization test case corresponding to the first analysis component.
The format of the interface request test case template is as follows: the first component name +' is initialized in a process of "+" making an interface request to "+ the target request interface address +" in a "+ the target request mode +", and the entry parameter of the "+" request is "+ the target request entry parameter +" requiring the interface to normally return the following parameters: "+ the necessary callback field name set.
Referring to fig. 4, in an embodiment, the step of obtaining a second initialization test case by using the preset buried point method keyword set and generating the test case triggered by the buried point in the component initialization process for each Hooks component includes the following steps S31 to S38:
s31: taking any one of the Hooks components as a second analysis component;
s32: intercepting a component name from the complete file name of the second analysis component as a second component name;
s33: acquiring a method code block corresponding to a preset second method keyword from the second analysis component as a second code block;
s34: judging whether the embedded point method keywords in the embedded point method keyword set exist in the second code block;
s35: if yes, taking each buried point method keyword in the second code block as a hit method keyword;
s36: taking a method code block corresponding to the hit method keyword in the second code block as a hit buried point code block;
s37: taking a first parameter in the hit buried point code block as a buried point identifier;
s38: and generating the second initialization test case corresponding to the second analysis component according to a preset buried point triggering test case template, the second component name and each buried point identifier.
In this embodiment, each parameter required by the buried point triggering test case template is acquired from the second analysis component, then the acquired parameter is added to the buried point triggering test case template, the buried point triggering test case template to which the parameter is added is used as the second initialization test case corresponding to the second analysis component, and a buried point triggering test case in the component initialization process is generated for each Hooks component, so that the coverage of the buried point triggering test case in the component initialization process is improved, and the standardization of the test case is improved by adopting a uniform writing specification.
For S32, a component name is intercepted from the full file name of the second analysis component, and the intercepted component name is taken as the second component name.
In S33, since the initialization operation of the Hooks component is performed in the simulation lifecycle method, a method code block corresponding to a preset second method keyword is acquired from the second analysis component, and the acquired method code block is used as the second code block.
For step S34, the buried point method keyword set is obtained from the configuration file of the front-end development framework project, and then the buried point method keywords in the buried point method keyword set are used to search in the second code block.
For S35, if yes, that is, there are buried method keys in the set of buried method keys found in the second code block, then each of the buried method keys in the second code block is taken as a hit method key. That is, the number of hit method keys may be 0, 1, or a plurality of hits.
For S36, the method code block in the second code block corresponding to the hit method key is taken as a hit buried point code block.
For S37, the first parameter in the hit buried code block means buried point coding, and therefore, the first parameter in the hit buried code block is identified as a buried point.
And S38, according to the buried point triggering test case template, carrying out test case splicing on the second component name and each buried point identifier, and taking the spliced test case as the second initialization test case corresponding to the second analysis component.
The format of the buried point trigger test case template is as follows: and the second component name + 'executes a buried point operation in the initialization process, wherein' + 'id is' + each buried point identifier.
Referring to fig. 5, in an embodiment, the step of generating a test case of a click event-triggered jump for each of the Hooks components to obtain a first jump test case includes the following steps S41-S49:
s41: taking any one of the Hooks components as a third analysis component;
s42: intercepting a component name from the complete file name of the third analysis component to be used as a third component name;
s43: acquiring a function instantiation code block corresponding to a preset hook function keyword from the third analysis component as a third code block;
s44: acquiring a method name corresponding to a preset component skipping method keyword from the third code block as a skipping method name;
s45: if the name of the skip method is obtained, obtaining a method code block corresponding to a preset return keyword from the third analysis component as a fourth code block;
s46: judging whether the fourth code block has the name of the skip method;
s47: if so, acquiring a display case corresponding to the skipping method name from the third analysis component as a target display case;
s48: acquiring a first parameter transmitted by the skip method name from the third analysis component as a first skip component name;
s49: and triggering a jump test case template, the third component name, the target display file and the first jump component name according to a preset click event to generate the first jump test case corresponding to the third analysis component.
In this embodiment, each parameter required by the click event trigger skip test case template is acquired from the third analysis component, the acquired parameter is added to the click event trigger skip test case template, the click event trigger skip test case template to which the parameter is added is used as the first skip test case corresponding to the third analysis component, a skip test case triggered by the click event is generated for each Hooks component, the coverage of the skip test case triggered by the click event is improved, and a uniform compiling specification is adopted, so that the standardization of the test case is improved.
For S42, a component name is intercepted from the full file name of the third analytic component, and the intercepted component name is taken as the third component name.
For S43, since the page jumps are all performed by routing, and in the Hooks component, the routing jumps are implemented by hook functions, a function instantiation code block corresponding to a preset hook function keyword is obtained from the third analysis component, and the obtained function instantiation code block is used as a third generation code block.
That is, the third code block is code instantiated by a function (i.e., a hook function) to which the hook function key corresponds.
Optionally, the hook function keyword is expressed as useHistory.
For S44, the component jump method keyword is expressed as route.
And finding out a method for jumping by using the component jumping method keyword from the third generation code block, wherein the method name of the found method is used as a jumping method name. It can be understood that the name of the jump method may not be obtained, one jump method name may be obtained, or a plurality of jump method names may be obtained.
For S45, if the obtained skip method name indicates that there is a method for skipping using the component skip method keyword in the third code block, the method code block corresponding to the preset return keyword is obtained from the third analysis component, and the obtained method code block is used as the fourth code block.
And returning the method code block corresponding to the key, namely returning the code block behind the key.
Optionally, the returned keyword is expressed as return.
For S47, if yes, that is, the fourth code block has the jump method name, so that the third analysis component obtains the display case corresponding to the jump method name, and uses the obtained display case as the target display case.
Wherein the click event is bound within a tag in the presentation.
For S48, from the third analysis component, a first parameter that the jump method name comes in is acquired, and a value of the acquired parameter is taken as a first jump component name.
And S49, triggering a jump test case template according to a click event, splicing the test cases of the third component name, the target display file and the first jump component name, and taking the spliced test case as the first jump test case corresponding to the third analysis component.
The format of the click event triggered jump test case template is as follows: the third component name + "will jump to" + the first jump component name + "corresponding component by clicking" + the target presentation document + ".
Referring to fig. 6, in an embodiment, after the step of determining whether the jump method name exists in the fourth code block, the following steps S51-S55 are further included:
s51: if not, acquiring code blocks except the fourth code block from the third analysis component as a fifth code block;
s52: acquiring a method name for referring to the name of the jump method from the fifth code block as a target method name;
s53: according to the fifth code block, calling link data for the target method name generation method;
s54: acquiring a first parameter transmitted by the skip method name from the third analysis component as a second skip component name;
s55: and generating the second jump test case corresponding to the third analysis component according to a preset indirect trigger jump test case template, the third component name, the method call link data and the second jump component name.
In this embodiment, when the jump method name does not exist in the fourth code block, each parameter required by the indirect trigger jump test case template is acquired from the third analysis component, then the acquired parameter is added to the indirect trigger jump test case template, the indirect trigger jump test case template to which the parameter is added is used as the second jump test case corresponding to the third analysis component, and an indirect trigger jump test case is generated for each Hooks component, so that the coverage of the indirectly trigger jump test cases is improved, and a uniform writing specification is adopted, so that the normalization of the test cases is improved.
For S51, if no, that is, if there is the jump method name in the fourth code block, it means that a click event is not used to trigger a jump, so that the code blocks other than the fourth code block are obtained from the third analysis component, and the obtained code block is used as a fifth code block.
For S52, a method name referencing the jump method name is acquired from the fifth code block, and the acquired method name is taken as a target method name.
For S53, a method name that directly or indirectly refers to the method corresponding to the target method name is obtained from the fifth code block, and method call link data is generated for each obtained method name according to the reference relationship of the method.
For step S54, a first parameter, which is introduced by the name of the jumping method, is obtained from the third analysis component, and a value of the parameter is used as a name of a second jumping component;
and S55, according to the indirect trigger jump test case template, splicing the third component name, the method call link data and the second jump component name, and taking the spliced test case as the second jump test case corresponding to the third analysis component.
The format of the indirect trigger jump test case template is as follows: the third component name +' will jump to "+ the second jumped component name +" corresponding component "by" + the method call link data + ".
Referring to fig. 7, in an embodiment, after the step of generating the test case set corresponding to the front-end item code file package according to each of the first initialization test cases, each of the second initialization test cases, each of the first jump test cases, and each of the second jump test cases, the method includes the following steps S61-S63:
s61: acquiring a historical case set corresponding to the front-end project code file package;
s62: according to the historical case set, obtaining different test cases from the test case set as the latest case;
s63: and marking the test cases corresponding to the latest case in the test case set by adopting a preset label.
In the embodiment, the historical case set is compared with the test case set generated this time, the newly added or changed test cases in the test case set are found out, and then the marking processing is carried out on the found test cases in the test case set, so that a tester can quickly determine the change of the test cases.
For S61, the historical case set corresponding to the front-end project code file package may be obtained from a database;
and the historical case set is a set of historically generated test cases of the front-end items corresponding to the front-end item code file package.
For S62, according to the historical case set, each different test case is obtained from the test case set, and the found test case is taken as the latest case.
And S63, marking the test cases corresponding to the latest case in the test case set by adopting a preset label, thereby marking the newly added or changed test cases in the test case set.
Referring to fig. 8, the present application further proposes a test case generation apparatus suitable for front-end projects, the apparatus including:
the data acquisition module 100 is configured to acquire a front-end project code file package and perform Hooks component identification on the front-end project code file package;
a first initialization test case determining module 200, configured to generate a test case of an interface request in the component initialization process for each Hooks component, to obtain a first initialization test case;
a second initialization test case determining module 300, configured to generate, for each Hooks component, a test case triggered by a buried point in a component initialization process by using a preset buried point method keyword set, so as to obtain a second initialization test case;
a first skip test case determining module 400, configured to generate a skip test case triggered by a click event for each Hooks component to obtain a first skip test case;
a second jump test case determining module 500, configured to generate a jump test case that is indirectly triggered for each Hooks component, so as to obtain a second jump test case;
a test case set determining module 600, configured to generate a test case set corresponding to the front-end item code file package according to each of the first initialization test cases, each of the second initialization test cases, each of the first jump test cases, and each of the second jump test cases.
According to the embodiment, the identification of the Hooks components and the compiling of the test case of each Hooks component are realized automatically, the compiling efficiency is improved, and the labor cost is reduced; the test cases of the interface requests in the component initialization process, the test cases triggered by the buried points in the initialization process, the jump test cases triggered by the click events and the jump test cases triggered indirectly are automatically compiled for each Hooks component, so that the coverage of the test cases is improved, and the standardization of the test cases is improved by adopting uniform compiling specifications.
Referring to fig. 9, a computer device, which may be a server and whose internal structure may be as shown in fig. 9, is also provided in the embodiment of the present application. The computer device includes a processor, a memory, a network interface, and a database connected by a system bus. Wherein the computer designed processor is used to provide computational and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer equipment is used for storing data such as a test case generation method suitable for a front-end project. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement a test case generation method suitable for a front-end project. The test case generation method suitable for the front-end project comprises the following steps: acquiring a front-end project code file package, and carrying out Hooks component identification on the front-end project code file package; generating a test case of an interface request in the component initialization process for each Hooks component to obtain a first initialization test case; generating a testing case triggered by the embedded point in the component initialization process for each Hooks component by adopting a preset embedded point method keyword set to obtain a second initialization testing case; generating a jumping test case triggered by a click event for each Hooks component to obtain a first jumping test case; generating a test case of indirect-triggered jump for each Hooks component to obtain a second jump test case; and generating a test case set corresponding to the front-end project code file package according to the first initialization test cases, the second initialization test cases, the first jump test cases and the second jump test cases.
According to the embodiment, the identification of the Hooks components and the compiling of the test case of each Hooks component are realized automatically, the compiling efficiency is improved, and the labor cost is reduced; the test cases of the interface requests in the component initialization process, the test cases triggered by the buried points in the initialization process, the jump test cases triggered by the click events and the jump test cases triggered indirectly are automatically compiled for each Hooks component, so that the coverage of the test cases is improved, and the standardization of the test cases is improved by adopting uniform compiling specifications.
An embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the computer program implements a method for generating test cases suitable for front-end projects, including the steps of: acquiring a front-end project code file package, and carrying out Hooks component identification on the front-end project code file package; generating a test case of an interface request in the component initialization process for each Hooks component to obtain a first initialization test case; generating a testing case triggered by the embedded point in the component initialization process for each Hooks component by adopting a preset embedded point method keyword set to obtain a second initialization testing case; generating a jumping test case triggered by a click event for each Hooks component to obtain a first jumping test case; generating a test case of indirect-triggered jump for each Hooks component to obtain a second jump test case; and generating a test case set corresponding to the front-end project code file package according to the first initialization test cases, the second initialization test cases, the first jump test cases and the second jump test cases.
According to the executed test case generation method suitable for the front-end project, the identification of the Hooks components and the compiling of the test case of each Hooks component are realized automatically, the compiling efficiency is improved, and the labor cost is reduced; the test cases of the interface requests in the component initialization process, the test cases triggered by the buried points in the initialization process, the jump test cases triggered by the click events and the jump test cases triggered indirectly are automatically compiled for each Hooks component, so that the coverage of the test cases is improved, and the standardization of the test cases is improved by adopting uniform compiling specifications.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium provided herein and used in the examples may include non-volatile and/or volatile memory. Non-volatile memory can include read-only memory (ROM), Programmable ROM (PROM), Electrically Programmable ROM (EPROM), Electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), double-rate SDRAM (SSRSDRAM), Enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and bus dynamic RAM (RDRAM).
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, apparatus, article, or method 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, apparatus, article, or method. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, apparatus, article, or method that includes the element.
The above description is only a preferred embodiment of the present application, and not intended to limit the scope of the present application, and all modifications of equivalent structures and equivalent processes, which are made by the contents of the specification and the drawings of the present application, or which are directly or indirectly applied to other related technical fields, are also included in the scope of the present application.

Claims (10)

1. A test case generation method suitable for a front-end project is characterized by comprising the following steps:
acquiring a front-end project code file package, and carrying out Hooks component identification on the front-end project code file package;
generating a test case of an interface request in the component initialization process for each Hooks component to obtain a first initialization test case;
generating a testing case triggered by the embedded point in the component initialization process for each Hooks component by adopting a preset embedded point method keyword set to obtain a second initialization testing case;
generating a jumping test case triggered by a click event for each Hooks component to obtain a first jumping test case;
generating a test case of indirect-triggered jump for each Hooks component to obtain a second jump test case;
and generating a test case set corresponding to the front-end project code file package according to the first initialization test cases, the second initialization test cases, the first jump test cases and the second jump test cases.
2. The method of claim 1, wherein the step of obtaining a front-end project code file package and performing Hooks component recognition on the front-end project code file package comprises:
acquiring development code address configuration data;
acquiring the front-end project code file package from a storage space corresponding to the development code address configuration data;
taking any one front-end project code file in the front-end project code file package as a code file to be analyzed;
judging whether the code file to be analyzed contains a preset first method keyword, wherein the first method keyword is a method keyword for declaring and using a variable;
if yes, judging whether the code file to be analyzed contains a preset second method keyword, wherein the second method keyword is a method keyword simulating a life cycle method;
and if so, determining the code file to be analyzed as the Hooks component.
3. The method as claimed in claim 1, wherein the step of generating the test case for the interface request in the component initialization process for each Hooks component to obtain the first initialization test case includes:
taking any one of the Hooks components as a first analysis component;
intercepting a component name from the complete file name of the first analysis component as a first component name;
acquiring a method code block corresponding to a preset second method keyword from the first analysis component as a first code block;
searching whether a preset request initiating method keyword exists in a first incoming parameter of the first code block;
if yes, determining a target request mode according to a first keyword behind the keyword of the request initiating method in the first code block;
acquiring a method code block corresponding to the keyword for initiating the request method from the first analysis component as a request method code block;
determining a target request interface address according to a first incoming parameter of the request method code block;
determining target request participation according to a second incoming parameter of the request method code block;
determining a target request callback function according to a third incoming parameter of the request method code block;
taking codes except the request method code block in the first analysis component as codes to be processed;
judging whether the callback field name in the target request callback function exists in the code to be processed or not;
if so, taking each callback field name in the code to be processed as a necessary callback field name set;
and generating the first initialization test case corresponding to the first analysis component according to a preset interface request test case template, the first component name, the target request mode, the target request interface address, the target request entry parameter and the necessary callback field name set.
4. The method for generating test cases suitable for front-end projects of claim 1, wherein the step of obtaining a second initialization test case for each test case triggered by a buried point in the initialization process of the Hooks component generation component by using a preset buried point method keyword set includes:
taking any one of the Hooks components as a second analysis component;
intercepting a component name from the complete file name of the second analysis component as a second component name;
acquiring a method code block corresponding to a preset second method keyword from the second analysis component as a second code block;
judging whether the embedded point method keywords in the embedded point method keyword set exist in the second code block;
if yes, taking each buried point method keyword in the second code block as a hit method keyword;
taking a method code block corresponding to the hit method keyword in the second code block as a hit buried point code block;
taking a first parameter in the hit buried point code block as a buried point identifier;
and generating the second initialization test case corresponding to the second analysis component according to a preset buried point triggering test case template, the second component name and each buried point identifier.
5. The method as claimed in claim 1, wherein the step of generating a test case for each Hooks component, where the test case is a jump triggered by a click event, to obtain a first jump test case includes:
taking any one of the Hooks components as a third analysis component;
intercepting a component name from the complete file name of the third analysis component to be used as a third component name;
acquiring a function instantiation code block corresponding to a preset hook function keyword from the third analysis component as a third code block;
acquiring a method name corresponding to a preset component skipping method keyword from the third code block as a skipping method name;
if the skip method name is obtained, obtaining a method code block corresponding to a preset return keyword from the third analysis component as a fourth code block;
judging whether the fourth code block has the name of the skip method;
if so, acquiring a display case corresponding to the skipping method name from the third analysis component as a target display case;
acquiring a first parameter transmitted by the skip method name from the third analysis component as a first skip component name;
and triggering a jump test case template, the third component name, the target display file and the first jump component name according to a preset click event to generate the first jump test case corresponding to the third analysis component.
6. The method as claimed in claim 5, wherein after the step of determining whether the jump method name exists in the fourth code block, the method further comprises:
if not, acquiring code blocks except the fourth code block from the third analysis component as a fifth code block;
acquiring a method name for referring to the jump method name from the fifth code block as a target method name;
according to the fifth code block, calling link data for the target method name generation method;
acquiring a first parameter transmitted by the skip method name from the third analysis component as a second skip component name;
and generating the second jump test case corresponding to the third analysis component according to a preset indirect trigger jump test case template, the third component name, the method call link data and the second jump component name.
7. The method for generating test cases suitable for front-end projects according to claim 1, wherein after the step of generating the test case set corresponding to the front-end project code file package according to each of the first initialization test cases, each of the second initialization test cases, each of the first jump test cases, and each of the second jump test cases, the method comprises:
acquiring a historical case set corresponding to the front-end project code file package;
according to the historical case set, acquiring different test cases from the test case set to serve as the latest case;
and marking the test cases corresponding to the latest case in the test case set by adopting a preset label.
8. A test case generation apparatus for a front-end project, the apparatus comprising:
the data acquisition module is used for acquiring a front-end project code file package and carrying out Hooks component identification on the front-end project code file package;
the first initialization test case determining module is used for generating a test case of an interface request in the component initialization process for each Hooks component to obtain a first initialization test case;
the second initialization test case determining module is used for generating a test case triggered by the embedded point in the component initialization process for each Hooks component by adopting a preset embedded point method keyword set to obtain a second initialization test case;
the first skip test case determining module is used for generating a skip test case triggered by a click event for each Hooks component to obtain a first skip test case;
the second jump test case determining module is used for generating a jump test case which is indirectly triggered for each Hooks component to obtain a second jump test case;
and the test case set determining module is used for generating a test case set corresponding to the front-end project code file package according to each first initialization test case, each second initialization test case, each first jump test case and each second jump test case.
9. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor implements the method of any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the method of any one of claims 1 to 7.
CN202210285461.2A 2022-03-22 2022-03-22 Test case generation method, device, equipment and medium suitable for front-end project Pending CN114610637A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210285461.2A CN114610637A (en) 2022-03-22 2022-03-22 Test case generation method, device, equipment and medium suitable for front-end project

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210285461.2A CN114610637A (en) 2022-03-22 2022-03-22 Test case generation method, device, equipment and medium suitable for front-end project

Publications (1)

Publication Number Publication Date
CN114610637A true CN114610637A (en) 2022-06-10

Family

ID=81865626

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210285461.2A Pending CN114610637A (en) 2022-03-22 2022-03-22 Test case generation method, device, equipment and medium suitable for front-end project

Country Status (1)

Country Link
CN (1) CN114610637A (en)

Similar Documents

Publication Publication Date Title
CN109918079B (en) Rule updating method and device of rule engine system and computer equipment
CN110708210B (en) Cloud test configuration method and device, computer equipment and storage medium
CN111679965A (en) Automatic testing method and device, computer equipment and storage medium
CN111984228B (en) Interface document processing method and device, computer equipment and storage medium
CN112380130A (en) Application testing method and device based on call dependency relationship
CN109766261B (en) Coverage test method, coverage test device, computer equipment and storage medium
CN113489650B (en) Routing method, device and equipment of client and storage medium
CN113835713A (en) Source code package downloading method and device, computer equipment and storage medium
CN113283620A (en) Operation and maintenance method, device and equipment based on artificial intelligence and storage medium
CN113064584B (en) Idempotent implementation method, device, equipment and medium
Wu et al. CoDocent: Support API usage with code example and API documentation
CN112579459A (en) Method and device for testing application program and computer equipment
CN111158642A (en) Data construction method and device, computer equipment and storage medium
CN113946363A (en) Method and device for executing and configuring service data, computer equipment and storage medium
CN113900962A (en) Code difference detection method and device
CN114610637A (en) Test case generation method, device, equipment and medium suitable for front-end project
CN116860254A (en) Front-end compiling method, device, equipment and storage medium
CN111061637A (en) Interface test method, interface test device and storage medium
CN114610973A (en) Information search matching method and device, computer equipment and storage medium
CN115794214A (en) Application module metadata management method, device, storage medium and device
CN112559671B (en) ES-based text search engine construction method, device, equipment and medium
CN111427770B (en) Resource testing method and related equipment
CN113486267A (en) Analysis method, device and equipment of application entry page and storage medium
CN106775629B (en) Search file generation method and device
CN109284097B (en) Method, device, system and storage medium for realizing complex data analysis

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