Application program testing method and system
By obtaining and verifying the target environment domain name in application testing, the repeated packaging and installation problems caused by frequent replacement of the test environment are solved, and an efficient testing and development process is achieved, ensuring the continuity of the test and data consistency.
Patent Information
- Application Number
- CN202510314101.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-17
- Publication Date
- 2025-07-18
AI Technical Summary
During the application development testing phase, repeated packaging and installation are required when frequently changing the test environment, resulting in inefficient testing and development.
By obtaining the domain name of the current environment, replacing it with the target environment domain name in response to the test request, and verifying it before or after the replacement, using the system configuration or interface to obtain the domain name, setting a drop-down box or input box for domain name switching, sending test cases and generating a report.
It realizes that only package and install in different environments is required at one time, avoiding repeated operations, improving testing and development efficiency, and ensuring the continuity of testing and data consistency.
Smart Images

Figure CN120336201A_ABST
Abstract
Description
Technical Field
[0001] The present invention generally relates to the field of computer technology. More specifically, the present invention relates to an application testing method and system. Background Art
[0002] During the development and testing phase of an application, it is necessary to test in multiple test environments to ensure the availability of the application. Therefore, when changing the test environment, it is necessary to repackage and install the application so that the application can be tested based on the new test environment. However, if there are multiple environments to be tested, frequently repackaging and installing the application will greatly affect the testing efficiency, thereby affecting the development efficiency.
[0003] Therefore, when there are multiple environments to be tested, how to avoid repeatedly repackaging and installing the application to improve the development efficiency is a technical problem that urgently needs to be solved. Summary of the Invention
[0004] To solve the above technical problem of low application testing efficiency, the present invention provides solutions in the following aspects.
[0005] In a first aspect, the present invention provides an application testing method, including: obtaining the domain name of the current environment; in response to receiving a test request, extracting the domain name in the test request, replacing the domain name of the current environment with the domain name in the test request to obtain a target environment; wherein, before the replacement, verifying the domain name in the test request, or after the replacement, verifying the domain name of the target environment; and performing testing based on the target environment.
[0006] Further, after extracting the domain name in the test request, it further includes: in response to the extracted domain name including multiple candidate domain names, verifying the candidate domain names in sequence according to a preset priority order; and selecting the first candidate domain name that passes the verification as the final replacement target.
[0007] Further, obtaining the domain name of the current environment includes: obtaining the domain name of the current environment through system configuration, environment variables, or by calling a preset interface.
[0008] Further, obtaining the domain name of the current environment through the system configuration includes: obtaining the domain name of the current environment through BASEURL[XYUtility getBaseUrlString].
[0009] Further, verifying the domain name in the test request includes: determining whether it contains valid domain name information.
[0010] Further, it is determined whether valid domain name information is included, including: determining whether the domain name in the test request contains at least one dot and does not start or end with a dot; and determining whether the domain name in the test request only contains letters, numbers, dots, and hyphens.
[0011] Further, before extracting the domain name in the test request, it also includes: determining whether the source of the test request is legal.
[0012] Further, testing is performed based on the target environment, including: sending a series of preset test cases to the target environment; recording the execution results of the test cases, where the execution results include passing the test or failing the test; and generating a test report according to the execution results.
[0013] Further, the method of the present invention also includes: verifying the availability and correctness of the target environment.
[0014] In a second aspect, the present invention provides an application program test system, including a processor and a memory, where the memory stores computer program instructions, and when the computer program instructions are executed by the processor, an application program test method according to the first aspect is implemented.
[0015] The beneficial effects of the present invention are as follows: The method of the present invention flexibly switches the target environment according to the domain name in the test request, so as to obtain and test data in different environments. Therefore, the application program only needs to be packaged and installed once to be tested in different environments, avoiding the problem of frequently packaging and installing the application program when testing data in different environments, saving test time and labor costs, and thus improving the work efficiency of testing and development. Further, by performing validity verification before or after replacement, it is possible to avoid testing with invalid domain names and ensure the continuity of testing. Description of the Drawings
[0016] By referring to the drawings and reading the following detailed description, the above and other objects, features, and advantages of the exemplary embodiments of the present invention will become readily understood. In the drawings, several embodiments of the present invention are shown in an exemplary rather than restrictive manner, and the same or corresponding reference numerals represent the same or corresponding parts, where:
[0017] Figure 1 is a flowchart schematically showing an application program test method according to Embodiment 1 of the present invention;
[0018] Figure 2 is a schematic diagram schematically showing the domain name switching function according to an embodiment of the present invention;
[0019] Figure 3It is a flowchart schematically showing an application program testing method according to Embodiment 2 of the present invention;
[0020] Figure 4 It is a block diagram schematically showing the structure of an application program testing system according to Embodiment 3 of the present invention. Detailed implementation manners
[0021] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative efforts fall within the protection scope of the present invention.
[0022] Next, the detailed implementation manners of the present invention will be described in conjunction with the accompanying drawings.
[0023] Embodiment 1
[0024] Figure 1 It is a flowchart schematically showing an application program testing method according to Embodiment 1 of the present invention.
[0025] Generally speaking, a network request includes a domain name and a path. Among them, the domain name is used to locate the server, and the path is used to specify the location of specific resources on the server. In the network requests written in the application program code, only the domain names of the network requests are different, but the paths of the network requests are the same. For this, a method of replacing the domain name of the network request can be added to obtain different data, so that testers can test the data under different requested IPs by installing the application program once, avoiding the problem of needing to repeatedly install the application program by packaging, thereby improving the work efficiency of development and testing. Specifically, in the first aspect, Embodiment 1 of the present invention provides an application program testing method. As Figure 1 shown, the method of this Embodiment 1 includes:
[0026] S101. Obtain the domain name of the current environment.
[0027] The domain name of the current environment can be obtained through system configuration, environment variables or by calling a preset interface.
[0028] Specifically, in this embodiment, the domain name information of the current environment is obtained through system configuration. It can be understood that various parameters and settings related to the current environment are usually stored in the system configuration file, including domain name information. Through specific reading functions or tools, the domain name of the current environment can be accurately extracted from the configuration file. Specifically, the method of the present invention obtains the domain name of the current environment through BASEURL[XYUtility getBaseUrlString], and this statement is a macro setting for obtaining the BaseUrl. It should be noted that BaseUrl represents the domain name of the current environment.
[0029] S102. In response to receiving a test request, extract the domain name in the test request, replace the domain name of the current environment with the domain name in the test request to obtain a target environment, and verify the domain name of the target environment.
[0030] In one embodiment, a page for the domain name switching function is set, and a default domain name is set. The required domain name can be selected from a preset multiple domain names for switching through a dropdown box / dropdown list. Exemplarily, as Figure 2 shown, on the login page, the default request is https: / / www.xyyl.com (formal environment), and testers can click on the dropdown box to select the preset www.xyyl.com (formal environment) or test.xyyl.com (test environment) for testing. This method can avoid the problem of entering incorrect domain names, thus ensuring the continuity of testing. In an alternative embodiment, it can also be set as an input box to allow testers to flexibly enter the domain name according to their needs.
[0031] Furthermore, after receiving the test request from the tester, assign the domain name in the test request to the domain name of the current environment to obtain a target environment. Specifically, set the property url (global variable baseurl, equivalent to the domain name of the current environment) in the appdelegate (application delegate, responsible for the startup, entering the background, etc. of the application), and set the value of url to the domain name selected by the tester to obtain a target environment.
[0032] In an alternative embodiment, it further includes determining whether the source of the test request is legal. Specifically, it is possible to compare the user name and password corresponding to the received test request with the pre-stored user information, and perform domain name replacement after the comparison passes. In an alternative embodiment, an IP white list is also created to only allow IP addresses in the white list to send requests, thereby ensuring the legality of the request source; or an IP black list is created to prohibit IP addresses in the black list from sending requests, and the white list or black list is updated regularly. By determining whether the source of the test request is legal, external malicious attacks can be prevented; in addition, legal request sources usually follow preset specifications, thereby ensuring that the format and content of the data are correct.
[0033] After obtaining the target environment, it further includes: verifying the domain name of the target environment. Specifically, it is determined whether the domain name of the target environment is empty. If so, an error prompt is returned or it is set to the default domain name. If not (indicating that the verification passes), the test is performed based on the target environment.
[0034] Specifically, the above process can be implemented by the following method:
[0035] +(NSString*)getBaseUrlString{
[0036] AppDelegate* del = [UIApplication sharedApplication].delegate;
[0037] return del.baseUrl? del.baseUrl : @"https: / / xyst.xyyl.com / com / ";
[0038] }
[0039] Among them, AppDelegate* del = [UIApplication sharedApplication].delegate is used to obtain the global variable baseurl (i.e., the domain name of the target environment, and the domain name here is the domain name input by the tester); del.baseUrl? del.baseUrl : @"https: / / xyst.xyyl.com / com / " is used to determine whether the global variable is empty. If it is empty, the default domain name is used; if it is not empty, the test is performed based on the domain name input by the tester. It can be understood that the above judgment process is actually to determine whether the domain name input by the tester is empty. If it is not empty, the test is performed based on the domain name input by the tester. If it is empty, the test is performed based on the default domain name.
[0040] In alternative embodiments, for the domain name entered in the input box, its format can be verified through regular expressions to ensure that the domain name entered by the tester is in a legal URL format. Specifically, it can be achieved through the following method:
[0041] +(NSString*)getBaseUrlString{
[0042] AppDelegate* del = [UIApplication sharedApplication].delegate;
[0043] NSString* baseUrl = del.baseUrl? del.baseUrl : @"https: / / xyst.xyyl.com
[0044] / com / ";
[0045] / / Define the regular expression
[0046] NSString* urlRegex = @"^((https?|ftp|file): / / )?([\\da-z.-]+)\\.([a-z.]{2,6})$";
[0047] NSPredicate* urlTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", urlRegex];
[0048] if (![urlTest evaluateWithObject:baseUrl]){
[0049] baseUrl = @"https: / / xyst.xyyl.com / com / ";
[0050] }
[0051] return baseUrl;}
[0052] The specific explanations of the above regular expression are as follows:
[0053] "^" represents the start position of the string; "$" represents the end position of the string.
[0054] "((https?|ftp|file): / / )?" represents an optional group. Among them, "(https?|ftp|file)" represents matching the http, https, ftp, or file protocol, and "?" indicates that this group is optional, that is, the URL can not contain the protocol part. For example, if the https protocol is uniformly adopted for the domain names corresponding to all environments, then the user may not input the protocol part.
[0055] "([\\da-z.-]+)" represents matching the main part of the domain name. Among them, "\\d" represents matching any digit; "a - z" represents matching any lowercase letter; "." and "-" represent characters allowed to appear in the domain name; "+" represents that the previous character class (digit, lowercase letter, etc.) can appear once or more times.
[0056] "\\." represents matching the dot in the domain name.
[0057] "([a-z.]{2,6})" matches the top-level domain part of the domain name, such as.com,.cn, etc. Among them, "a - z" represents matching any lowercase letter; "." represents a character allowed to appear in the top-level domain; "{2,6}" represents that the previous character class can appear 2 to 6 times. It should be noted that common top-level domains are generally short. Therefore, by restricting the length of the top-level domain, overmatching can be avoided and the situation of incorrect matching can be reduced.
[0058] Further, if (![urlTest evaluateWithObject:baseUrl]) {baseUrl =
[0059] @"https: / / xyst.xyyl.com / com / ";} represents judging whether the input URL conforms to the above regular expression. If so, the input domain name is used; if not, it is set to the default URL.
[0060] By assigning the input domain name to a global variable and then making a judgment, the consistency of data can be ensured. Because the global variable serves as the only data source and all modules share the same configuration, it can avoid different modules using different temporarily input values, thus ensuring the consistency of data. Further, it also avoids reading the values of interface controls every time a network request is made, which can reduce unnecessary access and thus improve the efficiency of testing. Further, for an empty input domain name, using the default domain name can prevent the network request from being interrupted due to an invalid domain name.
[0061] 103. Conduct tests based on the target environment.
[0062] In this embodiment, the testing process includes sending a series of preset test cases to the target environment. The test cases are designed according to the testing requirements and the characteristics of the target environment, and are used to verify whether the various functions of the system are normal, whether the performance meets the standards, and whether there are compatibility issues, etc. The test cases can be divided into different types such as functional test cases, performance test cases, and compatibility test cases.
[0063] Functional test cases are mainly used to verify whether the various functions of the system are implemented as expected. For example, for an online shopping system, the functional test cases may include testing whether functions such as user registration, login, product browsing, and placing an order to purchase are normal. When sending functional test cases, the actual operations of users are simulated, corresponding requests are sent to the target environment, and it is checked whether the responses of the system meet the expectations.
[0064] Compatibility test cases are used to check the compatibility of the system in different environments such as browsers, operating systems, devices, etc. For example, test whether the display effects and functions of the system are normal under different browsers such as Chrome, Firefox, Safari, etc., and the running conditions under different operating systems such as Windows, Mac OS, Linux, etc. When sending compatibility test cases, different browser and operating system environments are used to access the target environment, and it is checked whether the performance of the system is consistent.
[0065] During the testing process, the execution results of the test cases are recorded, and the execution results include passing the test or failing the test. The execution situation of the test cases is monitored in real time. When the execution of the test cases is completed, the test result is determined to be passed or failed according to the preset judgment criteria. For example, if the expected response result of a functional test case is to return a preset value, and the system actually returns this preset value during execution, then it is determined that this test case passes; otherwise, if the returned preset value does not match the expectation, it is determined that the test fails.
[0066] Finally, a test report is generated according to the execution results of the test cases. The test report includes the description of the test environment, the execution situation of the test cases, the statistical data of various performance indicators, and the problems found, etc. By generating the test report, it enables testers and developers to view and analyze.
[0067] In an alternative embodiment, it further includes: storing and updating the recently used domain names (the domain names for which the testing has been completed) for quickly switching back to the previously used environment.
[0068] In this embodiment, by assigning the domain name in the request to the domain name of the current environment, it is possible to test data under different request IPs according to the request IP domain name selected by the tester. Therefore, it is only necessary to package and install once to test data in different environments, avoiding the problem of repeatedly packaging and installing the application program to test different environments, thereby improving the efficiency of development and testing. By setting a dropdown box, the situation of entering an invalid domain name can be avoided. In addition, after directly assigning the domain name selected by the tester to the domain name of the current environment and then performing verification, the consistency of the data can be ensured. By outputting a test report, the test situation can be intuitively and clearly understood.
[0069] Embodiment 2
[0070] Figure 3 It is a flowchart schematically showing an application program testing method according to Embodiment 2 of the present invention.
[0071] In a first aspect, Embodiment 2 of the present invention provides an application program testing method, where the same or corresponding technical terms as those in the above embodiment will not be described in detail herein. As Figure 3 shown, the method of this Embodiment 2 includes:
[0072] S201. Obtain the domain name of the current environment.
[0073] S202. In response to receiving a test request, extract the domain name in the test request, verify the domain name in the test request. If the verification passes, replace the domain name of the current environment with the domain name in the test request to obtain a target environment.
[0074] In this embodiment, a page with a domain name input function can be set up, and users can enter the domain name of a certain environment to be tested in the input box according to their own needs. When a new environment appears, it can avoid the situation where the above-mentioned drop-down box does not add the corresponding domain name option for the new environment in time (according to different types of test requirements, corresponding test environments need to be set), and the flexibility is higher. Further, an input domain name memory function can also be set, that is, the entered domain name will be stored (the stored domain name must be a valid domain name). When entering again next time, the complete domain name will automatically pop up. For example, the stored historical domain names are www.xyyl.com and test.xyyl.com. When the user enters the first letter, for example, the user enters w, then "www.xyyl.com" will be automatically displayed. If the domain name matches the domain name the user wants, directly click on the domain name to replace the domain name, and there is no need to perform domain name validity verification again, thus improving the test efficiency. For multiple matched domain names, they can be sorted by input time. For example, the most recently used domain name is ranked first, or they can be sorted by usage frequency, and the domain name with the highest usage rate is ranked first. Among them, the usage rate of the domain name can be updated regularly. In this way, users can quickly find the domain names that have been entered and used. In an alternative embodiment, if multiple environments need to be tested, the domain names corresponding to multiple environments can be entered in the input box.
[0075] Further, when a test request from a tester is received, the domain name in the test request is extracted and the domain name in the test request is verified. Specifically, the verification includes: determining whether the domain name is empty and whether it contains valid domain name information. By checking whether the domain name is empty or conforms to the format specification of the domain name, it is determined whether the domain name in the test request is valid, avoiding the situation where the test fails due to using an invalid domain name.
[0076] When determining whether the entered domain name conforms to the format specification of the domain name, it includes: determining whether the domain name in the test request contains at least one dot and does not start or end with a dot; and determining whether the domain name in the test request only contains letters, numbers, dots, and hyphens. When it conforms to the corresponding format of the domain name, the domain name of the current environment is replaced with the domain name in the request. If the domain name is empty or an invalid domain name, a prompt indicating that the domain name is invalid is returned or it is set as the default domain name. By verifying the entered domain name, the situation where the server corresponding to the target environment cannot be accessed due to an invalid domain name is avoided, thus ensuring the continuity of the test.
[0077] In one embodiment, multiple domain names are entered in the above-mentioned input box, and the availability / validity of the candidate domain names is verified in sequence according to the preset priority order; the first candidate domain name that passes the verification is selected as the final replacement target. In an alternative embodiment, the verification can also be directly performed in the order entered by the tester, and the domain name switching is performed in the order of passing the verification. Specifically, after the current environment test is completed, the test of the environment corresponding to the next domain name can be automatically performed according to the order of passing the verification, so as to avoid the situation that when the user performs tests on multiple environments, after waiting for the current environment test to be completed, the user needs to manually enter the next domain name to be tested before the test of the next environment can be performed, thereby improving the efficiency of application program testing.
[0078] S203. Perform testing based on the target environment.
[0079] In one embodiment, before verifying the target environment, it further includes: verifying the correctness and availability of the target environment. Specifically, the verification includes: determining whether the IP of the target environment is accessible / reachable, and whether the domain name resolution correctly points to the IP of the target environment, etc. By verifying the target environment, it can be ensured that the entered domain name can be used normally, and the corresponding data can be obtained based on this target environment, which re-verifies the validity of the domain name, ensures the continuity of the test, and at the same time avoids problems that may be caused by incorrect domain name resolution.
[0080] The method of this embodiment can flexibly switch the test environment according to the domain name in the test request. The tester can easily test the data in different environments, meeting the diversified test requirements. At the same time, it avoids the problem of repeatedly packaging and installing the application program to test different environments, thereby improving the efficiency of development and testing. Further, by setting the input box, the domain name to be tested can be entered according to the actual needs of the user, with high flexibility; further, by verifying the entered domain name, the situation of entering invalid / wrong domain names can be avoided, ensuring the continuity of the test. In addition, through the automated domain name replacement and test process, the cumbersome process of manually reconfiguring the test environment is avoided, saving test time and labor costs.
[0081] Embodiment III
[0082] Figure 4 It is a schematic block diagram showing the structure of an application program test system according to Embodiment III of the present invention.
[0083] In a second aspect, the present invention further provides an application program test system. As Figure 4As shown, the application program testing system includes a processor and a memory. The memory stores computer program instructions, which, when executed by the processor, implement an application program testing method according to the first aspect of the present invention.
[0084] The application program testing system further includes a communication bus, a communication interface, and other components well-known to those skilled in the art. Their settings and functions are known in the art, so they will not be elaborated here.
[0085] In the present invention, the aforementioned memory can be any tangible medium that contains or stores a program, and this program can be used by or in combination with an instruction execution system, device, or component. For example, a computer-readable storage medium can be any suitable magnetic storage medium or magneto-optical storage medium, such as resistive random access memory (RRAM), dynamic random access memory (DRAM), static random access memory (SRAM), enhanced dynamic random access memory (EDRAM), high-bandwidth memory (HBM), hybrid memory cube (HMC), etc., or any other medium that can be used to store the required information and can be accessed by an application program, module, or both. Any such computer storage medium can be part of the device or accessible or connectable to the device. Any application or module described in the present invention can be implemented using computer-readable / executable instructions that can be stored or otherwise held by such a computer-readable medium.
[0086] In the description of this specification, the meanings of "a plurality of" and "several" are at least two, such as two, three, or more, unless otherwise specifically defined. In addition, the step division of the above method is only for clear description. When implemented, it can be combined into one step or some steps can be split into multiple steps, as long as the same logical relationship is included.
[0087] Although this specification has shown and described multiple embodiments of the present invention, it is obvious to those skilled in the art that such embodiments are provided by way of example only. Those skilled in the art will think of many changes, alterations, and alternative ways without departing from the spirit and idea of the present invention. It should be understood that various alternative solutions to the embodiments of the present invention described herein can be adopted in the process of practicing the present invention.
Claims
1. A method for testing an application program, characterized in that, It includes: Obtain the domain name of the current environment; In response to receiving a test request, extract the domain name in the test request, replace the domain name of the current environment with the domain name in the test request to obtain a target environment; wherein, before the replacement, verify the domain name in the test request, or after the replacement, verify the domain name of the target environment; Conduct tests based on the target environment.
2. The application program testing method according to claim 1, wherein After extracting the domain name in the test request, it further includes: In response to the extracted domain name including multiple candidate domain names, verify the candidate domain names in sequence according to a preset priority order; Select the first candidate domain name that passes the verification as the final replacement target.
3. The application program testing method according to claim 1, wherein Obtain the domain name of the current environment, including: obtaining the domain name of the current environment through system configuration, environment variables or by calling a preset interface.
4. The application program testing method according to claim 3, wherein Obtain the domain name of the current environment through the system configuration, including: obtaining the domain name of the current environment through BASEURL[XYUtility getBaseUrlString].
5. The application program testing method according to claim 1, wherein Verify the domain name in the test request, including: determining whether it contains valid domain name information.
6. The application program testing method according to claim 5, wherein Determine whether it contains valid domain name information, including: determining whether the domain name in the test request contains at least one dot and does not start or end with a dot; and determining whether the domain name in the test request only contains letters, numbers, dots and hyphens.
7. The application program testing method according to claim 1, characterized in that, Before extracting the domain name in the test request, it further includes: determining whether the source of the test request is legal.
8. The application program testing method according to claim 1, characterized in that Conduct tests based on the target environment, including: Send a series of preset test cases to the target environment; record the execution results of the test cases, the execution results including passing the test or failing the test; generate a test report according to the execution results.
9. The application program testing method according to claim 1, wherein It further includes: Verify the availability and correctness of the target environment.
10. An application testing system, characterized in that, It includes a processor and a memory, and the memory stores computer program instructions, which, when executed by the processor, implement an application program test method according to claims 1-9.
Citation Information
Patent Citations
Web test method, proxy server and Web test device
CN104009880A
Test method and electronic device
CN107402880A
Test environment switching method and device, electronic equipment and storage medium
CN113377678A
Method and device for controlling network environment switching and electronic equipment
CN114040025A