An efficient software testing method and system based on artificial intelligence
Through the efficient software testing method based on artificial intelligence, the problem of low software testing efficiency in the existing technology is solved, and the effect of quickly covering code segments and improving test coverage and efficiency is achieved.
Patent Information
- Application Number
- CN202411413104.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-11
- Publication Date
- 2025-04-08
- Estimated Expiration
- 2044-10-11
AI Technical Summary
Existing software testing technology is inefficient and cannot cover all code segments in a short time, resulting in potential defects not being discovered.
Using an efficient software testing method based on artificial intelligence, we use the code data of the target software, divide functional requirements, generate test points and test paths, extract code features, generate test cases, and calculate the distance between test cases and historical cases, and reasonably arrange the test sequence.
It realizes the rapid positioning of functional module problems, ensures coverage of all possible execution paths, improves test coverage and efficiency, obtains test results in a timely manner, clarify defective code data, and improves test coverage.
Smart Images

Figure CN119396719B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to an efficient software testing method and system based on artificial intelligence. Background Art
[0002] With the changes in the software development environment and the improvement of user needs, the importance of software testing has become increasingly prominent, and users have higher expectations for the stability, performance and security of the software. Any defects may lead to user loss. In order to complete software testing in a short time, the software code needs to be efficiently tested to ensure software quality.
[0003] The existing software testing technology is to test the software code one by one according to the manually written test cases. In actual applications, the software functions may change at any time, and the test cases need to be constantly updated. In addition, the software codes are tested one by one. Under time constraints, it may not be possible to cover all code segments, resulting in potential defects not being discovered, making the software testing process too cumbersome, and thus reducing the efficiency of software testing. Summary of the invention
[0004] The present invention provides an efficient software testing method and system based on artificial intelligence, the main purpose of which is to solve the problem of low efficiency when performing software testing.
[0005] To achieve the above object, the present invention provides an efficient software testing method based on artificial intelligence, comprising:
[0006] Obtaining code data of the target software, dividing the code data according to preset functional requirements, and obtaining a required code data set;
[0007] Generating test points of the code data one by one according to the code segments of the code data in the required code data set, and generating test paths of the code data according to the test points;
[0008] Extracting code features of the code data, generating test cases for the code data according to the code features and the test path, calculating a test distance between the test case and a previously acquired historical test case, and generating a test scheduling sequence according to the test distance;
[0009] The method comprises: performing a synchronous test on the required code data set according to the test scheduling sequence to obtain a test result set, including: performing set mapping between the test scheduling sequence and the required code data set to obtain a test mapping relationship; obtaining a test time corresponding to the required code data set, and synchronizing the test time corresponding to the required code data set according to the test time to obtain a synchronized test time, wherein the synchronized test time is:
[0010]
[0011] Among them, δ h is the synchronous test time corresponding to the hth requirement code data set, T h is the test time corresponding to the hth requirement code data set, ΔT is the time sampling period, INT is the rounding function, and E is the benchmark test time;
[0012] Execute the test scheduling sequence on the required code data set according to the synchronous test time and the test mapping relationship to obtain a test result set, and extract defect code data in the required code data set through a test defect report in the test result set;
[0013] A test update case for the defective code data is generated according to the test case using a preset mutation algorithm, a test update report for the defective code data is generated through the test update case, and a test report for the target software is generated according to the test result set and the test update report.
[0014] Optionally, the code data is divided according to preset functional requirements to obtain a required code data set, including:
[0015] Extracting the business function logic corresponding to the functional requirements;
[0016] Identify the code segment corresponding to the code data according to the business function logic;
[0017] Mark the functional requirement identifier corresponding to the code segment;
[0018] Generate a code dependency graph according to the functional requirement identifier and the code segment;
[0019] A required code data set corresponding to the code data is generated according to the code dependency graph.
[0020] Optionally, the step of generating test points of the code data one by one according to the code segments of the code data in the required code data set includes:
[0021] Extracting code association logic of code data in the required code data set;
[0022] generating a test logic point of the code data according to the code association logic;
[0023] Mark the starting and ending points of the code segment;
[0024] The test logic points are divided according to the starting segment point and the ending segment point to obtain the test points corresponding to the code data.
[0025] Optionally, generating a test path for the code data according to the test point includes:
[0026] Determine a test edge according to the code association logic corresponding to the test point;
[0027] Mark the test mark corresponding to the test point;
[0028] The test edges are connected according to the test identifiers to obtain a test path for the code data.
[0029] Optionally, generating a test case for the code data according to the code feature and the test path includes:
[0030] Extracting input type, logic type and boundary conditions from the code features;
[0031] Determine the path direction of the test path according to the logic type;
[0032] Generate an input use case of the code data according to the input type and the boundary condition;
[0033] The input case and the path direction are combined into a test case for the code data.
[0034] Optionally, calculating the test distance between the test case and a pre-acquired historical test case includes:
[0035] Extracting the data type corresponding to the test case;
[0036] Selecting a target test case from the historical test cases according to the data type;
[0037] Numerizing the data type to obtain a type identifier;
[0038] The test distance between the test case and the target test case is calculated using the following preset type distance formula and the type identifier:
[0039]
[0040] Wherein, D is the test distance, l is the type identifier, l1 is the type identifier of the numerical type, l2 is the type identifier of the character type, l3 is the type identifier of the Boolean type, x is the numerical attribute in the test case, y is the numerical attribute in the target test case, R is the mean attribute corresponding to the numerical range in the test case, C is the tuple of the number of occurrences of each character in the test case, n is the total number of all different characters, and c k is the number of occurrences of character k in the target test case, p tis the number of the t-th Boolean attribute in the test case, v t is the number of the t-th Boolean attribute in the target test case.
[0041] Optionally, extracting defect code data in the requirement code data set through a test defect report in the test result set includes:
[0042] Determine the target test case in the requirement code data set through the test defect report in the test result set;
[0043] Locating the test code segment in the required code data set according to the target test case;
[0044] Defective code data in the required code data set is extracted according to the test code segment.
[0045] Optionally, the generating a test update case of the defective code data according to the test case by using a preset mutation algorithm includes:
[0046] The mutation value of the use case corresponding to the defect code data is calculated using the following preset mutation algorithm:
[0047]
[0048] Among them, f i+1 is the case variation value of the i+1th iteration, f i is the case variation value of the i-th iteration, α i is the variation learning rate of the i-th iteration, INT is the rounding function, exp is the exponential function, γ i is the radius of the mutation range of the i-th iteration, is the maximum number of iterations;
[0049] Determining the update quantity of the test update case according to the case variation value;
[0050] The test case is updated according to the update quantity and the pre-acquired mutation rule to obtain a test update case for the defect code data.
[0051] Optionally, generating a test report of the target software according to the test result set and the test update report includes:
[0052] The test result set is updated according to the test update report to obtain a test result update set;
[0053] Counting the test cases in the test result update set and the test statuses corresponding to the test cases;
[0054] Count the number of defects and defect descriptions in the test update report;
[0055] A test report for the target software is generated according to the defect quantity, the defect description, the test case and the test status.
[0056] In order to solve the above problems, the present invention also provides an efficient software testing system based on artificial intelligence, the system comprising:
[0057] A code data partitioning module is used to obtain code data of the target software, and to partition the code data according to preset functional requirements to obtain a required code data set;
[0058] A test path generation module, used to generate test points of the code data according to the code segments of the code data in the required code data set one by one, and generate a test path of the code data according to the test points;
[0059] A test scheduling sequence generation module is used to extract code features of the code data, generate test cases for the code data according to the code features and the test path, calculate the test distance between the test case and the previously acquired historical test case, and generate a test scheduling sequence according to the test distance;
[0060] A synchronous testing module, used to perform synchronous testing on the required code data set according to the test scheduling sequence to obtain a test result set, and extract defect code data in the required code data set through a test defect report in the test result set;
[0061] A test report generation module is used to generate a test update case for the defective code data according to the test case using a preset mutation algorithm, generate a test update report for the defective code data through the test update case, and generate a test report for the target software according to the test result set and the test update report.
[0062] The embodiment of the present invention can quickly locate the problem of a specific functional module by dividing the code according to functional requirements; generate test points by analyzing code segments one by one to ensure that all possible execution paths are covered; the test cases generated according to code features can more accurately reflect the actual needs of the software; by calculating the distance between historical test cases and new test cases, it can be identified which test cases are more important or more likely to find defects, and the test sequence can be reasonably arranged to make the best use of limited test resources; through synchronous testing, test results can be obtained in a timely manner and problems found can be responded to quickly; extracting defect code data can clearly point out which specific code fragments have defects; new test cases generated by mutation algorithms can dig out more potential defects and improve test coverage; the test report integrates the results of all test activities and provides a comprehensive project status. Therefore, the efficient software testing method and system based on artificial intelligence proposed by the present invention can solve the problem of low efficiency when performing software testing. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] Figure 1 A flowchart of an efficient software testing method based on artificial intelligence provided by an embodiment of the present invention;
[0064] Figure 2 A schematic diagram of a process for generating test points provided by an embodiment of the present invention;
[0065] Figure 3 A schematic diagram of a process for generating a test case according to an embodiment of the present invention;
[0066] Figure 4 A functional module diagram of an artificial intelligence-based software efficient testing system provided by one embodiment of the present invention.
[0067] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0068] 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.
[0069] The embodiment of the present application provides an efficient software testing method based on artificial intelligence. The execution subject of the efficient software testing method based on artificial intelligence includes but is not limited to at least one of the electronic devices such as the server, the terminal, etc. that can be configured to execute the method provided by the embodiment of the present application. In other words, the efficient software testing method based on artificial intelligence can be executed by software or hardware installed on a terminal device or a server device, and the software can be a blockchain platform. The server includes but is not limited to: a single server, a server cluster, a cloud server or a cloud server cluster, etc. The server can be an independent server, or it can be a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and basic cloud computing services such as big data and artificial intelligence platforms.
[0070] Reference Figure 1 FIG. 1 is a flow chart of an efficient software testing method based on artificial intelligence provided by an embodiment of the present invention. In this embodiment, the efficient software testing method based on artificial intelligence includes:
[0071] S1. Obtain code data of the target software, divide the code data according to preset functional requirements, and obtain a required code data set.
[0072] In an embodiment of the present invention, the code data refers to all information and content related to software development, including but not limited to source code, script files, configuration files, and document data, where source code refers to program code written in a programming language, script files refer to files that are automatically constructed, configuration files refer to configuration parameters required for the application to run, and document data refers to files that explain code functions, usage methods, and development guidelines.
[0073] In detail, the code data of the target software can be obtained from a pre-stored storage area through a computer statement with a data capture function (such as a Java statement, a Python statement, etc.), where the storage area includes but is not limited to a database and a blockchain.
[0074] Furthermore, in order to more clearly understand the purpose and function of each module or function, it is necessary to correspond the code data to the specific functional requirements. Therefore, after the code data of the target software is divided according to functional requirements, it is easier to design and execute test cases for specific functions and improve code quality.
[0075] In an embodiment of the present invention, the functional requirements refer to specific functions and behaviors possessed by the target software, describing the tasks or operations that the user hopes to achieve. For example, if the software is a shopping software, its corresponding functional requirements include user management function, product management function, shopping cart function, order management function, payment function, inventory function, and evaluation function; the requirement code data set refers to a code set extracted from the code data of the target software, which is a set intended to reflect the relationship between functional requirements and code implementation, including a functional requirement identifier, a corresponding code segment, and dependency information. The functional requirement identifier refers to an ID or name that uniquely identifies each functional requirement, the corresponding code segment refers to a specific code fragment that implements the functional requirement, including a function, class, or module, and the dependency information indicates the calling and dependency relationships between different code segments so as to understand the interactions between the functions.
[0076] In the embodiment of the present invention, the code data is divided according to the preset functional requirements to obtain the required code data set, including:
[0077] Extracting the business function logic corresponding to the functional requirements;
[0078] Identify the code segment corresponding to the code data according to the business function logic;
[0079] Mark the functional requirement identifier corresponding to the code segment;
[0080] Generate a code dependency graph according to the functional requirement identifier and the code segment;
[0081] A required code data set corresponding to the code data is generated according to the code dependency graph.
[0082] In detail, based on the requirement document of the target software, identify each business function module, and convert each function requirement into a business logic description, clarifying its input, processing and output. For example, if the function requirement is user registration, the corresponding business function logic is input: user information (user name, password, email address), processing: verify the information format, check whether the username already exists, store the user information in the database, and output: registration success or failure message; if the function requirement is product browsing, the corresponding business function logic is input: category ID, processing: query the database to obtain the product list, filter according to category, and output: product list. Then, locate the code data of the target software according to the extracted business function logic, identify the code segment corresponding to the function requirement, that is, match the business logic with the code, ensure that each function has a corresponding code implementation, and add an identifier to the identified code segment in the code. Comments or specific tags (such as @Function Requirement ID) can usually be used to make it easy to track.
[0083] Specifically, the functional requirement identifier is mapped with the corresponding code segment, that is, the calling relationship and dependency between the code segments are identified through static analysis tools or manual analysis. For example, function_c() is called in main.py, function_c() calls function_a() in module_b.py, and function_a() calls function_b() in module_a.py. The final calling relationship is main.py->module_b.py->module_a.py|->function_c()->function_a()->function_b. Static analysis tools (such as PyLint or Flake8) can be used to generate a call tree. The static analysis tool will analyze the call of each function and output the dependency relationship. A graphical tool (such as a dependency analysis tool) can be used to generate a visual code dependency graph to show the relationship between the code segments. Then, according to the dependency graph and mapping table, all functional requirements, corresponding code segments and their dependencies are integrated into a set. For example, the code segment corresponding to functional requirement a is A, and the dependent codes corresponding to A include B and C. Then the requirement code data set corresponding to functional requirement a is {A, B, C}.
[0084] Furthermore, in order to ensure that different paths, conditions and boundary cases are tested and to improve the overall code coverage, it is necessary to analyze the code segments in the divided requirement code data set one by one and test specific functions to avoid invalid testing and save time and resources.
[0085] S2. Generate test points of the code data one by one according to the code segments of the code data in the required code data set, and generate test paths of the code data according to the test points.
[0086] In the embodiment of the present invention, the test point refers to a position where each code segment needs to be tested in all required code data sets after division, so as to ensure the correctness and functional integrity of the code.
[0087] In the embodiment of the present invention, referring to Figure 2 As shown, the step of generating the test points of the code data one by one according to the code segments of the code data in the required code data set includes:
[0088] S21, extracting the code association logic of the code data in the required code data set;
[0089] S22, generating a test logic point of the code data according to the code association logic;
[0090] S23, marking the starting point and the ending point of the code segment;
[0091] S24. Divide the test logic points according to the starting segment point and the ending segment point to obtain test points corresponding to the code data.
[0092] In detail, code association logic refers to the relationship between each code segment in each required code data set, including function calls, variable dependencies, and conditional branches, etc., and then the logic points that need to be tested are determined according to the extracted code association logic. The test logic points can be the input location, the function call location, the conditional branch location, and the variable dependency location, and the starting segment point and the ending segment point corresponding to the code segment are marked. For example, if the relevant code is user_login(username, password), then user_login( is found in the code, and its location is recorded as the starting segment point. From the starting segment point, search backward to find the first one), and its location is recorded as the ending segment point. The input location, function call location, conditional branch location, and variable dependency location are searched in the starting segment point and the ending segment point of the code segment, and then the test logic points are configured in these locations, so that the test logic points in these locations are determined as the test points corresponding to the code data.
[0093] Furthermore, in order to visually see which software functions need to be tested, it is necessary to generate test paths based on test points to implement comprehensive testing of different scenarios, thereby ensuring that the code works properly under various conditions, and after each code update, newly introduced errors can be discovered in a timely manner by running the existing test paths.
[0094] In an embodiment of the present invention, the test path refers to a series of statements or branches in the program code that are systematically executed in a specific logical order in software testing to verify the correctness and functionality of the software program, and describes the execution route from the starting point of the software program to a specific end point.
[0095] In the embodiment of the present invention, the step of generating a test path for the code data according to the test point includes:
[0096] Determine a test edge according to the code association logic corresponding to the test point;
[0097] Marking the test mark corresponding to the test point;
[0098] The test edges are connected according to the test identifiers to obtain a test path for the code data.
[0099] In detail, based on the code association logic corresponding to the code data, that is, the logic in the code is analyzed, the various functional modules and the relationship between them are identified, and the test edges in the code are drawn according to the logical relationship of the test points, and a unique test identifier is assigned to each test point for subsequent reference. The information related to each test identifier is recorded, including input values, expected outputs, and test purposes. Then, according to the previously assigned test identifiers, the corresponding test edges are connected to form a complete test path, that is, the test edges are connected according to the relationship between the various code segments in each required code data set. The test path finally generated should cover all important logical branches and be able to verify all test points.
[0100] For example, if the requirement code data set corresponding to functional requirement a is {A, B, C}, the test points involved in code segment A are input point A1, function call point A2, and conditional branch point A3, the test points involved in code segment B are input point B1, function call point B2, and conditional branch point B3, and the test points involved in code segment C are input point C1, function call point C2, and conditional branch point C3, then the test edges in code segment A are A1-A2-A3, the test edges in code segment B are B1-B2-B3, and the test edges in code segment C are C1-C2-C3, and A, B, and C are a calling relationship, A calls B, B calls C, then the test path of the code data is A1-A2-A3-B1-B2-B3-C1-C2-C3.
[0101] Furthermore, in order to conduct comprehensive and efficient testing of the software and ensure that all possible execution paths are tested, it is necessary to analyze the control flow and data flow, and to avoid duplication of work by systematically extracting code features and generating use cases, making the testing process more efficient and standardized.
[0102] S3. Extract code features of the code data, generate test cases for the code data according to the code features and the test path, calculate the test distance between the test case and a previously acquired historical test case, and generate a test scheduling sequence according to the test distance.
[0103] In an embodiment of the present invention, the code features refer to various attributes and features that can be analyzed and extracted from the code, so as to help understand the structure, logic and function of the code. The code features include logic types, and the logic types include control flow features and data flow features. Control flow features include conditional statements and loop structures; data flow features include variable usage and input-output relationships; function features include function names, input parameters and return types; boundary conditions refer to the behavior and reaction of the system when the input value approaches or reaches the limit, which are usually used for testing to ensure that the code can still run normally under extreme circumstances. The code features corresponding to the code data can be extracted from a pre-stored storage area through computer statements with data capture functions (such as Java statements, Python statements, etc.).
[0104] Furthermore, in order to test the target software comprehensively and efficiently, it is necessary to generate accurate test cases. The test cases can verify whether the business logic implemented by the code meets expectations and ensure that each functional module can run correctly under different inputs. Through comprehensive test cases, potential defects and errors can be discovered earlier, thereby improving the overall quality and reliability of the code.
[0105] In an embodiment of the present invention, the test case refers to a set of inputs, execution conditions and expected results designed to verify whether the software function meets the requirements, including a test case ID, a test case description, preconditions, input data, execution steps, expected results, actual results, and status. The test case ID is a unique identifier, the test case description is a brief description of the purpose and content of the test, the preconditions are the conditions that need to be met before executing the test, the input data are the specific data used during the test, the execution steps are the specific operation steps required to execute the test, the expected results are the expected results according to the requirements document, the actual results are the actual results obtained after execution (filled in after the test is executed), and the status is the execution result of the test case (passed, failed).
[0106] In the embodiment of the present invention, referring to Figure 3 As shown, the test case for the code data is generated according to the code feature and the test path, including:
[0107] S31, extracting input type, logic type and boundary conditions from the code features;
[0108] S32, determining the path direction of the test path according to the logic type;
[0109] S33, generating an input use case of the code data according to the input type and the boundary condition;
[0110] S34: Combine the input test case and the path direction into a test case for the code data.
[0111] In detail, based on the code features, the input type, logic type and boundary conditions of the code segment are determined. The input types include integers, strings, and lists; the logic types include conditional statements, loops, and exception handling; boundary conditions include integers: 0, -1, maximum value (assumed to be 100), minimum value (assumed to be -100), strings: empty string, single character ("a"), maximum length string (assumed to be 100 characters), lists: empty list ([]), single element list ([1]), multiple element list ([1,2,3]), and then the direction of the test path is determined according to the logic type. For example, in the conditional statement, path 1 means the condition is true, and path 2 means the condition is false; in the loop type, path 1 means the loop is executed once, and path 2 means the loop is not executed.
[0112] Specifically, input use cases of the code segment can be generated according to the input type and boundary conditions. For example, when the input type is an integer, the corresponding input use cases are use case 1: 0, use case 2: -1, use case 3: maximum integer value 100, and use case 4: minimum integer value -100. When the input type is a string, the corresponding input use cases are use case 1: empty string, use case 2: single character ("a"), and use case 3: maximum length string (assuming a string of 100 characters). The input use cases and path directions are then combined into test cases for code data. For example, if the title of the test case includes a test case ID, description, input data, execution steps, expected results, and status, the data corresponding to the title is TC01, test condition is true, integer 0, execute function, return expected result A, and wait for execution; TC02, test condition is false, integer -1, execute function, return expected result B, and wait for execution; TC03, test maximum integer boundary, integer 100, execute function, return expected result C, and wait for execution, and so on.
[0113] Furthermore, based on the generated new test cases, they can be compared with historical test cases to find out which functions or boundary conditions have not been covered, ensuring the comprehensiveness of the test, and identifying the test cases that have been tested to reduce unnecessary repeated testing, thereby saving time and resources, deleting redundant or inefficient test cases, and optimizing the test case library.
[0114] In the embodiment of the present invention, the pre-acquired historical test cases refer to test cases that have been executed before during the software testing process, which usually contain different inputs and their corresponding expected outputs, and record the behavior of the system under specific conditions; the test distance is an indicator to measure the similarity between the new test cases and the historical test cases, reflecting the differences between the new test cases and the historical test cases in terms of input features, data types, etc. By calculating the test distance, it can be determined whether the new test case can effectively cover potential defects or verify different functions of the system. A smaller test distance usually means that the new test case is logically closer to the historical test case and may produce similar test effects.
[0115] In the embodiment of the present invention, the calculating of the test distance between the test case and the pre-acquired historical test case includes:
[0116] Extracting the data type corresponding to the test case;
[0117] Selecting a target test case from the historical test cases according to the data type;
[0118] Numerizing the data type to obtain a type identifier;
[0119] The test distance between the test case and the target test case is calculated using the following preset type distance formula and the type identifier:
[0120]
[0121] Wherein, D is the test distance, l is the type identifier, l1 is the type identifier of the numerical type, l2 is the type identifier of the character type, l3 is the type identifier of the Boolean type, x is the numerical attribute in the test case, y is the numerical attribute in the target test case, R is the mean attribute corresponding to the numerical range in the test case, C is the tuple of the number of occurrences of each character in the test case, n is the total number of all different characters, and c k is the number of occurrences of character k in the target test case, p t is the number of the t-th Boolean attribute in the test case, v t is the number of the t-th Boolean attribute in the target test case.
[0122] In detail, the data type (such as numeric value, string, character, Boolean, etc.) of each attribute is extracted from the newly generated test case, and the corresponding target test case is selected from the historical test case according to the extracted data type, ensuring that the selected target test case is comparable with the new test case in data type, that is, the test case with the same type as the test case is selected from the historical test case as the target test case, and then the different data types are digitized to obtain type identifiers, such as determining the type identifier corresponding to the numeric type as 0, the type identifier corresponding to the string type as 1, the type identifier corresponding to the Boolean type as 2, the type identifier corresponding to the character type as 3, etc., and the type identifier is configured in the dictionary for subsequent use and query.
[0123] Specifically, the test distance is a distance measure between a new test case and a target test case. The smaller the value, the more similar the two are in terms of features, and vice versa. The type identifier is then used to distinguish different types of test case attributes. That is, when the type identifier of a test case is a numeric type, the absolute difference between the two numeric attributes is calculated, and then this is divided by the range mean to obtain a standardized distance value, thereby determining whether the two numeric values are similar; when the type identifier of a test case is a character type, the similarity of string attributes between the two test cases is evaluated by considering the difference in character frequency and the number of different characters; when the type identifier of a test case is a Boolean type, the quantitative difference between the two Boolean attributes is directly calculated to measure the test distance; when the type identifier of a test case is a string type, the distance between the two strings is calculated by 1-|s1∩s2| / |s1∪s2|; and when the type of a test case does not conform to the numeric, string, character, or Boolean type, the distance between the two test cases is identified as infinite, indicating that the two are not comparable.
[0124] For example, the new test case attributes are a numeric attribute x=10, a string attribute "abc", a Boolean attribute p t = 2, the target test case attribute is a numerical attribute y = 8, a string attribute "ab", a Boolean attribute v t =1, the mean of the numerical attribute range R = 5, the character occurrence tuple C = (1,1,1) (i.e., 'a', 'b', 'c' each appear once), the total number of different characters n = 3, the target test case characters 'a' and 'b' each appear once, and the character 'c' does not appear, then the numerical distance D1 = |10-8| / 5 = 2 / 5 = 0.4, the string distance D2 = C×(nc k )=3×(3-2)=3×1=3, Boolean distance D3=|2-1|=1.
[0125] Furthermore, a test scheduling sequence is generated according to the test distance, that is, the test cases are sorted according to the calculated distance, and the test cases with smaller distances are more similar to the new test cases and are executed first, and then a final scheduling sequence is generated according to the sorted test cases, wherein the test scheduling sequence refers to the order in which a group of test cases are arranged in an orderly manner in order to improve test efficiency and coverage during the software testing process, so as to quickly identify potential problems during regression testing and ensure software quality.
[0126] Furthermore, based on the test cases corresponding to all generated requirement code data sets, the divided requirement code data sets can be tested synchronously. By reasonably scheduling and executing the test cases, the test time can be reduced and the utilization rate of the test resources can be improved.
[0127] S4. Perform synchronous testing on the required code data set according to the test scheduling sequence to obtain a test result set, and extract defect code data in the required code data set through a test defect report in the test result set.
[0128] In an embodiment of the present invention, the test result set refers to a summary of all test results collected after executing a test case, including a test case ID, a test status, an execution time, an error message, a log record, and environmental information, wherein the test case ID refers to a unique identifier for each test case, the test status refers to the execution result of each test case, typically including states such as "passed", "failed", or "not executed", the execution time refers to the time required to execute each test case, the error message refers to a detailed description of the cause of the failure and the error message if the test case fails, the log record refers to the relevant logs generated during the test process, which are used for subsequent analysis and debugging, and the environmental information refers to the environmental configuration during test execution, such as the operating system, software version, etc.
[0129] In the embodiment of the present invention, the step of performing synchronous testing on the required code data set according to the test scheduling sequence to obtain a test result set includes:
[0130] Performing set mapping between the test scheduling sequence and the required code data set to obtain a test mapping relationship;
[0131] Acquire the test time corresponding to the required code data set, and synchronize the test time corresponding to the required code data set according to the test time to obtain a synchronized test time, wherein the synchronized test time is:
[0132]
[0133] Among them, δ h is the synchronous test time corresponding to the hth requirement code data set, Th is the test time corresponding to the hth requirement code data set, ΔT is the time sampling period, INT is the rounding function, and E is the benchmark test time;
[0134] The test scheduling sequence is executed on the required code data set according to the synchronous test time and the test mapping relationship to obtain a test result set.
[0135] In detail, by analyzing the requirements and test cases, a mapping relationship is established to ensure that each requirement has a corresponding test case. For example, requirement 1, requirement 2, and requirement 3 correspond to test cases A, B, and C respectively, and the mapping relationship is {requirement 1: A, requirement 2: B, requirement 3: C}. When testing, the environment may change due to time differences, thereby reducing the accuracy of the test results. Therefore, all test data sets need to be tested synchronously, and the impact of requirement changes should be evaluated within each synchronization cycle. This can better manage project risks. When comparing the test results of different data sets horizontally, the consistency in time is easier to analyze and evaluate.
[0136] Specifically, each requirement code data set will have a corresponding test time when executing the test, and the test time that all requirement code data sets need to synchronize is determined based on the test time, that is, the difference between the test time of the hth requirement code and the benchmark test time is calculated to represent the time interval between the two, and then through Calculate the ratio of the time difference to the sampling period ΔT, which indicates how many times sampling (testing) can be performed within this time interval. Calculate the time increment of each sampling by dividing the time difference by the number of samplings, and then add this increment to the hth test time T h The test time after synchronization is obtained h , thereby performing cyclic calculation for each pair of adjacent test times to obtain all the synchronous test times.
[0137] For example, the test time corresponding to the requirement code data sets A, B, and C is T A ,T B ,T C , time sampling period ΔT, select the earliest test time as the reference time, such as T A <T B <T C , then the reference time is T A , for the synchronous test time δ corresponding to the requirement code data set A h =T A, remains unchanged. For the requirement code data sets B and C, the synchronous test time can be obtained through the synchronous test time calculation formula. The synchronous test time is used as the new test time to ensure that all resources are available at the new time point and start the test at the same time. For example, the test time of set A is T A =10:00, the test time T of set B B =10:30, the test time T of set C C = 11:00, the set sampling period ΔT = 15 minutes, then the synchronization time of set B is calculated as time difference A is T B -T A =30 minutes, INT(30 / 15)=2, δ B =10:00+30 / 2=10:00+15=10:15, calculate the synchronization time of set C, the time difference is T C -T A =30 minutes, INT(60 / 15)=4, δ C =10:00+60 / 4=10:00+15=10:15, then the test time of set A is: 10:00 (remains unchanged), the test time of set B is: 10:15, and the test time of set C is: 10:15. Therefore, all requirement code data sets A, B, and C are adjusted to the same time (10:15) for testing. Testing at the same time point is conducive to ensuring that the test data is tested in the same environment and conditions, thereby improving the reliability and comparability of the test results.
[0138] Furthermore, the test cases that failed are analyzed according to the test results after the test. Based on the failed test cases, defective code data can be identified to discover potential problems in the code, thereby improving code quality and reducing the possibility of similar defects.
[0139] In an embodiment of the present invention, the defect code data refers to defect information related to the code identified during the software development and testing process, such as logical errors, performance issues, security vulnerabilities, interface defects, etc.
[0140] In the embodiment of the present invention, the extracting defect code data in the requirement code data set through the test defect report in the test result set includes:
[0141] Determine the target test case in the requirement code data set through the test defect report in the test result set;
[0142] Locating the test code segment in the required code data set according to the target test case;
[0143] Defective code data in the required code data set is extracted according to the test code segment.
[0144] In detail, the test cases related to the defects are analyzed and screened out from the test defect report. These test cases should directly correspond to the defects found to ensure that subsequent processing can be carried out in a targeted manner; according to the determined target test cases, the specific test code segments in the required code data set are found and located, and the map test cases are implemented with the corresponding codes to ensure that the problems can be accurately found, and then the defective code data is extracted from the located test code segments. The defects include specific problems such as incorrect logic, unhandled boundary conditions, and resource leakage. The defective code data can be obtained from a pre-stored storage area through a computer statement with a data capture function. Therefore, through a targeted extraction process, unnecessary code reviews can be reduced and the efficiency of defect location can be improved.
[0145] Furthermore, in order to retest the defective code data and increase the test coverage scenarios and conditions, it is necessary to make slight modifications to the original test cases and generate multiple variant versions. By introducing mutations, various possible defect scenarios can be simulated to help testers identify problems that were not captured in the original test cases, thereby improving the effectiveness of defect detection.
[0146] S5. Generate a test update case for the defective code data according to the test case using a preset mutation algorithm, generate a test update report for the defective code data through the test update case, and generate a test report for the target software according to the test result set and the test update report.
[0147] In the embodiment of the present invention, the test update case refers to a test case that modifies or expands the original test case to adapt to new requirements, fix defects or improve test coverage.
[0148] In an embodiment of the present invention, the step of generating a test update case for the defect code data according to the test case using a preset mutation algorithm includes:
[0149] The mutation value of the use case corresponding to the defect code data is calculated using the following preset mutation algorithm:
[0150]
[0151] Among them, f i+1 is the case variation value of the i+1th iteration, f i is the case variation value of the i-th iteration, α i is the variation learning rate of the i-th iteration, INT is the rounding function, exp is the exponential function, γ i is the radius of the mutation range of the i-th iteration, is the maximum number of iterations;
[0152] Determining the update quantity of the test update case according to the case variation value;
[0153] The test case is updated according to the update quantity and the pre-acquired mutation rule to obtain a test update case for the defect code data.
[0154] In detail, in the mutation algorithm, α i As the number of mutations increases, it gradually decreases. The initial value α0 is specified as the maximum learning rate. i max For the specified maximum number of mutations, the test case proportion change function uses a Gaussian function, expressed as γ i is the mutation range radius. The mutation range radius, like the learning rate, also gradually decreases with the increase of the number of iterations i. The adjustment rule is Before starting the calculation, you need to set the initial mutation value f0, the initial learning rate α0 and the mutation range radius γ0, as well as the maximum number of iterations. In each iteration i, the result f of the previous iteration is used i To calculate the new variation value f i+1 , as the number of iterations increases, the expected variation value f i It will tend to be stable, which means that it has reached a state of equilibrium, and then according to the final use case variability value Determine the number of updates N (which can be determined by setting a threshold or function mapping, such as rounding or directly using A certain proportion of), such as setting a maximum update number N max , use a linear map to ensure that N does not exceed Then M is the maximum value of the mutation value, that is, after multiple iterations, the maximum mutation value in the iteration process is taken as the maximum value M, and the maximum number of updates is a custom configuration.
[0155] Specifically, obtain pre-defined mutation rules (such as replacement operation, insertion operation, deletion operation, etc.), update the original test case according to the update number N, and generate new test update cases. For example, the mutation rules include boundary value mutation, adjusting the boundary value of the input data; logical operator mutation, changing the logical operator in the conditional judgment (such as changing AND to OR); state mutation, modifying the system state or the order of user input, so as to obtain the test update case of the defective code data.
[0156] Furthermore, a test update report of the defect code data is generated through the test update use case, and the test update report includes the defect number, description, severity level, discovery use case, status, and remarks. For example, the content in the test update report is DEF001, an exception occurred during data submission, high priority, TC002, to be repaired, and a recurrence rate of 100%; DEF002, inaccurate user authority verification, medium priority, TC003, to be repaired, and some users are affected; DEF003, inconsistent data query results, medium priority, TC004, to be repaired, and occurs when the query conditions are special.
[0157] Furthermore, the test result set generated by the original test case and the test result generated by the updated test case can be reintegrated to obtain a more comprehensive test report. The combination of test results and defect information is conducive to identifying deficiencies in the test process and promoting continuous improvement and optimization of test strategies.
[0158] In an embodiment of the present invention, the test report refers to a document in the software testing process, which is used to summarize and record the results of the test activities, including the execution status of all test cases, passed and failed cases, and detailed records of defects found, including defect numbers, descriptions, severity levels, and current status; statistical information such as the overall number of test cases, pass rate, and failure rate.
[0159] In an embodiment of the present invention, generating a test report of the target software according to the test result set and the test update report includes:
[0160] The test result set is updated according to the test update report to obtain a test result update set;
[0161] Counting the test cases in the test result update set and the test statuses corresponding to the test cases;
[0162] Count the number of defects and defect descriptions in the test update report;
[0163] A test report for the target software is generated according to the defect quantity, the defect description, the test case and the test status.
[0164] In detail, based on the latest test update report, involving use case number, use case description, expected results, actual results, test status, defect number, defect description, severity level, and defect status, a test report for the target software is generated based on the number of defects, defect descriptions, test cases, and test status.
[0165] For example, the updated test result set is shown in Table 1 below:
[0166]
[0167] Table 1 Defect quantity and descriptive statistics, as shown in Table 2 below, if the total number of defects is 3, that is
[0168]
[0169]
[0170] Table 2
[0171] The embodiment of the present invention can quickly locate the problem of a specific functional module by dividing the code according to functional requirements; generate test points by analyzing code segments one by one to ensure that all possible execution paths are covered; the test cases generated according to code features can more accurately reflect the actual needs of the software; by calculating the distance between historical test cases and new test cases, it can be identified which test cases are more important or more likely to find defects, and the test sequence can be reasonably arranged to make the best use of limited test resources; through synchronous testing, test results can be obtained in a timely manner and problems found can be responded to quickly; extracting defect code data can clearly point out which specific code fragments have defects; new test cases generated by mutation algorithms can dig out more potential defects and improve test coverage; the test report integrates the results of all test activities and provides a comprehensive project status. Therefore, the efficient software testing method and system based on artificial intelligence proposed by the present invention can solve the problem of low efficiency when performing software testing.
[0172] like Figure 4 , which is a functional module diagram of an artificial intelligence-based software efficient testing system provided by an embodiment of the present invention.
[0173] The software efficient testing system 100 based on artificial intelligence of the present invention can be installed in an electronic device. According to the functions implemented, the software efficient testing system 100 based on artificial intelligence can include a code data partitioning module 101, a test path generation module 102, a test scheduling sequence generation module 103, a synchronous test module 104 and a test report generation module 105. The module of the present invention can also be referred to as a unit, which refers to a series of computer program segments that can be executed by an electronic device processor and can complete fixed functions, which are stored in the memory of the electronic device.
[0174] In this embodiment, the functions of each module / unit are as follows:
[0175] The code data division module 101 is used to obtain the code data of the target software, divide the code data according to the preset functional requirements, and obtain the required code data set;
[0176] The test path generation module 102 is used to generate test points of the code data according to the code segments of the code data in the required code data set one by one, and generate a test path of the code data according to the test points;
[0177] The test scheduling sequence generation module 103 is used to extract code features of the code data, generate test cases of the code data according to the code features and the test path, calculate the test distance between the test case and the pre-acquired historical test case, and generate a test scheduling sequence according to the test distance;
[0178] The synchronous testing module 104 is used to perform synchronous testing on the required code data set according to the test scheduling sequence to obtain a test result set, and extract defect code data in the required code data set through a test defect report in the test result set;
[0179] The test report generation module 105 is used to generate a test update case for the defect code data according to the test case using a preset mutation algorithm, generate a test update report for the defect code data through the test update case, and generate a test report for the target software according to the test result set and the test update report.
[0180] In detail, each module described in the software efficient testing system 100 based on artificial intelligence in the embodiment of the present invention is used in the same manner as described above. Figures 1 to 3 The same technical means are used as the efficient software testing method based on artificial intelligence described in the text, and can produce the same technical effects, so I will not go into details here.
[0181] In the several embodiments provided by the present invention, it should be understood that the disclosed systems and methods can be implemented in other ways. For example, the system embodiments described above are only illustrative, for example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation.
[0182] The modules described as separate components may or may not be physically separated, and the components shown as modules 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.
[0183] In addition, each functional module in each embodiment of the present invention may be integrated into one processing unit, each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional modules.
[0184] It is obvious to those skilled in the art that the present invention is not limited to the details of the above exemplary embodiments, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention.
[0185] Therefore, no matter from which point of view, the embodiments should be regarded as illustrative and non-restrictive, and the scope of the present invention is not limited only according to the above description, and it is intended that all changes within the meaning and scope of equivalent elements within the scope of protection are included in the present invention.
[0186] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0187] In addition, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or systems stated in a system claim can also be implemented by one unit or system through software or hardware. The words first, second, etc. are used to indicate names, and do not indicate any particular order.
[0188] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present invention.
Claims
1. An efficient software testing method based on artificial intelligence, characterized in that: The method comprises: Obtaining code data of the target software, dividing the code data according to preset functional requirements, and obtaining a required code data set; Generating test points of the code data one by one according to the code segments of the code data in the required code data set, and generating test paths of the code data according to the test points; Extracting code features of the code data, generating test cases for the code data according to the code features and the test path, calculating a test distance between the test case and a previously acquired historical test case, and generating a test scheduling sequence according to the test distance; The method comprises: performing a synchronous test on the required code data set according to the test scheduling sequence to obtain a test result set, including: performing set mapping between the test scheduling sequence and the required code data set to obtain a test mapping relationship; obtaining a test time corresponding to the required code data set, and synchronizing the test time corresponding to the required code data set according to the test time to obtain a synchronized test time, wherein the synchronized test time is: Among them, δ h is the synchronization test time corresponding to the hth requirement code data set, T h is the test time corresponding to the hth requirement code data set, ΔT is the time sampling period, INT is the rounding function, and E is the benchmark test time; Execute the test scheduling sequence on the required code data set according to the synchronous test time and the test mapping relationship to obtain a test result set, and extract defect code data in the required code data set through a test defect report in the test result set; A test update case for the defective code data is generated according to the test case using a preset mutation algorithm, a test update report for the defective code data is generated through the test update case, and a test report for the target software is generated according to the test result set and the test update report.
2. The efficient software testing method based on artificial intelligence according to claim 1, characterized in that: The code data is divided according to preset functional requirements to obtain a required code data set, including: Extracting the business function logic corresponding to the functional requirements; Identify the code segment corresponding to the code data according to the business function logic; Mark the functional requirement identifier corresponding to the code segment; Generate a code dependency graph according to the functional requirement identifier and the code segment; A required code data set corresponding to the code data is generated according to the code dependency graph.
3. The efficient software testing method based on artificial intelligence according to claim 1, characterized in that: The step of generating test points of the code data one by one according to the code segments of the code data in the required code data set comprises: Extracting code association logic of code data in the required code data set; generating a test logic point of the code data according to the code association logic; Mark the starting and ending points of the code segment; The test logic points are divided according to the starting segment point and the ending segment point to obtain the test points corresponding to the code data.
4. The efficient software testing method based on artificial intelligence according to claim 1, characterized in that: The step of generating a test path for the code data according to the test point comprises: Determine a test edge according to the code association logic corresponding to the test point; Marking the test mark corresponding to the test point; The test edges are connected according to the test identifiers to obtain a test path for the code data.
5. The efficient software testing method based on artificial intelligence according to claim 1, characterized in that: The generating a test case for the code data according to the code feature and the test path comprises: Extracting input type, logic type and boundary conditions from the code features; Determine the path direction of the test path according to the logic type; Generate an input use case of the code data according to the input type and the boundary condition; The input case and the path direction are combined into a test case for the code data.
6. The efficient software testing method based on artificial intelligence according to claim 1, characterized in that: The calculating the test distance between the test case and the pre-acquired historical test case includes: Extracting the data type corresponding to the test case; Selecting a target test case from the historical test cases according to the data type; Numerizing the data type to obtain a type identifier; The test distance between the test case and the target test case is calculated using the following preset type distance formula and the type identifier: Wherein, D is the test distance, l is the type identifier, l1 is the type identifier of the numerical type, l2 is the type identifier of the character type, l3 is the type identifier of the Boolean type, x is the numerical attribute in the test case, y is the numerical attribute in the target test case, R is the mean attribute corresponding to the numerical range in the test case, C is the tuple of the number of occurrences of each character in the test case, n is the total number of all different characters, and c k is the number of occurrences of character k in the target test case, p t is the number of the t-th Boolean attribute in the test case, v t is the number of the t-th Boolean attribute in the target test case.
7. The efficient software testing method based on artificial intelligence according to claim 1, characterized in that: The extracting defect code data in the requirement code data set through the test defect report in the test result set includes: Determine the target test case in the requirement code data set through the test defect report in the test result set; Locating the test code segment in the required code data set according to the target test case; Defective code data in the required code data set is extracted according to the test code segment.
8. The efficient software testing method based on artificial intelligence according to claim 1, characterized in that: The step of generating a test update case for the defect code data according to the test case using a preset mutation algorithm includes: The mutation value of the use case corresponding to the defect code data is calculated using the following preset mutation algorithm: Among them, f i+1 is the case variation value of the i+1th iteration, f i is the case variation value of the i-th iteration, α i is the variation learning rate of the i-th iteration, INT is the rounding function, exp is the exponential function, γ i is the radius of the mutation range of the i-th iteration, is the maximum number of iterations; Determining the update quantity of the test update case according to the case variation value; The test case is updated according to the update quantity and the pre-acquired mutation rule to obtain a test update case for the defect code data.
9. The efficient software testing method based on artificial intelligence according to claim 1, characterized in that: Generating a test report for the target software according to the test result set and the test update report includes: The test result set is updated according to the test update report to obtain a test result update set; Counting the test cases in the test result update set and the test statuses corresponding to the test cases; Count the number of defects and defect descriptions in the test update report; A test report for the target software is generated according to the defect quantity, the defect description, the test case and the test status.
10. An efficient software testing system based on artificial intelligence, characterized in that: Used to execute the artificial intelligence-based software efficient testing method as described in any one of claims 1 to 9, the system comprises: A code data partitioning module is used to obtain code data of the target software, and to partition the code data according to preset functional requirements to obtain a required code data set; A test path generation module, used to generate test points of the code data according to the code segments of the code data in the required code data set one by one, and generate a test path of the code data according to the test points; A test scheduling sequence generation module is used to extract code features of the code data, generate test cases for the code data according to the code features and the test path, calculate the test distance between the test case and the previously acquired historical test case, and generate a test scheduling sequence according to the test distance; A synchronous test module is used to perform synchronous testing on the required code data set according to the test scheduling sequence to obtain a test result set, including: performing set mapping between the test scheduling sequence and the required code data set to obtain a test mapping relationship; obtaining a test time corresponding to the required code data set, and synchronizing the test time corresponding to the required code data set according to the test time to obtain a synchronous test time, wherein the synchronous test time is: Among them, δ h is the synchronization test time corresponding to the hth requirement code data set, T h is the test time corresponding to the hth requirement code data set, ΔT is the time sampling period, INT is the rounding function, and E is the benchmark test time; Execute the test scheduling sequence on the required code data set according to the synchronous test time and the test mapping relationship to obtain a test result set, and extract defect code data in the required code data set through a test defect report in the test result set; A test report generation module is used to generate a test update case for the defective code data according to the test case using a preset mutation algorithm, generate a test update report for the defective code data through the test update case, and generate a test report for the target software according to the test result set and the test update report.
Citation Information
Patent Citations
Test case determination method and device and cloud disk regression test method and device
CN117493174A
Method and apparatus for the performing unit testing of software modules in software systems
US20110258601A1