Disclosure of Invention
The inventor finds that in the prior art, generally, a tester selects a page manually, configures test parameters, and repeats the operations, so that the test efficiency and the test accuracy are reduced.
One technical problem to be solved by the present disclosure is: how to improve the testing efficiency and accuracy.
According to some embodiments of the present disclosure, there is provided a test method comprising: reading user login information and address information of an object to be tested; generating an access request and sending the access request to a server corresponding to the object to be tested according to the user login information and the address information of the object to be tested; testing the information enabling assertion of the object to be tested returned by the server; and determining whether the object to be tested is normal or not according to the assertion result.
In some embodiments, generating the access request according to the user login information and the address information of the object to be tested comprises: creating a hypertext transfer protocol (HTTP) request; and adding the user login information and the address information of the object to be tested into the HTTP request to generate an access request.
In some embodiments, the object to be tested comprises a page to be tested; the testing of the information enabling assertion of the object to be tested returned by the server comprises the following steps: acquiring elements to be tested in the content information of the page to be tested returned by the server; enabling a first assertion to the element to be tested, and matching the element to be tested with a preset element in the first assertion to obtain a first assertion result.
In some embodiments, the object to be tested comprises a test interface; the testing of the information enabling assertion of the object to be tested returned by the server comprises the following steps: acquiring information of an interface to be tested returned by a server; and starting a second assertion for the information of the interface to be tested, and matching the preset information in the second assertion with the information of the interface to be tested to obtain a second assertion result.
In some embodiments, the object to be tested comprises a test interface; the method further comprises the following steps: reading parameters corresponding to the interface to be tested; generating an access request according to the user login information and the address information of the object to be tested comprises the following steps: and generating an access request according to the user login information, the parameters corresponding to the interface to be tested and the address information of the interface to be tested.
In some embodiments, reading the user login information and the address information of the object to be tested comprises: and responding to the triggering of the periodic timing test task, and reading user login information and address information of the object to be tested.
In some embodiments, further comprising: storing a test result of whether the object to be tested is normal to a database; or generating and outputting a test result of whether the object to be tested is normal.
In some embodiments, further comprising: and sending the abnormal test result of the object to be tested to a preset mailbox under the condition that the object to be tested is abnormal.
According to further embodiments of the present disclosure, there is provided a test apparatus including: the information reading module is used for reading user login information and address information of an object to be tested; the request module is used for generating an access request and sending the access request to a server corresponding to the object to be tested according to the user login information and the address information of the object to be tested; the testing module is used for testing the information enabling assertion of the object to be tested returned by the server; and the result generation module is used for determining whether the object to be tested is normal or not according to the assertion result.
In some embodiments, the request module is to create a hypertext transfer protocol, HTTP, request; and adding the user login information and the address information of the object to be tested into the HTTP request to generate an access request.
In some embodiments, the object to be tested comprises a page to be tested; the testing module is used for acquiring elements to be tested in the content information of the page to be tested returned by the server; enabling a first assertion to the element to be tested, and matching the element to be tested with a preset element in the first assertion to obtain a first assertion result.
In some embodiments, the object to be tested comprises a test interface; the test module is used for acquiring the information of the interface to be tested returned by the server; and starting a second assertion for the information of the interface to be tested, and matching the preset information in the second assertion with the information of the interface to be tested to obtain a second assertion result.
In some embodiments, the object to be tested comprises a test interface; the information reading module is further used for reading parameters corresponding to the interface to be tested, and the request module is used for generating an access request according to the user login information, the parameters corresponding to the interface to be tested and the address information of the interface to be tested.
In some embodiments, the information reading module is configured to read the user login information and the address information of the object to be tested in response to the triggering of the periodic timing test task.
In some embodiments, the apparatus further comprises: the storage module is used for storing a test result of whether the object to be tested is normal to the database; or, the result output module is used for generating and outputting a test result of whether the object to be tested is normal; or the notification module is used for sending the abnormal test result of the object to be tested to a preset mailbox under the condition that the object to be tested is abnormal.
According to still other embodiments of the present disclosure, there is provided a test apparatus including: a processor; and a memory coupled to the processor for storing instructions that, when executed by the processor, cause the processor to perform a test method as in any of the preceding embodiments.
According to still further embodiments of the present disclosure, there is provided a non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the testing method of any of the foregoing embodiments.
The automatic testing method comprises the steps of reading user login information and address information of an object to be tested, automatically generating an access request and sending the access request to a corresponding server, testing the information of the object to be tested returned by the server in an assertion mode, and determining whether the object to be tested is normal or not according to an assertion result. The automatic testing method can be applied to different testing objects and tests the information of the objects to be tested corresponding to the users with different authorities. The automatic test can be started at any time, the change is flexible, and the efficiency and the accuracy of the test are improved. And the change of the test logic can be realized only by changing the asserted logic by adopting an assertion mode, and the maintenance cost is low.
Other features of the present disclosure and advantages thereof will become apparent from the following detailed description of exemplary embodiments thereof, which proceeds with reference to the accompanying drawings.
Detailed Description
The technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the drawings in the embodiments of the present disclosure, and it is obvious that the described embodiments are only a part of the embodiments of the present disclosure, and not all of the embodiments. The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the disclosure, its application, or uses. All other embodiments, which can be derived by a person skilled in the art from the embodiments disclosed herein without making any creative effort, shall fall within the protection scope of the present disclosure.
The present disclosure proposes an automated testing method, described below in conjunction with fig. 1.
FIG. 1 is a flow chart of some embodiments of the disclosed test methods. As shown in fig. 1, the method of this embodiment includes: steps S102 to S108.
In step S102, user login information and address information of an object to be tested are read.
The object to be tested may include: at least one item of the page to be tested and the interface to be tested can be set according to actual requirements. For example, a Tomcat test environment is set up, one or more user login information is saved in a user information configuration file, and address information of one or more objects to be tested is saved in an object configuration file. A user information reading class, e.g., a cookie information class, may be created that reads user login information (e.g., login account and password) in a user information profile. An object read class, e.g., ReadUrl class, may be created that reads address information of the object to be tested (e.g., URL (uniform resource locator) of the object to be tested) in the object configuration file.
A test service class, such as the StartTest class, may be created to perform tests through the httpClient framework. After reading the user login information, the user information reading class can package the read user login information and provide the user login information for the test service class. After reading the address information of the object to be tested, the object reading class can package the address information and provide the packaged address information to the test service class. The test service class calls the packages provided by the user information reading class and the object reading class, so that the test service class reads the user login information and the address information of the object to be tested to perform the subsequent test method.
In some embodiments, in response to the triggering of a periodic timed test task, user login information and address information of an object to be tested are read. The timing Task configured by SpringQuartz can be used to set a Task class, for example, a Task class is used to set a timing test Task, and a test method in a test service class is executed in response to a preset time.
In step S104, an access request is generated according to the user login information and the address information of the object to be tested, and the access request is sent to the server corresponding to the object to be tested.
In some embodiments, an HTTP request may be generated as the access request. For example, create an HTTP (hypertext transfer protocol) request; and adding the user login information and the address information of the object to be tested into the HTTP request to generate an access request.
In step S106, the information enabling assertion of the object to be tested returned by the server is tested.
Assertions are programming terms, expressed as boolean expressions, that can be set according to the content and logic that needs to be tested in practice.
In step S108, it is determined whether the object to be tested is normal according to the assertion result.
The assertion will return the decision, true or false, of the boolean expression. And under the condition that the assertion result is false, the object to be tested is determined to be abnormal, and under the condition that the assertion result is true, the object to be tested is determined to be normal.
In the above embodiment, the login information of a plurality of users and the address information of the object to be tested can be read simultaneously. And executing the process of generating different access requests and performing the test by a plurality of threads in parallel.
In some embodiments, storing the test result of whether the object to be tested is normal to a database; or generating and outputting a test result of whether the object to be tested is normal. In other embodiments, in the case that the object to be tested is abnormal, the test result that the object to be tested is abnormal is sent to a preset mailbox so as to inform a worker. And under the condition that the object to be tested is normal, the test result can be sent to a preset mailbox.
A result output class, e.g., ResultWrite class, may be created, the test results written to a database, or output as a file, or sent to a preset mailbox. And the test service class calls a result output class to analyze, process and store the result in a database and send the mail related personnel.
The embodiment provides an automatic testing method, which includes reading user login information and address information of an object to be tested, automatically generating an access request and sending the access request to a corresponding server, testing the information of the object to be tested returned by the server in an assertion mode, and determining whether the object to be tested is normal according to an assertion result. The automatic testing method can be applied to different testing objects and tests the information of the objects to be tested corresponding to the users with different authorities. The automatic test can be started at any time, the automatic test is changed flexibly, the efficiency and the accuracy of the test are improved, and the logging information does not need to be manually input to different pages to carry out the test work with complicated repeatability. And the change of the test logic can be realized only by changing the asserted logic by adopting an assertion mode, and the maintenance cost is low. In addition, the automatic test is executed at regular time, so that errors caused by manual test of testers are reduced, and the safety and the stability of the test are improved. The related personnel of the test result warehousing and mail sending can reserve historical problems, record the problems and facilitate follow-up; sending the mail can quickly inform corresponding personnel to solve the problem.
Some embodiments are described below by taking the object to be tested as the page to be tested or the interface to be tested as an example.
FIG. 2 is a flow chart of additional embodiments of the testing method of the present disclosure. As shown in fig. 2, the method of this embodiment includes: steps S202 to S216.
In step S202, in response to the triggering of the periodic timing test task, the user login information and the address information of the page to be tested are read.
For example, a test task is issued 12 points a day, and referring to the foregoing embodiment, the package provided by the user information reading class and the object reading class is called by the test service class, so as to obtain the user login information and the address information of the page to be tested.
In step S204, an access request is generated and a server corresponding to the page to be tested is sent according to the user login information and the address information of the page to be tested.
In step S206, the element to be tested in the content information of the page to be tested returned by the server is obtained.
The content information of the page to be tested is, for example, an HTML (hypertext markup language) file, and parsing the HTML file can obtain various elements included in the page to be tested, such as a title, contents of each part, and the like. Different elements to be tested can be tested according to requirements, for example, whether the page name is correct, the text format is uniform, whether the typesetting is neat, the data loading condition and the like are tested.
In step S208, a first assertion is enabled for the element to be tested, and the element to be tested is matched with a preset element in the first assertion, so as to obtain a first assertion result.
For example, the user login account is 278011, and the user login account should be displayed in the upper right corner of the page to be tested after the user login account is logged in. If the user login account in the test page is normally displayed, an element displaying the position of the user login account in the page to be tested can be used as an element to be tested, the element to be tested is obtained, such as 'name', a preset assertion (name, '278011') is started, the obtained element to be tested is matched with 278011, if the two elements are matched, the assertion result is true, and if not, false is obtained.
In step S210, it is determined whether the page to be tested is normal according to the first assertion result.
In step S212, a test result indicating whether the page to be tested is normal is stored in the database.
In step S214, a test result indicating whether the page to be tested is normal is generated into a file and output.
In step S216, a test result indicating whether the page to be tested is normal is sent to a preset mailbox.
Steps S212 to S216 may be executed in parallel without any order.
The method of the embodiment realizes automatic testing of the page, can execute automatic testing regularly according to requirements, improves testing efficiency, stability and accuracy, retains the testing result after testing, informs workers of solving problems in time, and facilitates follow-up.
FIG. 3 is a flow chart of yet further embodiments of the disclosed test method. As shown in fig. 3, the method of this embodiment includes: steps S302 to S316.
In step S302, in response to the trigger of the periodic timing test task, user login information, parameters corresponding to the interface to be tested, and address information of the interface to be tested are read.
The parameters corresponding to the interface to be tested can also be stored in the interface parameter configuration file in advance, reading and packaging are carried out through the interface parameter reading class, and the testing service class calls the interface parameter reading class to obtain the parameters corresponding to the interface to be tested.
In step S304, an access request is generated and a server corresponding to the interface to be tested is sent according to the user login information, the parameter corresponding to the interface to be tested, and the address information of the interface to be tested.
In step S306, information of the interface to be tested returned by the server is obtained.
For example, the interface to be tested is a coupon picking interface, the information of the interface to be tested returned by the server is { "subCodeMsg": the coupon is robbed up in the current time period, please go to the bar 20: 00! "," subCode ": D2", "code": 0"," msg ": null }.
In step S308, a second assertion is enabled for the information of the interface to be tested, and the preset information in the second assertion is matched with the information of the interface to be tested, so as to obtain a second assertion result.
For example, the interface information that the coupon has been robbed up for the current time period may be represented by "code" of 0. Matching a value corresponding to the code in the information of the interface to be tested returned by the server with a preset value 0 in a second assertion assert rule (map.key,0), wherein the map.key represents the obtained code value, if the two are matched, the assertion result is true, otherwise, the assertion result is false.
In step S310, it is determined whether the interface to be tested is normal according to the second assertion result.
In step S312, the test result of whether the interface to be tested is normal is stored in the database.
In step S314, a test result indicating whether the interface to be tested is normal is generated into a file and output.
In step S316, a test result indicating whether the interface to be tested is normal is sent to a preset mailbox.
Steps S312 to S316 may be executed in parallel, without being in order.
The method of the embodiment realizes automatic testing of the interface, can execute automatic testing regularly according to requirements, improves testing efficiency, stability and accuracy, retains the testing result after testing, informs workers of solving problems in time, and facilitates follow-up.
The present disclosure also provides a testing device, described below in conjunction with fig. 4.
FIG. 4 is a block diagram of some embodiments of a testing device of the present disclosure. As shown in fig. 4, the apparatus 40 of this embodiment includes: the system comprises an information reading module 410, a request module 420, a test module 430 and a result generation module 440.
And an information reading module 410, configured to read user login information and address information of the object to be tested.
In some embodiments, the object to be tested comprises a test interface; the information reading module 410 is further configured to read a parameter corresponding to the interface to be tested, and the request module is configured to generate an access request according to the user login information, the parameter corresponding to the interface to be tested, and the address information of the interface to be tested.
In some embodiments, the information reading module 410 is configured to read the user login information and the address information of the object to be tested in response to the triggering of the periodic timing test task.
The request module 420 is configured to generate an access request according to the user login information and the address information of the object to be tested, and send the access request to the server corresponding to the object to be tested.
In some embodiments, the request module 420 is to create a hypertext transfer protocol, HTTP, request; and adding the user login information and the address information of the object to be tested into the HTTP request to generate an access request.
And the testing module 430 is configured to test the information enabling assertion of the object to be tested, which is returned by the server. In some embodiments, the object to be tested comprises a page to be tested; the test module 430 is configured to obtain an element to be tested in the content information of the page to be tested returned by the server; enabling a first assertion to the element to be tested, and matching the element to be tested with a preset element in the first assertion to obtain a first assertion result.
In some embodiments, the object to be tested comprises a test interface; the test module 430 is used for acquiring information of the interface to be tested returned by the server; and starting a second assertion for the information of the interface to be tested, and matching the preset information in the second assertion with the information of the interface to be tested to obtain a second assertion result.
And the result generating module 440 is configured to determine whether the object to be tested is normal according to the assertion result.
In some embodiments, the testing device 40 further comprises: a storage module 450, a result output module 470, and a notification module 470.
The storage module 450 is configured to store the test result of whether the object to be tested is normal in the database.
And a result output module 460, configured to generate and output a test result indicating whether the object to be tested is normal.
And the notification module 470 is configured to send a test result that the object to be tested is abnormal to a preset mailbox when the object to be tested is abnormal.
The testing apparatus in the embodiments of the present disclosure may each be implemented by various computing devices or computer systems, which are described below in conjunction with fig. 5 and 6.
FIG. 5 is a block diagram of some embodiments of a testing device of the present disclosure. As shown in fig. 5, the apparatus 50 of this embodiment includes: a memory 510 and a processor 520 coupled to the memory 510, the processor 520 configured to perform a test method in any of the embodiments of the present disclosure based on instructions stored in the memory 110.
Memory 510 may include, for example, system memory, fixed non-volatile storage media, and the like. The system memory stores, for example, an operating system, an application program, a BootLoader (BootLoader), a database, and other programs.
FIG. 6 is a block diagram of further embodiments of the testing device of the present disclosure. As shown in fig. 6, the apparatus 60 of this embodiment includes: memory 610 and processor 620 are similar to memory 510 and processor 520, respectively. An input output interface 630, a network interface 640, a storage interface 650, and the like may also be included. These interfaces 630, 640, 650 and the connections between the memory 610 and the processor 620 may be, for example, via a bus 660. The input/output interface 630 provides a connection interface for input/output devices such as a display, a mouse, a keyboard, and a touch screen. The network interface 640 provides a connection interface for various networking devices, such as a database server or a cloud storage server. The storage interface 650 provides a connection interface for external storage devices such as an SD card and a usb disk.
As will be appreciated by one skilled in the art, embodiments of the present disclosure may be provided as a method, system, or computer program product. Accordingly, the present disclosure may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present disclosure may take the form of a computer program product embodied on one or more computer-usable non-transitory storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present disclosure is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the disclosure. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The above description is only exemplary of the present disclosure and is not intended to limit the present disclosure, so that any modification, equivalent replacement, or improvement made within the spirit and principle of the present disclosure should be included in the scope of the present disclosure.