Code increment testing method and device, computer equipment and storage medium
The Git Diff command detects the code base changes and filters incremental Java files, and performs unit tests in combination with the Maven project structure, which solves the problem of too long unit testing in bank wealth management software development, and achieves rapid iteration and efficient development.
Patent Information
- Application Number
- CN202411363614.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-27
- Publication Date
- 2025-01-14
AI Technical Summary
In bank wealth management software development, due to functional complexity and business diversity, the large number of unit test cases has led to a significant increase in unit test execution time in the agile development environment, which violates the goals of fast feedback and continuous integration.
Use Git Diff command to detect the changes in the code base since the last successful construction, obtain incremental Java files, filter out the source code classes that need to be tested, determine the unit test classes based on the Maven project structure, and build and execute unit test commands to achieve the target software incremental test.
It effectively reduces the execution time of unit tests during target software iteration, speeds up the development process, and improves development efficiency.
Smart Images

Figure CN119311585A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data R&D management technology, and is applied to software code incremental testing scenarios related to financial services. In particular, the present invention relates to a code incremental testing method, device, computer equipment, and non-volatile computer-readable storage medium. Background Art
[0002] At present, with the rapid development of information technology, the development of software related to bank financial management has received increasing attention. These software not only carry huge capital flows and information flows, but are also directly related to the security and efficiency of financial transactions. Therefore, the delivery quality and operational stability of software have become key indicators to measure its success. In this context, software development quality control has become particularly important.
[0003] In the process of software development, unit testing is a basic method to verify code quality. It ensures the correctness and robustness of the code by checking and verifying the smallest code module. However, in the development of bank financial management software, due to the complexity of functions and the diversity of business, the number of unit test cases is often very large. In the environment of agile development, rapid iteration has become the norm. The accumulation of unit test cases will lead to a significant increase in the time of full execution, which is contrary to the goal of rapid feedback and continuous integration pursued by agile development.
[0004] Based on this, how to provide a code incremental testing method, device, computer equipment and non-volatile computer-readable storage medium that can effectively reduce the execution time of unit testing during target software iteration and speed up the development process is a problem that needs to be urgently solved by technical personnel in this field. Summary of the invention
[0005] In view of the above-mentioned deficiencies in the prior art, the purpose of the present invention is to provide a code incremental testing method, apparatus, computer equipment and non-volatile computer-readable storage medium that can be used in financial technology or other related fields, aiming to solve the problem of how to effectively reduce the execution time of unit tests during target software iterations and speed up the development process.
[0006] In order to achieve the above object, the present invention adopts the following technical solutions:
[0007] A code incremental testing method, comprising:
[0008] Use the Git Diff command to detect changes in the target software's code base since the last successful build;
[0009] Based on the detection result of the change of the code base, obtaining the incremental Java file of the code base;
[0010] Filter out target source code classes that need to be unit tested from the incremental Java files;
[0011] Determine the unit test class corresponding to the target source code class according to the standard Maven project structure;
[0012] A unit test command is constructed according to the unit test class, and the unit test command is executed to implement incremental testing of the target software.
[0013] In a further technical solution, the code increment testing method, wherein the use of the Git Diff command to detect changes in the code base of the target software since the most recent successful build, includes:
[0014] Determine the baseline commit version of the target software's code base since the most recent successful build;
[0015] Based on the baseline submission version, the Git Diff command is used to detect changes in the code base since the most recent successful build, and a change detection result of the code base is generated.
[0016] In a further technical solution, the code incremental testing method, wherein the step of obtaining the incremental Java file of the code library based on the change detection result of the code library, comprises:
[0017] According to the change detection result of the code base obtained by executing the Git Diff command, the files with the extension .java are screened out;
[0018] The filtered files with an extension of .java are sorted to obtain incremental Java files of the code base.
[0019] In a further technical solution, the incremental code testing method, wherein the step of screening out target source code classes that need to be unit tested from the incremental Java files, comprises:
[0020] Get the filtering rules for incremental code;
[0021] The target source code classes that need to be unit tested are filtered out from the incremental Java files according to the filtering rules.
[0022] In a further technical solution, the code incremental testing method, wherein the step of determining the unit test class corresponding to the target source code class according to the standard Maven project structure, comprises:
[0023] According to the standard Maven project structure, find the path and name corresponding to the target source code class;
[0024] Based on the path and name corresponding to the target source code class, a unit test class corresponding to the target source code class is determined.
[0025] In a further technical solution, the code incremental testing method, wherein the step of constructing a unit test command according to the unit test class and executing the unit test command to implement the incremental testing of the target software, comprises:
[0026] Construct a unit test command according to the unit test class;
[0027] In a pre-configured test environment, the unit test command is executed to implement incremental testing of the target software and generate corresponding test results.
[0028] In a further technical solution, the code incremental testing method, wherein, after executing the unit test command in a pre-configured test environment to implement the incremental testing of the target software and generating corresponding test results, further comprises:
[0029] Analyze the test results to generate corresponding analysis results;
[0030] Based on the analysis results, the incremental testing process of the target software is optimized.
[0031] A code increment testing device, comprising:
[0032] The detection module is used to use the Git Diff command to detect changes in the target software's code base since the last successful build;
[0033] An acquisition module, used for acquiring incremental Java files of the code base based on the detection result of the change of the code base;
[0034] A screening module is used to screen out target source code classes that need to be unit tested from the incremental Java files;
[0035] A determination module is used to determine the unit test class corresponding to the target source code class according to the standard Maven project structure;
[0036] A testing module is used to construct a unit testing command according to the unit testing class, and execute the unit testing command to implement incremental testing of the target software.
[0037] A computer device, wherein the computer device comprises at least one processor; and
[0038] a memory communicatively connected to the at least one processor; wherein,
[0039] The memory stores a computer program that can be executed by the at least one processor. When the computer program is executed by the at least one processor, the code increment testing method as described in any one of the above items can be implemented.
[0040] A non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by at least one processor, it can implement the code increment testing method as described in any one of the above items.
[0041] Compared with the prior art, the present invention provides a code incremental testing method, device, computer equipment and non-volatile computer-readable storage medium, wherein the method includes: using the Git Diff command to detect the changes in the code base of the target software since the most recent successful build; based on the detection results of the changes in the code base, obtaining the incremental Java files of the code base; filtering out the target source code class that needs to be unit tested from the incremental Java files; determining the unit test class corresponding to the target source code class according to the standard Maven project structure; constructing a unit test command according to the unit test class, and executing the unit test command to implement the incremental testing of the target software. In this way, the method of the present invention can effectively reduce the execution time of the unit test when the target software is iterated by unit testing only the incremental code of the target software instead of the entire code base, and can speed up the development process. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0043] Figure 1 A flowchart of a code incremental testing method provided by an embodiment of the present invention.
[0044] Figure 2 A schematic diagram of functional modules of a code increment testing device provided in an embodiment of the present invention.
[0045] Figure 3 A schematic diagram of the hardware structure of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical solution and effect of the present invention clearer and more specific, the present invention is further described in detail with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0047] In the description of the present invention, the terms "include", "including", "have", "contain", etc. are all open terms, which mean including but not limited to. The descriptions with reference to the terms "one embodiment", "a specific embodiment", "some embodiments", "for example", etc. mean that the specific features, structures or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures or characteristics described may be combined in a suitable manner in any one or more embodiments or examples. The order of steps involved in each embodiment is used to schematically illustrate the implementation of the present application, and the order of steps therein is not limited and can be appropriately adjusted as needed.
[0048] Various non-limiting embodiments of the present invention are described in detail below in conjunction with the accompanying drawings.
[0049] At present, with the rapid development of information technology, the development of software related to bank financial management has received increasing attention. These software not only carry huge capital flows and information flows, but are also directly related to the security and efficiency of financial transactions. Therefore, the delivery quality and operational stability of software have become key indicators to measure its success. In this context, software development quality control has become particularly important.
[0050] In the process of software development, unit testing is a basic method to verify code quality. It ensures the correctness and robustness of the code by checking and verifying the smallest code module. However, in the development of bank financial management software, due to the complexity of functions and the diversity of business, the number of unit test cases is often very large. In the environment of agile development, rapid iteration has become the norm. The accumulation of unit test cases will lead to a significant increase in the time of full execution, which is contrary to the goal of rapid feedback and continuous integration pursued by agile development.
[0051] Based on this, how to provide a code incremental testing method, device, computer equipment and non-volatile computer-readable storage medium that can effectively reduce the execution time of unit testing during target software iteration and speed up the development process is a problem that needs to be urgently solved by technical personnel in this field.
[0052] To solve the above problems, see Figure 1The embodiment of the present invention provides a code increment testing method, wherein the method comprises the steps of:
[0053] S100, using the Git Diff command to detect changes in the code base of the target software since the most recent successful build;
[0054] S200, based on the detection result of the change of the code base, obtaining the incremental Java file of the code base;
[0055] S300, filtering out target source code classes that need to be unit tested from the incremental Java files;
[0056] S400, determining the unit test class corresponding to the target source code class according to the standard Maven project structure;
[0057] S500. Construct a unit test command according to the unit test class, and execute the unit test command to implement incremental testing of the target software.
[0058] Furthermore, the code increment testing method, wherein the step S100, using the Git Diff command to detect changes in the code base of the target software since the most recent successful build, specifically includes:
[0059] Determine the baseline commit version of the target software's code base since the most recent successful build;
[0060] Based on the baseline submission version, the Git Diff command is used to detect changes in the code base since the most recent successful build, and a change detection result of the code base is generated.
[0061] In the specific implementation, in this embodiment, the baseline submission version of the code base of the target software since the most recent successful build is determined; based on the baseline submission version, the Git Diff command is used to detect the changes of the code base since the most recent successful build, and the change detection result of the code base is generated; wherein, the specific implementation process is roughly as follows:
[0062] 1) Determine the baseline submission version
[0063] Find the most recent successful build: First, you need to determine the baseline commit version of the target software's code base since the most recent successful build. This can usually be found through the history of the continuous integration (CI) system, or by manually checking the most recent successful build record.
[0064] Among them, Continuous Integration (CI) is a software development practice. Its core idea is that developers frequently merge code changes into the main branch. Each code merge is verified through automated building and testing to verify whether the new code is well integrated, so as to find and solve problems early. The purpose of CI is to reduce integration problems in software development, improve code quality, and speed up development.
[0065] The key components of CI include:
[0066] 1. Version control system: usually Git, used to manage code changes and history;
[0067] 2. Build server: One or more servers that monitor changes to the code base and automatically execute the build and test process;
[0068] 3. Build tools: such as Maven, Gradle, Ant, etc., used to compile code, package, run tests, etc.;
[0069] 4. Testing: Automated testing, including unit testing, integration testing, etc., to ensure the quality of the code;
[0070] 5. Report: The results of building and testing will generate reports for developers to view and analyze;
[0071] 6. Deployment: After the build is successful, it can be automatically deployed to the test environment or production environment;
[0072] The CI workflow usually includes:
[0073] 1. Code submission: Developers submit code changes to the version control system;
[0074] 2. Trigger build: Code submission triggers the build process on the build server;
[0075] 3. Automated build: The build server pulls the latest code and executes the build script;
[0076] 4. Run the test: After the build is successful, the test case will be automatically run;
[0077] 5. Result feedback: The test results will be fed back to the developer. If the test fails, the developer needs to fix the problem and resubmit;
[0078] 6. Deployment: After the test passes, it can be automatically deployed to the corresponding environment;
[0079] Benefits of CI:
[0080] 1. Early detection of defects: Through frequent integration and testing, errors can be discovered and fixed early;
[0081] 2. Reduce risks: Reduce conflicts and integration issues when merging code;
[0082] 3. Improve productivity: Automated processes allow developers to focus on coding rather than manual building and testing;
[0083] 4. Continuous delivery: CI is the basis for achieving continuous delivery and continuous deployment (CD);
[0084] The CI system provides powerful tools and plug-ins to support automated build, test, and deployment processes;
[0085] Among them, the Git Diff command is a tool used to compare file differences in the Git version control system. It can show the differences between two commits, two branches, a commit and the working directory, or the working directory and the staging area. In short, the Git Diff command is used to view the changes of files or directories in different versions or states.
[0086] 2) Execute the Git Diff command
[0087] Based on the baseline commit version, use the Git Diff command to detect changes in the code base since the last successful build;
[0088] 3) Analyze changes
[0089] Filter related files: Filter files related to the target software from the output of the Git Diff command, such as source code files, configuration files, etc.
[0090] Record change details: Record the changes of each file in detail, including the file name, number of changed lines, type of change (addition, deletion, modification), etc.
[0091] 4) Generate change detection results:
[0092] Formatted output: Format the analyzed changes into a format that is easy to read and process, such as JSON, XML, or a simple text report;
[0093] Storing results: Store the generated change detection results in an appropriate location so that they can be easily accessed and used for subsequent testing and analysis work;
[0094] Through the above process, this embodiment can accurately determine the changes in the code base of the target software since the most recent successful build, and provide necessary information for subsequent incremental testing and code review.
[0095] Furthermore, the code incremental testing method, wherein the step S200, based on the change detection result of the code library, obtains the incremental Java file of the code library, specifically includes:
[0096] According to the change detection result of the code base obtained by executing the Git Diff command, the files with the extension .java are screened out;
[0097] The filtered files with an extension of .java are sorted to obtain incremental Java files of the code base.
[0098] In the specific implementation, in this embodiment, according to the change detection result of the code base obtained by executing the Git Diff command, the files with the extension .java are screened out; the screened files with the extension .java are sorted out to obtain the incremental Java files of the code base; wherein the specific implementation process is roughly as follows:
[0099] 1) Filter files
[0100] Analyze the output of the Git Diff command and filter out all files with the extension .java;
[0101] 2) Organize files
[0102] Sort the filtered files with the extension .java, remove duplicates, and sort or classify them as needed. This can be done by using text processing tools or writing simple scripts to get the incremental Java files of the code base.
[0103] Through the above process, this embodiment can effectively filter and sort out incremental Java files from the output of the Git Diff command, providing accurate input for subsequent testing and analysis work.
[0104] Furthermore, the code incremental testing method, wherein the step S300, screening out the target source code class that needs to be unit tested from the incremental Java file, specifically includes:
[0105] Get the filtering rules for incremental code;
[0106] The target source code classes that need to be unit tested are filtered out from the incremental Java files according to the filtering rules.
[0107] In the specific implementation, in this embodiment, the filtering rules of the incremental code are obtained; the target source code class that needs to be unit tested is filtered out from the incremental Java file according to the filtering rules; wherein the specific implementation process is roughly as follows:
[0108] 1) Define filtering rules
[0109] Determine which conditions will be used to filter the target source code classes that need to be unit tested; these rules may be based on the file path, the file's modified content, the file's historical change frequency, code complexity, or other criteria;
[0110] For example, rules may include: selecting only files with more than 10 lines modified, or selecting files under a specific directory (such as a directory containing core business logic);
[0111] 2) Get filtering rules
[0112] Pipe the output of the Git Diff command to a script or tool that filters the incremental Java files according to the defined filtering rules;
[0113] For example, you can use a Shell script or Python script to analyze incremental Java files and filter them based on rules (such as file size, number of modified lines, specific directories, etc.);
[0114] 3) Generate screening results
[0115] Output the target source code class that needs to be unit tested after screening to a file or variable for use in subsequent steps;
[0116] For example, the screening results can be saved to a text file or kept as a list variable in a script;
[0117] 5) Verify screening results
[0118] Check the screening results to ensure that all target source code classes that need to be unit tested are correctly identified and included;
[0119] You can check manually or write additional scripts to automate the verification process to ensure that no important changed files are missed;
[0120] Through the above process, this embodiment can ensure that only the target source code classes that really need to be tested are selected for unit testing, thereby improving the efficiency and effectiveness of the test.
[0121] Furthermore, in the code incremental testing method, the step S400, determining the unit test class corresponding to the target source code class according to the standard Maven project structure, specifically includes:
[0122] According to the standard Maven project structure, find the path and name corresponding to the target source code class;
[0123] Based on the path and name corresponding to the target source code class, a unit test class corresponding to the target source code class is determined.
[0124] In the specific implementation, in this embodiment, according to the standard Maven project structure, the path and name corresponding to the target source code class are searched; based on the path and name corresponding to the target source code class, the unit test class corresponding to the target source code class is determined; wherein the specific implementation process is roughly as follows:
[0125] 1) Identify the target source class path and name
[0126] Browse or search for the src / main / java directory, which is the standard location for storing Java source code in Maven projects;
[0127] Record the full package path and class name of the target source code class that needs to be unit tested; for example, a target source code class may be located in the com.example.project package and the class name may be MyClass;
[0128] Among them, Maven is a widely used project management and understanding tool, mainly for Java projects; it is based on the Project Object Model (POM) and is used to manage project builds, reports, and documents; Maven's main features include:
[0129] 1. Dependency management: automatically handle project dependencies to ensure that the libraries and frameworks required by the project can be automatically downloaded and updated;
[0130] 2. Project construction: Provide standardized project construction process, including compilation, testing, packaging and deployment;
[0131] 3. Consistency: Ensure consistency in project structure and build process by using the principle of convention over configuration;
[0132] 4. Plugins and targets: A rich plugin ecosystem that supports various build extensions, such as code generation, test coverage reporting, etc.
[0133] 5. Project information: manage project information, such as version number, developer information, license, etc.;
[0134] 6. Inheritance and aggregation: Supports project inheritance and multi-module project aggregation, facilitating the organization and management of large projects;
[0135] 7. Cross-platform: can run on multiple operating systems, such as Windows, Linux and macOS;
[0136] Maven is one of the indispensable tools in Java development. It helps developers standardize the build process, simplify project management, and improve development efficiency.
[0137] 2) Build the expected path and name of the unit test class
[0138] According to the Maven project structure, unit test classes are usually located in the src / test / java directory and match the package structure of the target source code class;
[0139] Construct the expected name of the unit test class, usually using the naming convention of <target source code class name> Test; for example, the test class of MyClass may be MyClassTest;
[0140] 3) Verify the existence of the test class
[0141] In the src / test / java directory, find the corresponding unit test class file according to the expected path and name of the build;
[0142] Check if these files exist, and if so, confirm that they are up to date and match the target source classes;
[0143] 4) Automate the search process (optional)
[0144] Write a script (such as a Shell script or Python script) to automate the search process; the script can traverse the source code files in the src / main / java directory and build the corresponding test class path and name;
[0145] The script can also check whether the corresponding test class files exist in the src / test / java directory and report the missing test classes;
[0146] Through the above process, this embodiment can systematically find the corresponding unit test class from the target source code class and prepare for executing the unit test; this process helps to ensure the integrity and accuracy of the unit test and is an important part of continuous integration and continuous testing.
[0147] Further, the code incremental testing method, wherein the step S500, constructing a unit test command according to the unit test class, and executing the unit test command to implement the incremental testing of the target software, specifically includes:
[0148] Construct a unit test command according to the unit test class;
[0149] In a pre-configured test environment, the unit test command is executed to implement incremental testing of the target software and generate corresponding test results.
[0150] Furthermore, the code incremental testing method, wherein, after executing the unit test command in a preconfigured test environment to implement the incremental testing of the target software and generating corresponding test results, further comprises:
[0151] Analyze the test results to generate corresponding analysis results;
[0152] Based on the analysis results, the incremental testing process of the target software is optimized.
[0153] In the specific implementation, in this embodiment, a unit test command is constructed according to the unit test class; in a pre-configured test environment, the unit test command is executed to implement the incremental test of the target software and generate corresponding test results; the test results are analyzed to generate corresponding analysis results; based on the analysis results, the incremental test process of the target software is optimized; wherein the specific implementation process is roughly as follows:
[0154] 1) Build unit test command
[0155] Determine the test class: Identify the unit test class that needs to be tested based on the source code changes;
[0156] Build command: Use Maven or other test frameworks to build test commands; for example, using Maven, you can use mvn test Dtest= <testclassname>The command specifies a specific test class;
[0157] 2) Configure the test environment
[0158] Environment preparation: Ensure that the test environment has been configured, including the database, simulation of external services, necessary libraries and tools;
[0159] Dependency installation: Ensure that all test dependencies are correctly installed using Maven's install or dependency:resolve command;
[0160] 3) Execute unit test commands
[0161] Run tests: Execute the built unit test commands in the test environment; this is usually done from the command line or automatically by a continuous integration (CI) tool;
[0162] Monitor progress: Monitor the progress and status of test execution in real time to ensure smooth testing;
[0163] 4) Collect and analyze test results
[0164] Result collection: After the test is completed, collect the test results, including test coverage, successful and failed test cases;
[0165] Result analysis: Analyze the test results to determine whether the test passed, identify failed test cases, and analyze the reasons for failure;
[0166] 5) Optimize the testing process
[0167] Identify improvement points: Based on the analysis of test results, identify bottlenecks and deficiencies in the testing process;
[0168] Adjust test strategy: Based on the analysis results, adjust test cases, test environment configuration or test execution strategy to improve test efficiency and coverage;
[0169] Implementation improvements: Implement necessary code refactoring, add or modify test cases, and optimize the test environment;
[0170] 6) Recording and feedback
[0171] Documentation: Record test results and optimization measures in project documents for reference by team members;
[0172] Team feedback: Feedback test results and improvement suggestions to the development team to promote communication and collaboration among teams;
[0173] Through the above process, this embodiment can ensure the effective execution of incremental testing of the target software, and continuously optimize the testing process according to the test results, thereby improving software quality and development efficiency.
[0174] It can be seen from the above method embodiments that the code incremental testing method provided by the present invention includes: using the Git Diff command to detect the changes in the code base of the target software since the most recent successful build; based on the detection results of the changes in the code base, obtaining the incremental Java files of the code base; screening out the target source code class that needs to be unit tested from the incremental Java files; determining the unit test class corresponding to the target source code class according to the standard Maven project structure; constructing a unit test command according to the unit test class, and executing the unit test command to implement the incremental testing of the target software. In this way, the method of the present invention can effectively reduce the execution time of the unit test when the target software is iterated by unit testing only the incremental code of the target software instead of the entire code base, and can speed up the development process.
[0175] It should be understood that, although the present application provides method operation steps as described in the embodiments or flowcharts, more or less operation steps may be included based on conventional or non-creative labor, and these operation steps are not necessarily performed in sequence according to the embodiment or flowchart. The order of steps listed in the embodiment or flowchart is only one way of executing the order of many steps, and does not represent the only execution order. It should be noted that there is not necessarily a certain order between the above steps. A person of ordinary skill in the art can understand from the description of the embodiment of the present invention that in different embodiments, the above steps may have different execution orders, that is, they may be executed in parallel, or they may be executed in exchange, etc. Moreover, at least a part of the steps in the embodiment or flowchart may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but may be executed at different times, and the execution order of these sub-steps or stages is not necessarily performed in sequence, but may be executed in turn, alternately or synchronously with other steps or at least a part of the sub-steps or stages of other steps.
[0176] Based on the above method embodiment, please refer to Figure 2 Another embodiment of the present invention further provides a code increment testing device, wherein the device comprises:
[0177] A detection module 11 is used to detect changes in the code base of the target software since the last successful build using the Git Diff command;
[0178] An acquisition module 12 is used to acquire incremental Java files of the code base based on the detection result of the change of the code base;
[0179] A screening module 13 is used to screen out target source code classes that need to be unit tested from the incremental Java files;
[0180] A determination module 14 is used to determine the unit test class corresponding to the target source code class according to a standard Maven project structure;
[0181] The testing module 15 is used to construct a unit testing command according to the unit testing class, and execute the unit testing command to implement the incremental testing of the target software.
[0182] Furthermore, in the code increment testing device, the detection module 11 specifically includes:
[0183] A version determination unit, which is used to determine the baseline submission version of the target software's code base since the most recent successful build;
[0184] The detection unit is used to detect the changes of the code base since the most recent successful build based on the baseline submission version using the Git Diff command, and generate a change detection result of the code base.
[0185] Furthermore, in the code increment testing device, the acquisition module 12 specifically includes:
[0186] A file screening unit, configured to screen out files with a .java extension according to a detection result of a change in the code base obtained by executing the Git Diff command;
[0187] The file sorting unit is used to sort the filtered files with extensions of .java to obtain incremental Java files of the code base.
[0188] Furthermore, in the code increment testing device, the screening module 13 specifically includes:
[0189] A rule acquisition unit, used to acquire filtering rules for incremental codes;
[0190] The source code screening unit is used to screen out target source code classes that need to be unit tested from the incremental Java files according to the filtering rules.
[0191] Furthermore, in the code increment testing device, the determination module 14 specifically includes:
[0192] A search unit, used to search for the path and name corresponding to the target source code class according to the standard Maven project structure;
[0193] The test class determination unit is used to determine the unit test class corresponding to the target source code class based on the path and name corresponding to the target source code class.
[0194] Furthermore, in the code increment testing device, the testing module 15 specifically includes:
[0195] A command building unit, used to build a unit test command according to the unit test class;
[0196] The command execution unit is used to execute the unit test command in a pre-configured test environment to implement incremental testing of the target software and generate corresponding test results.
[0197] Furthermore, in the code increment testing device, the testing module 15 specifically includes:
[0198] A result analysis unit, used to analyze the test results and generate corresponding analysis results;
[0199] An optimization unit is used to optimize the incremental testing process of the target software based on the analysis result.
[0200] The specific implementation process and effects of the device embodiment of the present invention can be found in the above method embodiment, which will not be described in detail here.
[0201] It can be seen from the above device embodiments that the code incremental testing device provided by the present invention includes: a detection module, which is used to use the Git Diff command to detect the changes of the code base of the target software since the most recent successful build; an acquisition module, which is used to acquire the incremental Java files of the code base based on the detection results of the changes in the code base; a screening module, which is used to screen out the target source code class that needs to be unit tested from the incremental Java file; a determination module, which is used to determine the unit test class corresponding to the target source code class according to the standard Maven project structure; a testing module, which is used to construct a unit test command according to the unit test class, and execute the unit test command to implement the incremental testing of the target software. In this way, the device of the present invention can effectively reduce the execution time of the unit test when the target software is iterated by unit testing only the incremental code of the target software instead of the entire code base, and can speed up the development process.
[0202] Based on the above method embodiment, please refer to Figure 3 Another embodiment of the present invention further provides a computer device, wherein the computer device 10 includes:
[0203] memory 120 and one or more processors 110, Figure 3 A processor 110 is used as an example for description. The processor 110 and the memory 120 may be connected via a communication bus or other means. Figure 3 The example of connection via a communication bus is taken as an example.
[0204] The processor 110 is used to complete various control logics of the computer device 10. It can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), a single-chip microcomputer, an ARM (Acorn RISC Machine) or other programmable logic device, a discrete gate or transistor logic, a discrete hardware component, or any combination of these components. In addition, the processor 110 can also be any traditional processor, microprocessor or state machine. The processor 110 can also be implemented as a combination of computing devices, for example, a combination of a DSP and a microprocessor, a plurality of microprocessors, one or more microprocessors combined with a DSP, or any other such configuration.
[0205] The memory 120, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer executable programs and modules, such as the computer program corresponding to the code increment test method in any of the above method embodiments of the present invention. The processor 110 executes various functional applications and data processing of the computer device 10 by running the non-volatile software programs, instructions and units stored in the memory 120, that is, implements the code increment test method in any of the above method embodiments.
[0206] The memory 120 may include a program storage area and a data storage area, wherein the program storage area may store an application required for operating the device or at least one function; the data storage area may store data created according to the use of the computer device 10, etc. In addition, the memory 120 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 120 may optionally include a memory remotely arranged relative to the processor 110, and these remote memories may be connected to the computer device 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0207] One or more units are stored in the memory 120, and when executed by one or more processors 110, the code increment test method in any of the above method embodiments can be implemented, for example, the code increment test method described above can be implemented. Figure 1 The method comprises steps S100 to S500.
[0208] The specific implementation process and effects of the computer device embodiment of the present invention are shown in the above method embodiment, which will not be described in detail here.
[0209] It can be seen from the above computer device embodiments that the computer device provided by the present invention can achieve: using the Git Diff command to detect changes in the code base of the target software since the most recent successful build; based on the detection results of the changes in the code base, obtaining the incremental Java files of the code base; filtering out the target source code class that needs to be unit tested from the incremental Java files; determining the unit test class corresponding to the target source code class according to the standard Maven project structure; constructing a unit test command according to the unit test class, and executing the unit test command to implement incremental testing of the target software. In this way, the computer device of the present invention can effectively reduce the execution time of the unit test when the target software is iterated by unit testing only the incremental code of the target software instead of the entire code base, and can speed up the development process.
[0210] Those skilled in the art will understand that Figure 3 The hardware structure diagram shown in the figure is only a schematic diagram of a partial structure related to the solution of the present invention, and does not constitute a limitation on the computer device to which the solution of the present invention is applied. The specific computer device may include more components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0211] Based on the above method embodiments, another embodiment of the present invention further provides a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by at least one processor, the code increment test method in any of the above method embodiments can be implemented, for example, the above described Figure 1 The method comprises steps S100 to S500.
[0212] The specific implementation process and effects of the non-volatile computer-readable storage medium embodiment of the present invention are shown in the above method embodiment, which will not be repeated here.
[0213] From the above non-volatile computer-readable storage medium embodiments, it can be known that the non-volatile computer-readable storage medium provided by the present invention can achieve: using the Git Diff command to detect changes in the code base of the target software since the most recent successful build; based on the detection results of the changes in the code base, obtaining the incremental Java files of the code base; screening out the target source code class that needs to be unit tested from the incremental Java files; determining the unit test class corresponding to the target source code class according to the standard Maven project structure; constructing a unit test command according to the unit test class, and executing the unit test command to implement incremental testing of the target software. In this way, the non-volatile computer-readable storage medium of the present invention can effectively reduce the execution time of the unit test when the target software is iterated by unit testing only the incremental code of the target software instead of the entire code base, thereby speeding up the development process.
[0214] As an example, the non-volatile storage medium can include a read-only memory (ROM), a programmable ROM (PROM), an electrically programmable ROM (EPROM), an electrically erasable ROM (EEPROM), or a flash memory. Volatile memory can include a random access memory (RAM) as an external cache memory. By way of illustration and not limitation, RAM can be obtained in many forms such as synchronous RAM (SRAM), dynamic RAM, (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), Synch link DRAM (SLDRAM), and direct Rambus RAM (DRRAM). The disclosed memory components or memories of the operating environment described herein are intended to include one or more of these and / or any other suitable types of memory.
[0215] Based on the above method embodiments, another embodiment of the present invention further provides a computer program product, the computer program product includes a computer program stored on a non-volatile computer-readable storage medium, the computer program includes program instructions, when the program instructions are executed by a processor, the code increment test method in any of the above method embodiments can be implemented, for example, the above described Figure 1 The method comprises steps S100 to S500.
[0216] The specific implementation process and effects of the computer program product embodiment of the present invention are shown in the above method embodiment and will not be described in detail here.
[0217] It can be seen from the above computer program product embodiments that the computer program product provided by the present invention can achieve: using the Git Diff command to detect changes in the code base of the target software since the most recent successful build; based on the detection results of the changes in the code base, obtaining the incremental Java files of the code base; filtering out the target source code class that needs to be unit tested from the incremental Java files; determining the unit test class corresponding to the target source code class according to the standard Maven project structure; constructing a unit test command according to the unit test class, and executing the unit test command to implement incremental testing of the target software. In this way, the computer program product of the present invention can effectively reduce the execution time of the unit test when the target software is iterated by unit testing only the incremental code of the target software instead of the entire code base, and can speed up the development process.
[0218] The embodiments described above are merely illustrative, in which the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0219] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a general hardware platform, and of course can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can exist in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods of each embodiment or some parts of the embodiment.
[0220] Conditional language such as "can," "can," "might," or "may," among other things, unless specifically stated otherwise or otherwise understood within the context as used, is generally intended to convey that a particular embodiment can include (while other embodiments do not) a particular feature, element, and / or operation. Thus, such conditional language is also generally intended to imply that a feature, element, and / or operation is required for one or more embodiments anyway or that one or more embodiments must include logic for determining, with or without input or prompting, whether such features, elements, and / or operations are included or will be performed in any particular embodiment.
[0221] It should be noted that if non-company software tools or components appear in the embodiments of the present application, they are only used for example introduction and do not represent actual use. The content described in this article, in this specification and in the drawings includes examples that can provide a code increment test method, device, computer equipment and non-volatile computer-readable storage medium. Of course, it is not possible to describe every conceivable combination of elements and / or methods for the purpose of describing the various features of the present disclosure, but it can be recognized that many other combinations and permutations of the disclosed features are possible. Therefore, it is obvious that various modifications can be made to the present disclosure without departing from the scope or spirit of the present disclosure, but all these various modifications should belong to the scope of protection of the claims attached to the present invention. In addition, or in an alternative, other embodiments of the present disclosure may be obvious from consideration of the present specification and the drawings and from the practice of the present disclosure as presented herein. It is intended that the examples proposed in this specification and the drawings are considered to be illustrative and not restrictive in all respects. Although specific terms are used in this article, they are used in a general and descriptive sense and are not used for limiting purposes.< / testclassname>
Claims
1. A code incremental testing method, characterized in that: include: Use the Git Diff command to detect changes in the target software's code base since the last successful build; Based on the detection result of the change of the code base, obtaining the incremental Java file of the code base; Filter out target source code classes that need to be unit tested from the incremental Java files; Determine the unit test class corresponding to the target source code class according to the standard Maven project structure; A unit test command is constructed according to the unit test class, and the unit test command is executed to implement incremental testing of the target software.
2. The code increment testing method according to claim 1, characterized in that: The Git Diff command is used to detect changes in the target software's code base since the last successful build, including: Determine the baseline commit version of the target software's code base since the most recent successful build; Based on the baseline submission version, the Git Diff command is used to detect changes in the code base since the most recent successful build, and a change detection result of the code base is generated.
3. The code increment testing method according to claim 1, characterized in that: The acquiring of the incremental Java files of the code base based on the change detection result of the code base includes: According to the change detection result of the code base obtained by executing the Git Diff command, the files with the extension .java are screened out; The filtered files with an extension of .java are sorted to obtain incremental Java files of the code base.
4. The code increment testing method according to claim 1, characterized in that: The step of screening out target source code classes that need to be unit tested from the incremental Java files includes: Get the filtering rules for incremental code; The target source code classes that need to be unit tested are filtered out from the incremental Java files according to the filtering rules.
5. The code incremental testing method according to claim 1, characterized in that: Determining the unit test class corresponding to the target source code class according to the standard Maven project structure includes: According to the standard Maven project structure, find the path and name corresponding to the target source code class; Based on the path and name corresponding to the target source code class, a unit test class corresponding to the target source code class is determined.
6. The code increment testing method according to claim 1, characterized in that: The step of constructing a unit test command according to the unit test class and executing the unit test command to implement incremental testing of the target software includes: Construct a unit test command according to the unit test class; In a pre-configured test environment, the unit test command is executed to implement incremental testing of the target software and generate corresponding test results.
7. The code increment testing method according to claim 6, characterized in that: After executing the unit test command in the pre-configured test environment to implement the incremental test of the target software and generating corresponding test results, the method further includes: Analyze the test results and generate corresponding analysis results; Based on the analysis results, the incremental testing process of the target software is optimized.
8. A code increment testing device, characterized in that: include: The detection module is used to use the Git Diff command to detect changes in the target software's code base since the last successful build; An acquisition module, used for acquiring incremental Java files of the code base based on the detection result of the change of the code base; A screening module is used to screen out target source code classes that need to be unit tested from the incremental Java files; A determination module is used to determine the unit test class corresponding to the target source code class according to the standard Maven project structure; A testing module is used to construct a unit testing command according to the unit testing class, and execute the unit testing command to implement incremental testing of the target software.
9. A computer device, characterized in that: The computer device comprises at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor. When the computer program is executed by the at least one processor, the code incremental testing method as described in any one of claims 1 to 7 can be implemented.
10. A non-volatile computer-readable storage medium, characterized in that: The non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by at least one processor, the code incremental testing method as described in any one of claims 1 to 7 can be implemented.