A project testing method, system, computer device and readable storage medium
By automatically obtaining and judging business requests and project configuration information, calling mock components to realize automated mock testing, solving the cumbersome problem of manually adding mock components in the existing technology, reducing error rates and testing costs, and improving testing efficiency and security.
Patent Information
- Application Number
- CN202411586456.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-08
- Publication Date
- 2025-03-21
- Estimated Expiration
- 2044-11-08
AI Technical Summary
The existing mock testing technology requires manual addition of mock components, which leads to cumbersome processes and increases error rates and labor costs.
Provides a project testing method, which automatically obtains business requests and project configuration information, judges legitimacy and calls mock components to realize automatic mock testing, reducing error rate and testing costs.
No need to manually add mock components to achieve automated mock testing, reducing error rates and testing costs, and improving testing efficiency and security.
Smart Images

Figure CN119088719B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a project testing method, system, computer device and readable storage medium. Background Art
[0002] In the existing mock testing technology, it is necessary to manually add mock components, which makes the process cumbersome and further increases the error rate and labor costs. Summary of the invention
[0003] In view of this, the embodiments of the present application provide a project testing method, system, computer device and readable storage medium, which can automatically implement mock testing and effectively reduce the error rate and testing cost.
[0004] In a first aspect, an embodiment of the present application provides a project testing method, comprising:
[0005] After the project is deployed, obtain business requests and project configuration information;
[0006] When the project configuration information is judged to be legitimate, whether the service request contains a preset mock field is judged;
[0007] If so, the mock component is called to enable the mock component to search for the corresponding test result according to the business request; and the test result is returned.
[0008] In some embodiments, the project construction process includes:
[0009] Obtain a project build script and extract an environment tag from the project build script;
[0010] When the environment is determined to be a test environment according to the environment tag, the dependency package and dependency configuration table of the project build script are obtained, and the corresponding mock component is searched according to the dependency package;
[0011] Add the mock component to the dependency configuration table to obtain a new dependency configuration table;
[0012] Build and deploy the project according to the new dependency configuration table.
[0013] In some embodiments, it also includes:
[0014] When the environment is determined to be a production environment according to the environment tag, the dependency package and dependency configuration table of the project build script are obtained, and the project is built and deployed according to the dependency configuration table.
[0015] In some embodiments, after constructing the project according to the new dependency configuration table, the method further includes:
[0016] The new dependency configuration table is rolled back to the dependency configuration table.
[0017] In some embodiments, the project configuration information includes an environment tag and a startup tag;
[0018] When the environment tag is a test environment and the startup tag is a startup field, it is determined that the project configuration information passes legality.
[0019] In some embodiments, before determining that the project configuration information is passed, the method further includes:
[0020] Obtain the first computer IP segment to which the project belongs when it is running, and the second computer IP segment that is currently online;
[0021] When the environment tag is a test environment, the startup tag is a startup field, and the first computer IP segment is different from the second computer IP segment, the project configuration information is passed.
[0022] In some embodiments, it also includes:
[0023] If not, the business logic processing unit is called to perform logic processing on the business request, obtain a calculation result, and return the calculation result.
[0024] In a second aspect, an embodiment of the present application provides a project testing system, including:
[0025] An acquisition unit, used to acquire business requests and project configuration information;
[0026] A judging unit, configured to judge whether the service request contains a preset mock field when judging that the project configuration information is passed;
[0027] The processing unit is configured to, if yes, call the mock component so that the mock component searches for the corresponding test result according to the business request; and return the test result.
[0028] In a third aspect, an embodiment of the present application provides a computer device, comprising a processor and a memory, wherein the memory stores a computer program, and the processor is used to execute the computer program to implement the above-mentioned project testing method.
[0029] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium storing a computer program, which, when executed on a processor, implements the above-mentioned project testing method.
[0030] The embodiments of the present application have the following beneficial effects:
[0031] The present application proposes a project testing method, which includes: after the project is deployed, obtaining the business request and project configuration information; when the project configuration information is judged to be legitimate, judging whether the business request contains a preset mock field; if so, calling the mock component so that the mock component searches for the corresponding test result according to the business request; and returning the test result. The present application does not need to manually add the mock component, and can automatically implement the mock test, effectively reducing the error rate and testing cost. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0033] Figure 1 A first schematic diagram of a process for constructing a project in a project testing method according to an embodiment of the present application is shown;
[0034] Figure 2 A second schematic diagram of a process for constructing a project in a project testing method according to an embodiment of the present application is shown;
[0035] Figure 3 A first schematic diagram of a process for testing a project according to an embodiment of the present application is shown;
[0036] Figure 4 A second flow chart of the project testing method according to an embodiment of the present application is shown;
[0037] Figure 5 A structural schematic diagram of a project testing system according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0038] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments.
[0039] The components of the embodiments of the present application generally described and shown in the drawings herein may be arranged and designed in various configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.
[0040] Hereinafter, the terms "including", "having" and their cognates that can be used in various embodiments of the present application are intended only to indicate specific features, numbers, steps, operations, elements, components or a combination of the foregoing items, and should not be understood as first excluding the existence of one or more other features, numbers, steps, operations, elements, components or a combination of the foregoing items or increasing the possibility of one or more features, numbers, steps, operations, elements, components or a combination of the foregoing items. In addition, the terms "first", "second", "third" and the like are only used to distinguish descriptions and cannot be understood as indicating or implying relative importance.
[0041] Unless otherwise defined, all terms (including technical terms and scientific terms) used herein have the same meanings as those generally understood by those skilled in the art to which the various embodiments of the present application belong. The terms (such as those defined in generally used dictionaries) will be interpreted as having the same meanings as the contextual meanings in the relevant technical field and will not be interpreted as having idealized meanings or overly formal meanings unless clearly defined in the various embodiments of the present application.
[0042] In conjunction with the accompanying drawings, some embodiments of the present application are described in detail below. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.
[0043] Mock is a simulation technology used to simulate components or functions of a system for testing at different stages of software development. During the development and testing process, some data is not easy to construct or obtain due to unstable environment or unfinished collaborative development colleagues. It is necessary to create a virtual object or data sample to assist development or testing. Reduce the dependence on collaborative modules and make development and testing more independent. The goal of mock is to create a virtual implementation to replace real components or services, so that developers can test specific parts of their code independently without being affected by other components. Mock plays an important role in unit testing, integration testing, and system testing, helping to improve the testability, maintainability, and reliability of the code.
[0044] Usually, in mock testing technology, you need to manually add mock components to perform testing, and after the test, you need to manually remove the mock components so that the project can be launched safely and stably. However, manual operation is not only inefficient, costly, and error-prone, but also may cause the mock components to be introduced into the production environment due to forgetting to remove their dependencies, thus bringing security risks.
[0045] Therefore, in order to solve the above problems, the present application proposes a project testing method.
[0046] The test method of this project is described below with reference to some specific embodiments.
[0047] The process from project construction to launch includes environment preparation, project construction, project deployment, project testing and project launch. Therefore, the process of project construction and project testing will be explained separately.
[0048] In some embodiments, Figure 1 As shown, the construction process of the project includes:
[0049] S101, obtaining a project construction script, and extracting an environment tag from the project construction script.
[0050] The project building process needs to be executed according to the previously created project building script, and the environment tag is extracted from the obtained project building script to determine whether the current production environment is a production environment. This is because mock data and mock objects are mainly used in the development and testing stages for simulation. In the actual production environment, after the built project system (that is, the above-mentioned project) goes online, real data and services need to be used to ensure the stability and accuracy of the project system.
[0051] S102: When it is determined as a test environment according to the environment tag, the dependency package and dependency configuration table of the project build script are obtained, and the corresponding mock component is searched according to the dependency package.
[0052] If the environment tag is used to determine the environment to be a test environment, it means that the currently built project needs to add mock dependencies. Therefore, you need to obtain the dependency packages in the project build script to find the corresponding mock components. This is because there are many types of mock components, such as dubbo framework, http framework, mq framework, etc. Therefore, you need to find the mock components of the corresponding types of dependency packages in the project build script.
[0053] Exemplarily, the corresponding mock component is obtained according to the package name keyword in the dependent package. Of course, this is only a way to obtain the corresponding mock component, and does not limit the way to obtain the mock component in this embodiment, and other ways of obtaining can also be used.
[0054] S103: Add the mock component to the dependency configuration table to obtain a new dependency configuration table.
[0055] S104: Build and deploy the project according to the new dependency configuration table.
[0056] In project construction, the dependency configuration table can not only manage the external libraries and modules required by the project, but also ensure the stability and maintainability of the project. By configuring dependencies reasonably, you can avoid version conflicts, simplify the construction process, and improve development efficiency. The project built according to the new dependency configuration table includes mock components, so that when the project needs to use mock components during the test process, it can be called automatically without manual addition, which improves the overall test efficiency and reduces labor costs.
[0057] In some embodiments, based on the above, Figure 2 As shown, it also includes:
[0058] S105: When the environment is determined to be a production environment according to the environment tag, the dependency package and dependency configuration table of the project build script are obtained, and the project is built and deployed according to the dependency configuration table.
[0059] When it is determined to be a production environment, the build and deployment are performed directly according to the dependency packages and dependency configuration table of the project build script, without adding mock components to the dependency configuration table.
[0060] Exemplarily, the environment build tag may be "buildEnv". If buildEnv=pro, it means that the current project needs to be used in a production environment rather than a test environment, and there is no need to use mock components, that is, there is no need to build the project based on the dependencies of the mock components.
[0061] After the project is built, Figure 3 A flow chart of a project testing method according to an embodiment of the present application is shown. Exemplarily, the project testing method includes the following steps:
[0062] S110: After the project is deployed, obtain the business request and project configuration information.
[0063] During the testing process, data needs to be acquired according to the business requests corresponding to the project to complete the testing process.
[0064] Exemplarily, if the project is a shopping system, the business request may be a request to obtain user shopping data.
[0065] S210: When the project configuration information is judged to be legitimate, determine whether the service request contains a preset mock field.
[0066] During the test process, the legitimacy verification of the project configuration information is to ensure that the current project is in the test environment to avoid security issues in the project. The business request will contain a preset mock field to instruct the test system to call the mock component according to the preset mock field to complete the test process.
[0067] S310: If yes, call the mock component to make the mock component search for the corresponding test result according to the business request; and return the test result.
[0068] If the business request contains a preset mock field, it means that the current business request is a test request and the mock component needs to be called to complete the test.
[0069] In some embodiments, based on the above-mentioned project testing method, Figure 4 As shown, the project testing method also includes:
[0070] S410: If not, call the business logic processing unit to perform logic processing on the business request, obtain a calculation result, and return the calculation result.
[0071] The main purpose of the test process is to verify whether the logic of the code is correct. If the process being tested does not rely on external systems or uncontrollable factors (i.e. complex environment), logical processing can be performed directly. If the received business request does not contain the preset mock field, it means that the business request is not a test request or a test request that does not require a mock component. At this time, you only need to call the business logic processing unit to perform logical processing on the business request.
[0072] Exemplarily, if only simple addition and subtraction operations need to be performed on part of the received data, there is no need to use the mock component, and the corresponding addition and subtraction can be performed directly, and the result can be returned. Of course, this is just an example and does not impose any limitation on this embodiment.
[0073] In some implementations, based on the above, after building the project according to the new dependency configuration table, the project testing method further includes:
[0074] The new dependency configuration table is rolled back to the dependency configuration table.
[0075] After the test is completed, the project needs to be launched to enter the production environment, so the mock component dependency in the dependency configuration table needs to be removed. This implementation method removes the dependency in the new dependency configuration table by rolling back, that is, rolling back the new dependency configuration table to the dependency configuration table without adding the mock component.
[0076] Exemplarily, if the version of the dependency configuration table before adding the mock component is 1.0.0, and the version of the new dependency configuration table after adding the mock component is 1.0.1, the dependency configuration table with version 1.0.1 needs to be rolled back to the dependency configuration table with version 1.0.0.
[0077] In some implementations, based on the above, the project configuration information includes an environment tag and a startup tag.
[0078] When the environment tag is a test environment and the startup tag is a startup field, it is determined that the project configuration information passes legality.
[0079] Project configuration information is some information that is preset and configured in the project system. In order to protect the stability and accuracy of the project system operation, it is necessary to judge the preset mock fields of the business request and verify the various tags in the project configuration information to achieve multiple levels of control. In the actual environment, the project system may be in the testing stage or the production environment stage for various reasons. Therefore, in addition to judging whether the business request contains the preset mock fields, the legality verification of the project configuration information is also added to perform multiple verifications in order to ensure the stable and safe operation of the project system.
[0080] Project configuration information includes environment tags and startup tags. When the project needs to be in a test environment (i.e., non-production environment), the environment tag will be configured as a non-environment tag in advance, and the startup tag will be set to the startup field (i.e., starting the test environment) for multiple verifications to ensure that the current project system is in the test environment. When the project needs to be in a production environment, the environment tag will be configured as an environment tag in advance, and the startup tag will be set to the non-startup field (i.e., not starting the test environment) for multiple verifications to ensure that the current project system is in the production environment.
[0081] In some implementations, based on the above, before determining that the project configuration information passes, the project testing method further includes:
[0082] Get the first computer IP segment to which the project belongs when it is running, and the second computer IP segment that is currently online.
[0083] When the environment tag is a test environment, the startup tag is a startup field, and the first computer IP segment is different from the second computer IP segment, the project configuration information is passed.
[0084] In addition to the above-mentioned environment tag and startup tag verification, you can also perform computer IP verification as an additional layer of insurance. Generally, the computer IP segment of the production environment is different from the computer IP segment of the non-production environment. Therefore, you can also verify based on the computer IP segment. When the project is running, if the first computer IP segment and the second computer IP segment currently online are different, it means that the current project is in a test environment (that is, a non-production environment), which means that the verification has passed. When the first computer IP segment and the second computer IP segment currently online are the same when the project is running, it means that the current project is in a production environment, which means that the verification has failed.
[0085] The present application proposes a project testing method, which includes: after the project is deployed, obtaining the business request and project configuration information; when the project configuration information is judged to be legitimate, judging whether the business request contains a preset mock field; if so, calling the mock component so that the mock component searches for the corresponding test result according to the business request; and returning the test result. The present application does not need to manually add the mock component, and can automatically implement the mock test, effectively reducing the error rate and testing cost.
[0086] This application solution does not require R&D personnel to consider the details of mock component access. It can automatically identify and rely on specific mock components, realize automated mock component testing capabilities, and is more convenient to use and more efficient. In addition, this application solution also has high security. By isolating the online and offline environments during construction and rolling back the dependency configuration after the construction is complete, the security of the use of mock components is greatly guaranteed. Multi-dimensional and multi-judgment at runtime further ensures that mock components can only run in offline environments (non-production environments).
[0087] In addition, the expansion and upgrade of the mock components in the present application solution are completely controlled by automated scripts, which is completely transparent to the application system and has high maintainability.
[0088] Another embodiment of the present application also provides a project testing system 500, such as Figure 5 As shown, the project test system 500 includes:
[0089] The acquisition unit 510 is used to acquire the service request and project configuration information.
[0090] The judging unit 520 is configured to judge whether the service request contains a preset mock field when judging that the project configuration information is passed.
[0091] The processing unit 530 is configured to call the mock component to enable the mock component to search for the corresponding test result according to the business request, and return the test result.
[0092] It can be understood that the project testing system of this embodiment corresponds to the project testing method of the above embodiment, and the optional items in the above embodiment are also applicable to this embodiment, so they will not be described repeatedly here.
[0093] Another embodiment of the present application further provides a computer device, which includes a processor and a memory, wherein the memory stores a computer program, and the processor is used to execute the computer program to implement the above-mentioned project testing method.
[0094] Among them, the processor can be an integrated circuit chip with signal processing capabilities. The processor can be a general-purpose processor, including a central processing unit (CPU), a graphics processing unit (GPU), a network processor (NP), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or at least one of other programmable logic devices, discrete gates or transistor logic devices, and discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc., which can implement or execute the methods, steps and logic block diagrams disclosed in the embodiments of the present application.
[0095] The memory may be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electric erasable programmable read-only memory (EEPROM), etc. The memory is used to store a computer program, and the processor may execute the computer program accordingly after receiving an execution instruction.
[0096] The present application also provides a computer-readable storage medium storing a computer program, wherein when the computer program is executed on a processor, the above-mentioned project testing method is implemented. For example, the computer-readable storage medium may include, but is not limited to, various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0097] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and structure diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in an alternative implementation, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the structure diagram and / or the flow diagram, and the combination of boxes in the structure diagram and / or the flow diagram, can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0098] In addition, the functional modules or units in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0099] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a smart phone, a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application.
[0100] The above description is only a specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application.
Claims
1. A project testing method, characterized in that: include: After the project is deployed, obtain business requests and project configuration information; When the project configuration information is judged to be legitimate, whether the service request contains a preset mock field is judged; If yes, calling the mock component so that the mock component searches for the corresponding test result according to the business request; and returns the test result; The build process of the project includes: Obtain a project build script and extract an environment tag from the project build script; When the environment is determined to be a test environment according to the environment tag, the dependency package and dependency configuration table of the project build script are obtained, and the corresponding mock component is searched according to the dependency package; Add the mock component to the dependency configuration table to obtain a new dependency configuration table; Build and deploy the project according to the new dependency configuration table; The project configuration information includes an environment tag and a startup tag; When the environment tag is a test environment and the startup tag is a startup field, it is determined that the project configuration information is legal; Before the determining of the legitimacy of the project configuration information is passed, the method further includes: Obtain the first computer IP segment to which the project belongs when it is running, and the second computer IP segment that is currently online; When the environment tag is a test environment, the startup tag is a startup field, and the first computer IP segment is different from the second computer IP segment, the project configuration information passes legality.
2. The project testing method according to claim 1, characterized in that: Also includes: When the environment is determined to be a production environment according to the environment tag, the dependency package and dependency configuration table of the project build script are obtained, and the project is built and deployed according to the dependency configuration table.
3. The project testing method according to claim 1, characterized in that: After the project is constructed according to the new dependency configuration table, the method further includes: The new dependency configuration table is rolled back to the dependency configuration table.
4. The project testing method according to claim 1, characterized in that: Also includes: If not, the business logic processing unit is called to perform logic processing on the business request, obtain a calculation result, and return the calculation result.
5. A project testing system, characterized in that: include: An acquisition unit, used to acquire business requests and project configuration information; A judging unit, configured to judge whether the service request contains a preset mock field when judging that the project configuration information is passed; a processing unit, configured to, if yes, call a mock component so that the mock component searches for a corresponding test result according to the business request; and returns the test result; The build process of the project includes: Obtain a project build script and extract an environment tag from the project build script; When the environment is determined to be a test environment according to the environment tag, the dependency package and dependency configuration table of the project build script are obtained, and the corresponding mock component is searched according to the dependency package; Add the mock component to the dependency configuration table to obtain a new dependency configuration table; Build and deploy the project according to the new dependency configuration table; The project configuration information includes an environment tag and a startup tag; When the environment tag is a test environment and the startup tag is a startup field, it is determined that the project configuration information is legal; Before the determining of the legitimacy of the project configuration information is passed, the method further includes: Obtain the first computer IP segment to which the project belongs when it is running, and the second computer IP segment that is currently online; When the environment tag is a test environment, the startup tag is a startup field, and the first computer IP segment is different from the second computer IP segment, the project configuration information passes legality.
6. A computer device, characterized in that: The computer device comprises a processor and a memory, wherein the memory stores a computer program, and the processor is configured to execute the computer program to implement the project testing method according to any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that: The computer program is stored therein, and when the computer program is executed on a processor, the project testing method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Dubbo service test method, device and equipment
CN111966591A