CN111625445A - Java-based test framework construction method and device and storage medium - Google Patents

Java-based test framework construction method and device and storage medium Download PDF

Info

Publication number
CN111625445A
CN111625445A CN202010327398.5A CN202010327398A CN111625445A CN 111625445 A CN111625445 A CN 111625445A CN 202010327398 A CN202010327398 A CN 202010327398A CN 111625445 A CN111625445 A CN 111625445A
Authority
CN
China
Prior art keywords
test
level
packet
class
annotation
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
CN202010327398.5A
Other languages
Chinese (zh)
Inventor
艾可德
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An International Smart City Technology Co Ltd
Original Assignee
Ping An International Smart City 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 Ping An International Smart City Technology Co Ltd filed Critical Ping An International Smart City Technology Co Ltd
Priority to CN202010327398.5A priority Critical patent/CN111625445A/en
Publication of CN111625445A publication Critical patent/CN111625445A/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

Abstract

The present invention relates to a block chain technique, the test packets and test sub-packets being stored in a block chain. The test framework construction method based on Java is provided, and comprises the following steps: setting the test case set into a test packet and a test sub-packet with a hierarchical nesting relation; adding abstract method test preparation and test cleaning to a test package, wherein each level under the test package inherits the test preparation and the test cleaning; the test sub-packet inherits the label annotation of the cladding level test case at the upper level, and the test class inherits the label annotation of the cladding level test case at the upper level; the test method inherits the cladding level test case label annotation and the class level test case label annotation at the upper level. The test frame formed by the method can display and inherit information according to levels, so that the information is complete and convenient to maintain.

Description

Java-based test framework construction method and device and storage medium
Technical Field
The invention relates to the technical field of block chain software testing, in particular to a test framework construction method and device based on Java and a storage medium.
Background
Currently, the Java (an object-oriented programming language) test framework is mostly used as TestNG, which is a test framework designed to simplify a wide range of test requirements, from unit testing (which can test one class) to integrated testing (which tests an entire system consisting of multiple classes, multiple packages, and even multiple external frameworks, such as a server). There are typically three typical steps in the process of writing a test: 1. writing tested business logic and inserting testngannotion (note) into the code; 2. adding the test information into a testng.xml file or build.xml; 3. TestNG was run.
However, the TestNG test framework also has some disadvantages, such as:
1. the case label definition system is imperfect, labels cannot be set for the whole hierarchy of the test case set, and the test case set cannot inherit the labels of the test case father set;
2. data-driven test methods all require the provision of a data acquisition method, such as: a data-driven Test method testDemo of TestNG needs to provide a method dataProvider () corresponding to acquired data, and specifies the data by associating dataProvider attributes in @ Test annotation, so that a Test code is bloated;
3. test preparation (setup ()) and nested test cleaning (Teardown ()) cannot be nested in each level of the test case set, and test preparation and test cleaning cannot be added to the test class;
4. the test reports are not presented at the test case set level, nor can the test case set level be expanded or collapsed.
Therefore, there is a need for a test framework building method based on Java reflection and annotation that overcomes the above disadvantages.
Disclosure of Invention
In view of the above problems, it is an object of the present invention to provide a Java-based test framework building method, apparatus and storage medium. The Test framework constructed by the method supports the definition of a Case label (tag) for the whole Test Case set, and the Case label supports the transmission inheritance from a Test package (package) to a Test class (Suite) and then to a Test method (Case), so that the method can be conveniently used for filtering, grouping execution and the like of the Test Case (Test Case). The nested test packages of each level support test preparation (setup ()) and test cleanup (Teardown ()).
According to one aspect of the invention, a Java-based test framework construction method is provided, which comprises the following steps:
s110: setting the test case set into a test packet and a test sub-packet with the level nesting relation according to the level nesting relation of each test case set in the test software; wherein the test packet includes a test sub-packet and/or a test class of its next level, the test sub-packet includes a test sub-packet and/or a test class of its next level, the test class includes a test method;
s120: adding an abstract method to the test packet, wherein the abstract method comprises test preparation and test cleaning, and the test sub-packets and/or test classes of each level under the test packet inherit the test preparation and the test cleaning;
s130: defining packet level test case tag annotations for the test packet and the test sub-packet respectively, defining class level test case tag annotations for the test class, and defining method level test case tag annotations for the test method; the test sub-packet inherits the label annotation of the cladding level test case at the upper level, and the test class inherits the label annotation of the cladding level test case at the upper level; the test method is followed by the layer level test case label annotation and the class level test case label annotation at the upper layer.
Further, the test sub-packets are stored in the block chain, and the execution sequence among the test sub-packets, the execution sequence among the test sub-packets and the test classes, and the execution sequence among the test classes in the same level are configured by the solution configuration value.
In step S120, the test packet is stored in a block chain, and the method includes the following steps: defining base class configuration information of the test package as an InitBase abstract class, and adding the test preparation and the test cleaning at the test package level, wherein a test sub-package under the test package inherits the InitBase abstract class layer by layer so as to inherit the test preparation and the test cleaning, and a test class under the test package inherits the InitBase abstract class at the upper level so as to inherit the test preparation and the test cleaning.
In S130, the method further includes: setting the attribute of the median value of the class level test case tag annotation as a mandatory tag attribute or a default tag attribute; wherein the content of the first and second substances,
if the test method has no tag annotation, the test method inherits the value corresponding to the default tag attribute in the class-level test case tag annotation of the upper level;
if the test method has the tag annotation, the test method does not inherit the value corresponding to the default tag attribute in the class-level test case tag annotation of the upper level;
the test method has or does not have tag annotation, and the test method inherits the value corresponding to the mandatory tag attribute in the class-level test case tag annotation at the upper level.
Further, still include: setting a test case execution engine to traverse the test methods in the test class, acquiring the tag annotation on each test method, and judging whether the tag annotation of the test method contains the set annotation;
if the test method contains the set annotation, executing the test method by an execution engine, otherwise, not executing the test method;
wherein the set annotations include the following attributes: the attribute evaluation method comprises the following steps of describing a test case, an author of the test case, priority of the test case, sequence numbering, forbidding or not, retry times and dependent cases, wherein each attribute has a default value, and if the attribute is not assigned, the default value of the attribute is given;
and acquiring the attribute of the data driving annotation of the executed test method through the execution engine, and determining the source of the test data according to the attribute of the data driving annotation.
The attributes of the data driven annotations include: the attribute of the test data obtained from the variable, the attribute of the test data obtained from the file, and the attribute of the test data obtained from the method.
Further, still include: defining the type of the assertion exception when the test method runs as Assert RuntimeException, and uniformly capturing the assertion exception thrown when the test method is executed at the position set by the test framework.
According to another aspect of the present invention, there is provided a Java-based test framework building system, including:
the test packet level forming unit is used for setting the test case set into a test packet and a test sub-packet with the level nesting relation according to the level nesting relation of each test case set in the test software; wherein the test packet comprises a test sub-packet and/or a test class of its next level, the test sub-packet comprises a test sub-packet and/or a test class of its next level, the test class comprises a test method;
a test preparation and test cleaning inheritance unit, which is used for adding abstract methods to the test packet, wherein the abstract methods comprise test preparation and test cleaning, and the test sub-packets and/or test classes of each level under the test packet inherit the test preparation and the test cleaning;
a test case tag annotation propagation unit, configured to define a cladding-level test case tag annotation for the test packet and the test sub-packet, define a class-level test case tag annotation for the test class, and define a method-level test case tag annotation for the test method; the test sub-packet inherits the label annotation of the cladding-level test case at the upper level, and the test class inherits the label annotation of the cladding-level test case at the upper level; the test method inherits the cladding level test case label annotation and the class level test case label annotation at the upper level.
According to another aspect of the present invention, there is provided an electronic device comprising a memory and a processor, the memory having stored therein a computer program that, when executed by the processor, implements the steps of the above Java based test framework building method.
According to another aspect of the present invention, there is provided a computer readable storage medium, in which a Java based test framework building program is stored, and when the Java based test framework building program is executed by a processor, the steps of the Java based test framework building method are implemented.
By utilizing the test framework construction method based on Java, a test packet structure consistent with the hierarchy of the test case set is defined, the transmission succession of the tag annotation from the upper hierarchy to the test method is supported, the complete information required by the test case is formed, and the test case construction method can be conveniently used for filtering execution and grouping execution of the test case. The abstract method test preparation (setup ()) and the test cleaning (Teardown ()) can be sequentially carried by layers, so that the test cases written by a user can be cleaner and more convenient to maintain. The test report can also be expanded or contracted according to the hierarchy of the test case suite. Three annotation attributes are defined for data driving, so that data can be conveniently acquired from different places, and test codes are reduced.
To the accomplishment of the foregoing and related ends, one or more aspects of the invention comprise the features hereinafter fully described and particularly pointed out in the claims. The following description and the annexed drawings set forth in detail certain illustrative aspects of the invention. These aspects are indicative, however, of but a few of the various ways in which the principles of the invention may be employed. Moreover, the present invention is intended to include all such aspects and their equivalents.
Drawings
Other objects and results of the present invention will become more apparent and more readily appreciated as the same becomes better understood by reference to the following description and appended claims, taken in conjunction with the accompanying drawings. In the drawings:
FIG. 1 is a flowchart of a Java-based test framework building method according to embodiment 1 of the present invention;
FIG. 2 is a schematic diagram of a logical structure of a Java-based test framework building system according to embodiment 2 of the present invention;
fig. 3 is a schematic diagram of a logic structure of an electronic device according to embodiment 3 of the present invention.
Fig. 4 is a diagram of a test case tag annotation inheritance delivery process of the Java-based test framework building method according to embodiment 1 of the present invention.
The same reference numbers in all figures indicate similar or corresponding features or functions.
Detailed Description
In the following description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of one or more embodiments. It may be evident, however, that such embodiment(s) may be practiced without these specific details. In other instances, well-known structures and devices are shown in block diagram form in order to facilitate describing one or more embodiments.
For ease of understanding, some of the concepts involved in the present invention are first explained as follows:
test Case (Test Case): the behavior activity of the software test is scientifically organized and classified, and the purpose is to convert the behavior of the software test into a manageable mode; meanwhile, the test case is also one of methods for specifically quantifying the test, and the test cases are different for different types of software. A test case in a software project is a set of conditions or variables from which a tester determines whether an application software or software system or code logic or algorithmic logic is working correctly. The method of determining whether a software program or system passes a test is called a test criterion.
Test case set: the test cases are a set of test cases, the cases of the set can be a test case set formed for testing a certain function of software or because of having a certain incidence relation, the test case set can also contain a test case subset, and the test case set can have a multi-level nesting relation.
Test class: the test classes in JAVA are used to test functional components that have been written. A test class may contain a plurality of similar or related test methods or be used to collectively test a certain piece of functionality or logic of software.
The test method comprises the following steps: in the java test class, the test method is a class instance method in the framework, and one test method can correspond to one test case or a group of test cases (a data-driven test method corresponds to a group of test cases). Examples are: (1) the test method corresponds to a test case, such as public void test1 (). (2) The test method corresponds to a set of test cases, such as public void testByData () (and associates a test data file, such as by annotating an associated test case file, which is a case data driven method).
Java annotations provide a secure annotation-like mechanism to associate any information or metadata with program elements (classes, methods, member variables, etc.). Elements (classes, methods, member variables) of a program are provided with more intuitive and clear descriptions, and the description information is irrelevant to the business logic of the program and is used by a specified tool or framework. Note that like a modifier, it applies to declarative statements for packages, types, construction methods, member variables, parameters, and local variables. The Java annotation is some meta information attached to the code, and is used for some tools to parse and use during compiling and running, and plays a role in description and configuration. The annotations do not and do not affect the actual logic of the code, but merely serve an ancillary role. Contained in the java.
Assertion: is a means to check whether the program or test output is consistent with expectations, it being understood that it is concluded that an expression results in true, either by throwing an exception or otherwise failing the test case.
Specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
Example 1
Fig. 1 is a flowchart of a Java-based test framework building method according to embodiment 1 of the present invention.
As shown in fig. 1, the method for constructing a Java-based test framework provided in this embodiment includes the following steps:
s110: the test case set is set into a test packet and a test sub-packet with a hierarchical nesting relation according to the hierarchical nesting relation of each test case set in the test software, wherein the test packet comprises a test sub-packet and/or a test class of the next level, the test sub-packet comprises a test sub-packet and/or a test class of the next level, and the test class comprises a test method. It is emphasized that the test packets and the test sub-packets may also be stored in nodes of a block chain in order to further ensure privacy and security of the test packets and the test sub-packets.
The test software has several test case sets with hierarchical embedded relation, the test case set in the top layer may include several test case sets and/or test classes, and one test case subset may include several test case sets and/or test classes, or several test case subsets, or several test classes, with the test classes including several test methods.
And defining the test case set at the uppermost layer as a test packet, and defining the test case subset as a test sub-packet. Each test sub-package corresponds to one test case subset, and all the test packages and the test sub-packages have corresponding level nesting relations according to the level nesting relations of the test case subsets. One test packet may include several test sub-packets and test classes, or only several test sub-packets, or only several test classes.
The test case sets of different levels are designed into the relation between the test packet and the test sub-packet, and the relation between the test packet and the test sub-packet represents the relation between the test case sets and the test case subsets.
S120: adding abstract methods to the test packet, wherein the abstract methods comprise test preparation (setup ()) and test cleaning (Teardown ()), and the test sub-packet and/or test class of each level below the test packet inherits the test preparation (setup ()) and the test cleaning (teardown ()).
After the test case set is set as the test packet and the test sub-packet in step S110, the next level of the test packet includes the test sub-packet and/or the test class, and the test sub-packet may continue to have its next level of the test sub-packet and/or the test class. In this step, abstract methods setup () and teardown () are added to the test packet, the test sub-packet of each level under the test packet inherits this setup () and teardown () in turn, and the test class of each level under the test packet inherits this setup () and teardown () on which the test sub-packet is tested.
Thus, the test packets, sub-packets, and test classes all have the abstract methods setup (), teardown (). Test preparation may be added in the abstract method setup () inherited at each level, and test clean may be added in the abstract method teardown ().
S130: defining a cladding level test case tag annotation (PackageTag) for the test packet and the test sub-packet, defining a class level test case tag annotation (SuiteTag) for the test class, and defining a method level test case tag annotation (CaseTag) for the test method, respectively; wherein, the test sub-packet inherits the label annotation of the cladding level test case at the upper level, and the test class inherits the label annotation of the cladding level test case at the upper level; the test method inherits the label annotation of the cladding level test case and the label annotation of the class level test case at the upper level.
Each test sub-packet automatically inherits the test case tag annotation from the level of the test packet above the test sub-packet, and the test class automatically inherits the test case tag annotation from the level of the test packet above the test sub-packet. The test method automatically inherits the test case tag annotation from the previous test class hierarchy. Thus, the test case label annotation forms a step-by-step transmission inheritance mechanism among the test packet, the test sub-packet, the test class and the test method.
The test case tag adds different information to the test case by designing custom Java annotation, the added information is a special identifier of the test case, namely the test case tag annotation, and the test case can be flexibly grouped, filtered during execution, grouped and displayed in a test report and the like through the use case tag annotation.
Specifically, in step S110:
the test frame constructed by the Java-based test frame construction method comprises a test packet, a test sub-packet, a test class and a test method; the test packet, the test sub-packet, the test class and the test method are in a hierarchy nesting relation.
The test packet has the function of organizing the test sub-packets and/or the test classes with similar or related functions in the same packet, and the test sub-packets have the function of organizing the test sub-packets and/or the test classes with similar or related functions at a lower level in the same packet, so that the maintenance of the test case subsets or the test classes is facilitated. The test subpacket may contain a next level test subpacket that is functionally similar or related. Like folders, the test package also adopts a tree directory storage mode, and one test package comprises a plurality of sub-packages and/or test classes. The test framework uses the package mechanism to improve the management of the test case set and the test cases, facilitate the compiling and organization of the test cases and enhance the searching efficiency of the cases.
For example, the following is a test package framework constructed by the Java-based test framework construction method.
Figure RE-GDA0002576721160000081
The sfm test case set comprises an admin test case subset, and the admin test case subset comprises three test case subsets, namely common, login and main. And setting the test case sets and the subsets into a test packet and a test sub-packet, wherein the next level of the sfm test packet comprises an admin test sub-packet, the next level of the admin test sub-packet comprises a common test sub-packet, a logic test sub-packet and a main test sub-packet, and the next level of the main test sub-packet comprises an admin Main Page. The relation between the test packet and the test sub-packet represents the relation between the test case set and the test case subset, the test sub-packet can be continuously added to the lower layer of the test sub-packet to form a hierarchical nesting relation, and the hierarchical nesting relation represents the hierarchical nesting relation between the test case set and the test case subset.
It can be seen that the test report generated by the test framework formed by the method can also be displayed according to the hierarchy and is consistent with the nesting hierarchy of the test case set.
The execution order among the test sub-packets, the execution order among the test sub-packets and the test classes, and the execution order among the test classes of the same level can be configured. The configuration of the execution order is determined by the annotation configuration values.
Specifically, in step S120:
adding abstract method test preparation (setup ()) and test cleaning (Teardown ()) to a test packet, wherein the test sub-packet and/or test class of each level under the test packet inherits the test preparation (setup ()) and test cleaning (teardown ()), and the method comprises the following processes: defining the base class configuration information of the test packet as an InitBase abstract class, adding abstract methods setup () and teardown () in the test packet, wherein test sub-packets of each level under the test packet inherit the InitBase abstract class layer by layer so as to inherit the abstract methods setup () and teardown () of the InitBase abstract class, and test classes of each level under the test packet inherit the InitBase abstract class of the test sub-packets of the level above the test sub-packets so as to inherit setup () and teardown ().
In object-oriented design, a type is defined that contains all the entities in common, and is called a "base class".
The InitBase abstract class specifies the method for realizing the interface specification of the test package case set configuration class (Init).
Test preparation is to put the action to be prepared before the test is executed in setup (), and one or some test cases may depend on the same test preparation. For example, the execution of a set of test cases requires a login, then the test preparation for the set of test cases is the login, and the test preparation actions are written in the setup () method.
The test cleaning is an action which needs to be cleaned after the test cases are executed, and the test cleaning needs to be carried out after one or more test cases are executed. For example, after a set of test cases is executed, a certain test page needs to be closed, then the test cleaning of the set of test cases is to close a certain test page, and these test cleaning actions are written in the teardown () method.
After adding the abstract methods setup () and teardown () at the test packet level, test preparation and test cleaning can be added in the setup () and teardown (); the test sub-package of the lower level of the test package inherits the InitBase abstract class layer by layer, thereby inheriting setup () and teardown (), and test preparation and test cleaning can be added in the setup () and teardown () of the test sub-package of each layer; the method is used for realizing the test preparation and the test cleaning of the test packet formed by the test case set and the sub-packet level test case set.
The test class inherits the InitBase abstract class of the test sub-packet at the upper level, and realizes the abstract methods setup () and Teardown () of the inherited InitBase, and the test preparation and the test cleaning of the test class can be added in the two abstract methods respectively.
When the test packets and sub-packets formed by the test case set do not need to be subjected to test preparation and test cleaning, the test packet base class configuration information formed by the test case set can be undefined as the InitBase abstract class, and the test preparation and the test cleaning are added to the test class by adopting the following method.
The specific process comprises the following steps: defining test sub-package base class configuration information formed by a test class as a SuiteBase abstract class, adding an abstract method setup () and a teardown () of the SuiteBase abstract class in the test sub-package, succeeding the SuiteBase abstract class by the test class at the next level of the test sub-package so as to continue setup () and teardown (), adding test preparation in the abstract method setup () inherited by the test class, and adding test cleaning in the abstract method teardown () inherited by the test class.
The test class needs to inherit the base class SuiteBase of the test sub-packet at the upper layer, and realizes the abstract methods setup () and teardown () of the base class SuiteBase, and the test preparation and the test cleaning of the test class can be added in the two methods respectively.
The SuiteBase abstract class specifies the method which needs to be realized by the interface specification of the test class case set.
Through the two modes, the test class has the abstract methods setup () and Teardown (), and can complete the test preparation and the test cleaning.
Specifically, in step S130:
packet-level test case tag annotation (PackageTag) is applied to test packets and test sub-packets, class-level test case tag annotation (SuiteTag) is applied to test classes, and method-level test case tag annotation (CaseTag) is applied to test methods.
After the test case tag annotation is defined for each test method for the test packet, each test sub-packet and each test class, the test case tag annotation forms step-by-step transmission succession among the test packet, the test sub-packet, the test class and the test method. Thus, each test sub-packet comprises its own layer level test case label annotation and all layer level test case label annotations thereon; each test class comprises a class level test case label annotation and all levels of the class level test case label annotations thereon; the test method comprises the method level test case label annotation, the layer level test case label annotation of all levels above the method level test case label annotation and the class level test case label annotation of the layer level above the method level test case label annotation.
All the tag annotations may be the same or different, and are customized according to the actual situation of the test software.
Further, to provide the flexibility that class-level test case tag annotations inherit, the values in the class-level test case tag annotations may be set to force tag attributes to be represented by f or default tag attributes to be represented by d. The mandatory tag attribute f corresponds to the value of the mandatory tag annotation and the default tag attribute d corresponds to the value of the default tag annotation.
If the test method of the lower level of a certain test class has no tag annotation, the test method inherits the attribute in the class level test case tag annotation of the test class as the annotation value corresponding to the default tag attribute d; if the test method of the lower level of a certain test class has tag annotation, the test method will not inherit the annotation value corresponding to the default tag attribute d in the class level test case tag annotation of the test class, and the test method only contains the own method level test case tag annotation and the inherited cladding level test case tag annotation.
Whether a test method of a lower level of a certain test class has a tag annotation or not, the test method inherits the attribute in the class level test case tag annotation of the test class as an annotation value corresponding to the mandatory tag attribute f.
For example, as shown in FIG. 4, the inheritance delivery process is annotated to the test case label of the Java-based test framework build method.
admin is a test packet, ui is a test sub-packet of admin, test.java is a test class under the ui test sub-packet, init.java is a configuration class of the ui test sub-packet, which is inherited from initbase.java. @ PackageTag stands for annotation of the wrapper level test case tag. @ SuiteTag represents an annotation of class level test case tags. @ CaseTag stands for annotation of method level test case tags.
test1() is test method 1, and finally the [ ptag0, ptag1, ftag, daily ] tag is obtained.
test2() is test method 2, and finally the [ ptag0, ptag1, ftag, dtag ] tag is obtained.
The transfer process of the tag annotation comprises the following steps:
1. the admin test package has set an @ PackageTag, which is the value of ptag 0.
2. The ui test sub-packet inherits the tag annotation of its upper admin test packet and is set with an @ PackageTag, value ptag1, so the ui test sub-packet has tag annotation values ptag0, ptag 1.
3. The test.java test class is arranged at the lower layer of the ui test sub-packet and is provided with @ SuiteTag, the value corresponding to the default label attribute d is dtag, the value corresponding to the mandatory label attribute f is ftag, and then the test.java test class inherits ptag0 and ptag1 of the ui test sub-packet; java test class thus has tag annotation values ptag0, ptag1, ftag, dtag.
4. the test1() test method sets @ CaseTag with a value of daily, so that the test.java test type cannot inherit the value dtag corresponding to the default label attribute d, and only inherits the value ftag corresponding to the mandatory label attribute f; thus test1() will get the values of tag annotation ptag0, ptag1, ftag, daily.
5. the test2() test method does not set @ CaseTag, so that the value dtag corresponding to the default tag attribute d of the test.java test class is inherited, and thus the values of tag annotation obtained by the test2() are ptag0, ptag1, ftag, dtag.
The method may further comprise the steps of:
and setting a test case execution engine to identify the test method in the test case and executing the identified test method. The method specifically comprises the following steps:
when a test method is to be executed, the execution engine acquires all tag annotations on each test method by traversing the test methods in the test class, and judges whether the tag annotations of the test methods contain the set annotation @ Case; if the test method contains the annotation @ Case, the execution engine executes the test method, otherwise the test method will not be executed.
The method for defining the annotation @ Case comprises the following steps: the @ Case is set to comprise the following attributes, namely test Case description, test Case author, test Case priority, sequence number, whether forbidden or not, retry times, dependence cases and the like, each attribute of the @ Case is annotated to have a default value, and if a certain attribute is not assigned, the default value of the attribute is given.
And acquiring the attribute of the data driving annotation of the executed test method through the execution engine, and determining the source of the test data according to the attribute of the data driving annotation. The method specifically comprises the following steps:
and the information required by the test case execution engine is determined by dynamically acquiring the attribute value annotated on the test method through java reflection.
The attributes of the data-driven annotations of the test method may be defined as three attributes. The first attribute is: test data are obtained from variables and are expressed by data; the second attribute is as follows: acquiring test data from a file, and expressing the test data by using the file; the third attribute: test data were obtained from the methods and are denoted by method.
The attribute of the test data obtained from the variable is suitable for the scene that the test data required by the test case is ready in the variable.
The attribute of the test data obtained from the file can directly obtain the data required by the test case from the file, and the method is suitable for the test case requiring a large amount of data and the scene that the data does not need to be processed.
The attribute of the test data obtained from the method can be obtained from one test method, and the complex data can be provided after the assembly in the test method is completed.
The driver is an operation mode in the test case execution process, and shows the processing logic and the data use model in the test case execution process. The data driving represents that the test case is associated with a data group, generally, a data group has multiple groups of test data, and each group of data forms a test scene.
Uniformly acquiring the assertion exception thrown out during the operation of the test method, specifically comprising the following processes:
defining the type of the assertion Exception during the operation of the test method as Assert Exception (Assert Exception class during the operation), and uniformly capturing the assertion Exception with the type of Assert Exception in a position set in a test frame.
The Assert Runtime Exception is a Java Runtime Exception type, inherits from a Runtime Exception class, and the Exception is thrown out in a test method without forcing a user to perform Exception handling, so that a place is set in a program to uniformly capture the Exception, and a uniform framework custom assertion function is realized.
The step realizes unified assertion tools, encapsulates commonly used assertions, and judges that the assertions are not thrown out by converting into abnormity by assertion comparison logic. But the test frame captures the exception uniformly when executing the test case, thereby realizing the frame assertion function.
Example 2
FIG. 2 is a schematic diagram of a logical structure of a Java-based test framework building system according to embodiment 2 of the present invention;
as shown in fig. 2, the Java-based test framework building system provided in this embodiment includes: a test cladding level forming unit 201, a test preparation and test cleaning inheritance unit 202, and a test case label annotation inheritance unit 203.
The test cladding level forming unit 201 is used for setting the test case set into a test packet and a test sub-packet with a level nesting relationship according to the level nesting relationship of each test case set in the test software; the test sub-packet comprises a test sub-packet and/or a test class of the next level, and the test class comprises a test method;
a test preparation and test cleaning inheritance unit 202, configured to add an abstract method to a test packet, where the abstract method includes a test preparation (setup ()) and a test cleaning (Teardown ()), and a test sub-packet and/or a test class of each layer below the test packet inherits the test preparation (setup ()) and the test cleaning (teardown ());
a test case tag annotation propagation unit 203, configured to define a cladding-level test case tag annotation for the test packet and the test sub-packet, define a class-level test case tag annotation for the test class, and define a method-level test case tag annotation for the test method; the test sub-packet inherits the label annotation of the cladding-level test case at the upper level, and the test class inherits the label annotation of the cladding-level test case at the upper level; the test method inherits the cladding level test case label annotation and the class level test case label annotation at the upper level. It is emphasized that the test packets and the test sub-packets may also be stored in nodes of a block chain in order to further ensure privacy and security of the test packets and the test sub-packets.
Example 3
Fig. 3 is a schematic diagram of a logic structure of an electronic device according to embodiment 3 of the present invention.
As shown in fig. 3, an electronic device 1 includes a memory 3 and a processor 2, wherein the memory 3 stores a computer program 4, and the computer program 4 implements the steps of the Java-based test framework building method in embodiment 1 when being executed by the processor 2.
Example 4
A computer-readable storage medium, in which a Java-based test framework building program is stored, and when the Java-based test framework building program is executed by a processor, the steps of the Java-based test framework building method in embodiment 1 are implemented.
The block chain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism, an encryption algorithm and the like. A block chain (Blockchain), which is essentially a decentralized database, is a series of data blocks associated by using a cryptographic method, and each data block contains information of a batch of network transactions, which is used for verifying the validity of the information (anti-counterfeiting) and generating a next block. The blockchain may include a blockchain underlying platform, a platform product service layer, an application service layer, and the like.
The Java based test box architecture building method, apparatus and storage medium according to the present invention are described above by way of example with reference to fig. 1-4. However, it will be understood by those skilled in the art that various modifications may be made to the method, apparatus and storage medium for constructing a Java-based test framework as set forth in the above description without departing from the scope of the invention. Therefore, the scope of the present invention should be determined by the contents of the appended claims.

Claims (10)

1. A test framework construction method based on Java is characterized by comprising the following steps:
s110: setting the test case set into a test packet and a test sub-packet with the level nesting relation according to the level nesting relation of each test case set in the test software; wherein the test packet comprises a test sub-packet and/or a test class of its next level, the test sub-packet comprises a test sub-packet and/or a test class of its next level, the test class comprises a test method;
s120: adding an abstract method to the test packet, wherein the abstract method comprises test preparation and test cleaning, and the test sub-packets and/or test classes of each level under the test packet inherit the test preparation and the test cleaning;
s130: defining packet level test case tag annotations for the test packet and the test sub-packet respectively, defining class level test case tag annotations for the test class, and defining method level test case tag annotations for the test method; wherein, the test sub-packet inherits the label annotation of the upper layer of the test case, and the test class inherits the label annotation of the upper layer of the test case; the test method inherits the cladding level test case label annotation and the class level test case label annotation at the upper level.
2. The Java-based test framework building method of claim 1, wherein the test sub-packets are stored in a block chain, and an execution order between the test sub-packets, an execution order between the test sub-packets and the test classes, and an execution order between the test classes of the same hierarchy are configured by annotation configuration values.
3. The Java-based test framework building method according to claim 1, wherein the test package is stored in a block chain, and the step S120 includes the following processes:
defining base class configuration information of the test package as an InitBase abstract class, and adding the test preparation and the test cleaning at the test package level, wherein a test sub-package under the test package inherits the InitBase abstract class layer by layer so as to inherit the test preparation and the test cleaning, and a test class under the test package inherits the InitBase abstract class at the upper level so as to inherit the test preparation and the test cleaning.
4. The Java-based test framework building method according to claim 1, wherein in S130, the method further comprises: setting the attribute of the median value of the class level test case tag annotation as a mandatory tag attribute or a default tag attribute; wherein the content of the first and second substances,
if the test method has no tag annotation, the test method inherits the value corresponding to the default tag attribute in the class-level test case tag annotation of the upper level;
if the test method has the tag annotation, the test method does not inherit the value corresponding to the default tag attribute in the class-level test case tag annotation of the upper level;
the test method has or does not have tag annotation, and the test method inherits the value corresponding to the mandatory tag attribute in the class-level test case tag annotation at the upper level.
5. The Java-based test framework building method of claim 1, further comprising:
setting a test case execution engine to traverse the test methods in the test class, acquiring the tag annotation on each test method, and judging whether the tag annotation of the test method contains the set annotation;
if the test method contains the set annotation, executing the test method by an execution engine, otherwise, not executing the test method;
wherein the set annotations include the following attributes: the method comprises the following steps of describing a test case, an author of the test case, priority of the test case, sequence numbering, forbidding or not, retry times and dependent cases, wherein each attribute has a default value, and if the attribute is not assigned, the default value of the attribute is given;
and acquiring the attribute of the data driving annotation of the executed test method through the execution engine, and determining the source of the test data according to the attribute of the data driving annotation.
6. The Java based test framework building method of claim 5, wherein the attributes of the data-driven annotations include: the attribute of the test data obtained from the variable, the attribute of the test data obtained from the file, and the attribute of the test data obtained from the method.
7. The Java-based test framework building method of claim 1, further comprising: defining the type of the assertion Exception when the test method runs as Assert Exception, and uniformly capturing the assertion Exception thrown when the test method runs at the position set by the test framework.
8. A Java-based test framework building system, comprising:
the test packet level forming unit is used for setting the test case set into a test packet and a test sub-packet with the level nesting relation according to the level nesting relation of each test case set in the test software; wherein the test packet comprises a test sub-packet and/or a test class of its next level, the test sub-packet comprises a test sub-packet and/or a test class of its next level, the test class comprises a test method;
a test preparation and test cleaning inheritance unit, wherein abstract methods are added in the test packet, the abstract methods comprise test preparation and test cleaning, and test sub-packets and/or test classes of each level under the test packet inherit the test preparation and the test cleaning;
a test case tag annotation propagation unit, configured to define a packet-level test case tag annotation for the test packet and the test sub-packet, define a class-level test case tag annotation for the test class, and define a method-level test case tag annotation for the test method; wherein, the test sub-packet inherits the label annotation of the upper layer of the test case, and the test class inherits the label annotation of the upper layer of the test case; the test method inherits the cladding level test case label annotation and the class level test case label annotation at the upper level.
9. An electronic device, comprising a memory and a processor, wherein the memory stores a computer program which, when executed by the processor, implements the steps of the Java based test framework building method of any of claims 1 to 7.
10. A computer-readable storage medium, in which a Java based test framework builder is stored, which when executed by a processor, implements the steps of the Java based test framework building method according to any one of claims 1 to 7.
CN202010327398.5A 2020-04-23 2020-04-23 Java-based test framework construction method and device and storage medium Pending CN111625445A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010327398.5A CN111625445A (en) 2020-04-23 2020-04-23 Java-based test framework construction method and device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010327398.5A CN111625445A (en) 2020-04-23 2020-04-23 Java-based test framework construction method and device and storage medium

Publications (1)

Publication Number Publication Date
CN111625445A true CN111625445A (en) 2020-09-04

Family

ID=72260536

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010327398.5A Pending CN111625445A (en) 2020-04-23 2020-04-23 Java-based test framework construction method and device and storage medium

Country Status (1)

Country Link
CN (1) CN111625445A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112882931A (en) * 2021-02-06 2021-06-01 重庆富民银行股份有限公司 Automatic testing method and device based on DDT
CN112965905A (en) * 2021-03-11 2021-06-15 京东数科海益信息科技有限公司 Data testing method, device, equipment and storage medium
CN113419954A (en) * 2021-06-25 2021-09-21 陕西浪潮英信科技有限公司 Execution method and system of automation use case of cloud operating system and related components
CN117435512A (en) * 2023-12-21 2024-01-23 摩尔元数(福建)科技有限公司 Unit test method for automatically switching different database types based on Junit5

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112882931A (en) * 2021-02-06 2021-06-01 重庆富民银行股份有限公司 Automatic testing method and device based on DDT
CN112882931B (en) * 2021-02-06 2023-05-09 重庆富民银行股份有限公司 Automatic test method and device based on DDT
CN112965905A (en) * 2021-03-11 2021-06-15 京东数科海益信息科技有限公司 Data testing method, device, equipment and storage medium
CN113419954A (en) * 2021-06-25 2021-09-21 陕西浪潮英信科技有限公司 Execution method and system of automation use case of cloud operating system and related components
CN117435512A (en) * 2023-12-21 2024-01-23 摩尔元数(福建)科技有限公司 Unit test method for automatically switching different database types based on Junit5
CN117435512B (en) * 2023-12-21 2024-03-08 摩尔元数(福建)科技有限公司 Unit test method for automatically switching different database types based on Junit5

Similar Documents

Publication Publication Date Title
CN111625445A (en) Java-based test framework construction method and device and storage medium
US7797687B2 (en) Parameterized unit tests with behavioral purity axioms
Balanyi et al. Mining design patterns from C++ source code
Moreau et al. A templating system to generate provenance
US8832658B2 (en) Verification framework for business objects
CN109189374B (en) Object structure code generation method and system based on object reference chain
Rayside et al. Object ownership profiling: a technique for finding and fixing memory leaks
US7444622B2 (en) Access driven filtering
WO2009138495A1 (en) Automatic testing of a computer software system
US20060225042A1 (en) Virtual threads in business process programs
Xiao et al. Tzuyu: Learning stateful typestates
Miksa et al. Using ontologies for verification and validation of workflow-based experiments
Bartolini et al. Data flow-based validation of web services compositions: Perspectives and examples
Fleurey et al. Towards dependable model transformations: Qualifying input test data
Kiefer et al. Analyzing software with iSPARQL
JP2007535013A (en) Computer program design
de Boer et al. Combining monitoring with run-time assertion checking
Demurjian Sr et al. Towards a definitive paradigm for security in object-oriented systems and applications
Seidl et al. Generative software product line development using variability-aware design patterns
Barbey Test selection for specification-based testing of object-oriented software based on formal specifications
CN114385155A (en) vue project visualization tool generation method, device, equipment and storage medium
Cooper et al. Java implementation verification using reverse engineering
Kessel LASSO–an observatorium for the dynamic selection, analysis and comparison of software
Paradkar Inter-class testing of OO software in the presence of polymorphism
Chaturvedi Change impact analysis based regression testing of web services

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