CN113204389B - Method, system, equipment and storage medium for generating automatic execution strategy - Google Patents

Method, system, equipment and storage medium for generating automatic execution strategy Download PDF

Info

Publication number
CN113204389B
CN113204389B CN202110591248.XA CN202110591248A CN113204389B CN 113204389 B CN113204389 B CN 113204389B CN 202110591248 A CN202110591248 A CN 202110591248A CN 113204389 B CN113204389 B CN 113204389B
Authority
CN
China
Prior art keywords
list
class
test
string
url
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.)
Active
Application number
CN202110591248.XA
Other languages
Chinese (zh)
Other versions
CN113204389A (en
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.)
Dilu Technology Co Ltd
Original Assignee
Dilu Technology 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 Dilu Technology Co Ltd filed Critical Dilu Technology Co Ltd
Priority to CN202110591248.XA priority Critical patent/CN113204389B/en
Publication of CN113204389A publication Critical patent/CN113204389A/en
Application granted granted Critical
Publication of CN113204389B publication Critical patent/CN113204389B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention discloses a method, a system, equipment and a storage medium for generating an automatic execution strategy, which are characterized in that a command line processing program analyzes the input command line parameters, identifies jar packet files and converts the jar packet files into List < URL >, and initializes the filtering level and the filtering rule; initializing a custom Class loader by using a List < URL >, traversing the List < URL >, analyzing and obtaining the test Class name in the List < URL >, loading the initialized custom Class loader into the JVM, and storing the initialized custom Class loader into Map < String >, wherein the List < Class >; traversing List < Class >, obtaining Test Class, analyzing a Test method with @ Test annotation therein, and storing in Map < String >, list < String >; and analyzing the data to generate the testng.

Description

Method, system, equipment and storage medium for generating automatic execution strategy
Technical Field
The invention relates to a method, a system, equipment and a storage medium for generating an automatic execution strategy, and belongs to the field of automatic execution strategy generation.
Background
In the test items, testNG is selected as the execution framework of the automated test. In addition to full execution, it is often encountered that different automated case execution strategies are formulated for business testing needs. When the case quantity is small, the problem of manually configuring testng.xml is not large; however, under the conditions that the number of automatic cases is increased gradually and the overall planning is not good, manual configuration consumes too long manpower time, reduces the test efficiency and is easy to make mistakes and miss due to human negligence.
Disclosure of Invention
The technical problems to be solved by the invention are as follows: a method, system, device and storage medium for generating an automated execution policy are provided, which utilize Java to write a custom class loader, java reflection technology and a third party toolkit Jdot to develop a command line tool, and finally generate a target testng.
The invention adopts the following technical scheme for solving the technical problems:
a method of generating an automated enforcement policy, comprising the steps of:
step 1, analyzing the input command line parameters through a command line processing program, identifying jar packet files, converting and outputting the jar packet files into List < URL >, and initializing filtering levels and filtering rules;
step 2, initializing a custom Class loader by using a List < URL >, traversing the List < URL >, analyzing and obtaining the test Class name in the List < URL >, loading the test Class name into the JVM by using the initialized custom Class loader, and finally storing the test Class name into a Map < String >, wherein the key is the name of a jar packet, and the value is the test Class List analyzed in the jar packet identified by the URL;
step 3, traversing List < Class >, obtaining Test Class, analyzing a Test method with @ Test annotation therein, storing in Map < String >, wherein List < String > is a Class name, and value is a List of Test method names in the Class;
and 4, analyzing data in the Map < String, list < Class > and Map < String > by using the Map < String, list < Class > and Map < String > generated in the step 2 and the Map < String > generated in the step 3, and generating a testng.
As a preferable scheme of the method, the specific process of the step 2 is as follows:
initializing a TestClassLoader object by using the List < URL > generated in the step 1, analyzing the jar packet file, traversing Class files in sequence, obtaining Class names, calling the TestClassLoader object load method, loading the Class names into the JVM, screening out Class names meeting requirements according to the filtering level and the rule set in the step 1, storing the Class names in the List < Class >, initializing JarInfo by using the jar packet name and the List < Class >, and storing the Class names in the List < JarInfo >.
As a preferable scheme of the method, the specific process of the step 3 is as follows:
traversing each JarInfo object in sequence by using the List < JarInfo > generated in the step 2, then acquiring the List < Class > under the object, traversing the List, initializing a ClassParser object by using an item in the List, acquiring a Test method name with @ Test annotation and a description attribute under the annotation by java reflection, simultaneously verifying whether the set filtering level and rule are met, initializing the Test method object by using a Test method meeting the requirements, and then storing the Test method object in the List < Testmethod > one by one; finally, the value attribute of the class annotation record is acquired and used for initializing the TestClassInfo object together with the generated List < Testmethod >, and the TestClassInfo object is stored in the List < TestClassInfo >.
As a preferable scheme of the method, the specific process of the step 4 is as follows:
traversing the List < JarInfo > generated in the step 2, wherein each JarInfo in the List < JarInfo > correspondingly generates a test element in testng.xml, and the name attribute is the package name; then using the List < TestClassInfo > generated in step 3 to traverse the parsing, each TestClassInfo corresponding to one class element in testng. Finally, a testng.xml file is generated.
A system based on the method for generating the automatic execution strategy, which comprises a Main module, a custom class loader, a class parser and a target file generator;
the Main module is used for analyzing the input command line parameters through the command line processing program, identifying jar packet files, converting and outputting the jar packet files into List < URL >, and initializing the filtering level and the filtering rule;
the custom Class loader is used for initializing the custom Class loader by using a List < URL >, traversing the List < URL >, analyzing and obtaining the test Class name in the custom Class loader, loading the custom Class loader into the JVM by using the initialized custom Class loader, and finally storing the custom Class loader into Map < String >, wherein the key is the name of the jar packet, and the value is the List of the test Class analyzed in the jar packet identified by the URL;
the Class analyzer is used for traversing List < Class >, acquiring Test Class, analyzing a Test method with @ Test annotation therein, storing in Map < String >, wherein List < String > is a Class name, and value is a List of Test method names in the Class;
the object file generator is used for analyzing data in Map < String >, list < Class > > and Map < String >, list < String > > and generating a testng.
A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, the processor implementing the steps of the method of generating an automated execution policy when the computer program is executed.
A computer readable storage medium storing a computer program which, when executed by a processor, implements the steps of the method of generating an automated execution policy.
Compared with the prior art, the technical scheme provided by the invention has the following technical effects:
according to the invention, the custom class loader is written to load the test class in the jar packet, and the relevant test method in the class is analyzed by utilizing reflection, so that the testng.xml file is generated according to the rule. Mainly solves the following two problems: 1. with the gradual increase of the quantity of automatic test cases, the problems of time and labor consumption and low efficiency of manual testng.xml configuration are caused; 2. the problem of omission or configuration errors caused by manual configuration is solved.
Drawings
FIG. 1 is a flow chart of a method of generating an automated execution policy of the present invention.
Detailed Description
Embodiments of the present invention are described in detail below, examples of which are illustrated in the accompanying drawings. The embodiments described below by referring to the drawings are exemplary only for explaining the present invention and are not to be construed as limiting the present invention.
The invention mainly utilizes Java to write a custom class loader, java reflection technology and a third party toolkit Jdom to develop a command line tool, and finally generates a target testng.xml through the tool and related options.
System architecture or scenario:
selecting all or part of test cases to package according to the test strategy requirement, then using the packaged files as input, designating screening levels and rules, and obtaining the test cases meeting relevant requirements through a class loading module and a class analyzing module; if not, acquiring all the test cases; and finally, generating the target file by using a generating module according to the specified mapping rule.
Test case library: automated test scripts that have been written
And (3) packaging tools: eclipse
The parsing engine: is responsible for loading and analyzing classes and filtering out related cases according to filtering rules
Generating a file: generating a target file according to the mapping rule
Specific modules involved in the system or scenario:
main. Java: analyzing command line parameters and entry classes of programs, wherein the key point is that the command line parameters are analyzed, the incoming jar packet files are identified and converted into URL classes, and the URL classes are stored in a List < URL >;
testclassloader.java: the custom Class loader is responsible for traversing and analyzing jar files stored in a main/java module and loading test classes, storing the test classes in Map < String >, using jar packet names as keys and value as List, and storing the analyzed classes in jar packets;
ClassParser.java: a class parser for parsing the method with @ Test annotation in the class, storing in Map < String >, list < String >, using class name as key, value as List, for storing the parsed method name;
testngxml creator.java: and the target file generator is responsible for analyzing data in the Map by using maps generated by the TestClassLoader. Java and ClassParser. Java, and finally generating testng. Xml.
FIG. 1 is a flowchart of a method for generating an automated execution policy, comprising the following steps:
1. firstly, a Main module analyzes the input command line parameters through a command line processing program (or a Main class and an entry class), identifies jar packet files, converts and outputs the jar packet files into a List < URL >, and initializes a filtering level and a filtering rule;
2. firstly, generating a List < URL > in a main-Java module, initializing the TestClassLoader object, then analyzing a jar file (using the URL to initialize the JarFile object, then analyzing the JarFile to obtain a test Class name therein), traversing the Class file in sequence, obtaining the Class name, calling a load method of the TestClassLoader object to load the Class name into the JVM, screening out the Class name meeting the requirements according to the filtering level and the rule, storing the Class name into the List < Class >, finally initializing JarInfo by using the jar packet name and the List < Class >, and storing the Class name into the List < JarInfo >;
3. the ClassParser.java firstly uses List < JarInfo > acquired by a TestClassLoader to sequentially traverse each JarInfo object, acquires List < Class > under the object, traverses the List, initializes the ClassParser object by using a List item, acquires Test method names with @ Test annotation and description attributes under the annotation by java reflection, simultaneously verifies whether set filtering level and rule are met, and is used for initializing the TestMethod object meeting requirements and then stores the TestMethod objects in the List one by one; finally, the value attribute of the class annotation record is obtained and is used for initializing a TestClassInfo object together with the generated List < Testmethod >, and the TestClassInfo object is stored in the List < TestClassInfo >;
4. testngxml creator.java: and analyzing data in the Map by using maps generated by the TestClassLoader. Java and ClassParser. Java, and finally generating testng. Xml. Firstly traversing a List < JarInfo > generated by TestClassLoader.java, wherein each JarInfo of the List < JarInfo > correspondingly generates one test element in testng.xml, and the name attribute is the package name; then using List < TestClassInfo > generated by ClassParser.java, traversing and analyzing, wherein each TestClassInfo corresponds to one class element in testng.xml, then traversing a test method List corresponding to List < Testmethod >, and each TestMethod corresponds to one class element in testng.xml; finally, a testng.xml file is generated.
Firstly, using jar commands or eclipse to make java files related to written test cases into jar packages, and storing the jar packages under folders. Opening cmd, executing command, designating output folder, input can be catalog or jar package; if it is a directory, the-d option designation must be used; after execution, testng. Xml will be generated under the output folder. And then storing the output testng.xml and jar packets under the same folder, and executing the command.
The above embodiments are only for illustrating the technical idea of the present invention, and the protection scope of the present invention is not limited thereto, and any modification made on the basis of the technical scheme according to the technical idea of the present invention falls within the protection scope of the present invention.

Claims (7)

1. A method of generating an automated enforcement policy, comprising the steps of:
step 1, analyzing the input command line parameters through a command line processing program, identifying jar packet files, converting and outputting the jar packet files into List < URL >, and initializing filtering levels and filtering rules;
step 2, initializing a custom Class loader by using a List < URL >, traversing the List < URL >, analyzing and obtaining the test Class name in the List < URL >, loading the test Class name into the JVM by using the initialized custom Class loader, and finally storing the test Class name into a Map < String >, wherein the key is the name of a jar packet, and the value is the test Class List analyzed in the jar packet identified by the URL;
step 3, traversing List < Class >, obtaining Test Class, analyzing a Test method with @ Test annotation therein, storing in Map < String >, wherein List < String > is a Class name, and value is a List of Test method names in the Class;
and 4, analyzing data in the Map < String, list < Class > and Map < String > by using the Map < String, list < Class > and Map < String > generated in the step 2 and the Map < String > generated in the step 3, and generating a testng.
2. The method for generating an automated execution policy according to claim 1, wherein the specific procedure of step 2 is as follows:
initializing a TestClassLoader object by using the List < URL > generated in the step 1, analyzing the jar packet file, traversing Class files in sequence, obtaining Class names, calling the TestClassLoader object load method, loading the Class names into the JVM, screening out Class names meeting requirements according to the filtering level and the rule set in the step 1, storing the Class names in the List < Class >, initializing JarInfo by using the jar packet name and the List < Class >, and storing the Class names in the List < JarInfo >.
3. The method for generating an automated execution policy according to claim 2, wherein the specific procedure of step 3 is as follows:
traversing each JarInfo object in sequence by using the List < JarInfo > generated in the step 2, then acquiring the List < Class > under the object, traversing the List, initializing a ClassParser object by using an item in the List, acquiring a Test method name with @ Test annotation and a description attribute under the annotation by java reflection, simultaneously verifying whether the set filtering level and rule are met, initializing the Test method object by using a Test method meeting the requirements, and then storing the Test method object in the List < Testmethod > one by one; finally, the value attribute of the class annotation record is acquired and used for initializing the TestClassInfo object together with the generated List < Testmethod >, and the TestClassInfo object is stored in the List < TestClassInfo >.
4. A method for generating an automated execution policy according to claim 3, wherein the specific procedure of step 4 is as follows:
traversing the List < JarInfo > generated in the step 2, wherein each JarInfo in the List < JarInfo > correspondingly generates a test element in testng.xml, and the name attribute is the package name; then using the List < TestClassInfo > generated in step 3 to traverse the parsing, each TestClassInfo corresponding to one class element in testng. Finally, a testng.xml file is generated.
5. A system based on the method of generating an automated enforcement policy according to any of claims 1 to 4, wherein the system comprises a Main module, a custom class loader, a class parser and a target file generator;
the Main module is used for analyzing the input command line parameters through the command line processing program, identifying jar packet files, converting and outputting the jar packet files into List < URL >, and initializing the filtering level and the filtering rule;
the custom Class loader is used for initializing the custom Class loader by using a List < URL >, traversing the List < URL >, analyzing and obtaining the test Class name in the custom Class loader, loading the custom Class loader into the JVM by using the initialized custom Class loader, and finally storing the custom Class loader into Map < String >, wherein the key is the name of the jar packet, and the value is the List of the test Class analyzed in the jar packet identified by the URL;
the Class analyzer is used for traversing List < Class >, acquiring Test Class, analyzing a Test method with @ Test annotation therein, storing in Map < String >, wherein List < String > is a Class name, and value is a List of Test method names in the Class;
the object file generator is used for analyzing data in Map < String >, list < Class > > and Map < String >, list < String > > and generating a testng.
6. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the steps of the method of generating an automated execution policy as claimed in any one of claims 1-4.
7. A computer readable storage medium storing a computer program, characterized in that the computer program when executed by a processor implements the steps of the method of generating an automated execution policy according to any of claims 1-4.
CN202110591248.XA 2021-05-28 2021-05-28 Method, system, equipment and storage medium for generating automatic execution strategy Active CN113204389B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110591248.XA CN113204389B (en) 2021-05-28 2021-05-28 Method, system, equipment and storage medium for generating automatic execution strategy

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110591248.XA CN113204389B (en) 2021-05-28 2021-05-28 Method, system, equipment and storage medium for generating automatic execution strategy

Publications (2)

Publication Number Publication Date
CN113204389A CN113204389A (en) 2021-08-03
CN113204389B true CN113204389B (en) 2023-09-22

Family

ID=77023455

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110591248.XA Active CN113204389B (en) 2021-05-28 2021-05-28 Method, system, equipment and storage medium for generating automatic execution strategy

Country Status (1)

Country Link
CN (1) CN113204389B (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2005293084A (en) * 2004-03-31 2005-10-20 Nec Corp Optimization system of java class path
CN107562626A (en) * 2017-08-31 2018-01-09 国家电网公司 A kind of method that encapsulation Selenium and Sikuli realizes Web automatic tests
CN107766255A (en) * 2017-11-16 2018-03-06 郑州云海信息技术有限公司 WebUI automated testing methods based on Cucumber and Testng
CN108763083A (en) * 2018-05-30 2018-11-06 平安普惠企业管理有限公司 Automated testing method, device, computer equipment and storage medium
CN109240926A (en) * 2018-09-06 2019-01-18 郑州云海信息技术有限公司 A kind of software compatibility system safety testing device and method

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
GB2553896B (en) * 2016-07-14 2019-09-25 Accenture Global Solutions Ltd Product test orchestration

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2005293084A (en) * 2004-03-31 2005-10-20 Nec Corp Optimization system of java class path
CN107562626A (en) * 2017-08-31 2018-01-09 国家电网公司 A kind of method that encapsulation Selenium and Sikuli realizes Web automatic tests
CN107766255A (en) * 2017-11-16 2018-03-06 郑州云海信息技术有限公司 WebUI automated testing methods based on Cucumber and Testng
CN108763083A (en) * 2018-05-30 2018-11-06 平安普惠企业管理有限公司 Automated testing method, device, computer equipment and storage medium
CN109240926A (en) * 2018-09-06 2019-01-18 郑州云海信息技术有限公司 A kind of software compatibility system safety testing device and method

Also Published As

Publication number Publication date
CN113204389A (en) 2021-08-03

Similar Documents

Publication Publication Date Title
US7581212B2 (en) Method and system for conversion of automation test scripts into abstract test case representation with persistence
CN100468356C (en) Test case inheritance controlled via attributes
EP2667306B1 (en) Software systems testing interface
US20050188271A1 (en) Method and system for rule-based generation of automation test scripts from abstract test case representation
CN110401634A (en) A kind of web application hole detection regulation engine implementation method and terminal
CN110825385B (en) Method for constructing read Native offline package and storage medium
CN112187713B (en) Message conversion method, device, computer equipment and storage medium
CN110555074B (en) Method, terminal and computer readable storage medium for timing data extraction and processing
US7340725B1 (en) Smart test attributes and test case scenario in object oriented programming environment
CN110377516A (en) Test method, device, electronic equipment and computer readable storage medium
US8898644B2 (en) Efficient unified tracing of kernel and user events with multi-mode stacking
CN110543427A (en) Test case storage method and device, electronic equipment and storage medium
CN116302930A (en) Application testing method and device
CN107608873A (en) Method for testing software and system and test platform
CN103942140A (en) Automatic testing program conversion method
CN112463596B (en) Test case data processing method, device and equipment and processing equipment
CN113204389B (en) Method, system, equipment and storage medium for generating automatic execution strategy
US20060064570A1 (en) Method and apparatus for automatically generating test data for code testing purposes
CN110147313A (en) A kind of log-output method and device
CN116048731A (en) Code processing method, device, electronic equipment and storage medium
US8938647B2 (en) System and method for capturing and using web page views in a test environment
US20060179351A1 (en) Target object for dynamic marshaling testing
US20090172648A1 (en) Byte code analysis library
CN109308256A (en) A kind of java dynamically analyzing of program method, equipment and storage medium
US20220317884A1 (en) Data collector in an electronic device

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
GR01 Patent grant
GR01 Patent grant