Software test case generation method based on semantic analysis and optimization algorithm

The method addresses inefficiencies in automated software testing by using semantic analysis and optimization algorithms to automatically generate and optimize test cases from source code, enhancing automation, targeting, and adaptability.

CN119149440APending Publication Date: 2024-12-17GUOXIN JINHONG (CHENGDU) INSPECTION & TESTING TECH RES INST CO LTD +1
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202411665881.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-20
Publication Date
2024-12-17

AI Technical Summary

Technical Problem

Existing automated software testing methods face challenges such as low test case generation efficiency, high maintenance costs, and difficulty adapting to rapidly changing software requirements, particularly in complex and changing graphical user interfaces, with NLP and optimization algorithm integration facing inefficiencies in test case accuracy and coverage.

Method used

A method using semantic analysis and optimization algorithms, including latent semantic analysis, TextRank, and particle swarm optimization, to automatically extract and optimize test cases from source code annotations, incorporating natural language processing for preprocessing and concept extraction.

Benefits of technology

Improves automation, targeting, and efficiency of test case generation, ensuring adaptability to software changes, reducing manual effort and enhancing test case quality and relevance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119149440A_ABST
    Figure CN119149440A_ABST
Patent Text Reader

Abstract

The invention discloses a software test case generation method based on semantic analysis and an optimization algorithm, which successfully realizes the goal of automatically extracting and generating a test case from a source code annotation through the steps of data acquisition and preprocessing, keyword and concept extraction and optimization, test case generation, test case updating and maintenance and the like. By means of advanced algorithms such as LSA, TextRank and PSO, not only is the quality of test cases improved, but also the automation and continuous optimization capability of the test process is ensured so as to cope with changes and challenges in the software life cycle. According to the method, the workload of manually writing test cases is reduced, the accuracy and comprehensiveness of the test are enhanced, powerful support is provided for software development teams, and the software development teams are assisted to construct more stable and reliable software products.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of software testing, and in particular relates to the design of a software testing case generation method based on semantic analysis and optimization algorithm. Background Art

[0002] Existing automated software testing methods, whether traditional script-based or model-based, face challenges such as low test case generation efficiency, high maintenance costs, and difficulty adapting to rapidly changing software requirements. Traditional software test case generation usually relies on manual writing, which is not only time-consuming but also prone to human errors; while model-based testing can automatically generate test cases, its complexity and maintenance difficulty increase sharply with the growth of software scale.

[0003] Although some studies have proposed methods to use GPT-3 and NLP (Natural Language Processing) technology to automatically generate GUI (Graphical User Interface) tests and extract test cases from requirement documents, these innovative approaches still face multiple challenges and limitations. Although the GUI testing method based on GPT-3 has improved efficiency, it is not good enough in real-time tracking of interface element status and feedback, especially when dealing with complex and changing graphical user interfaces, the adaptability and stability of the model need to be improved. Although NLP can identify key test points from semantic analysis, its test coverage for non-functional requirements such as performance and security is weak, and when dealing with large and complex systems, the generated test cases may not be accurate and efficient enough. In addition, there is a gap between the theoretical efficiency and actual operation of the strategy of integrating NLP with optimization algorithms to generate optimized test combinations, which is manifested in the difficulty of accurately measuring the quality and coverage of test cases, as well as the problem of effective coordination between NLP and optimization algorithms. These are key problems that need to be solved urgently. Summary of the invention

[0004] The purpose of the present invention is to solve the problems of low test case generation efficiency, high maintenance cost and difficulty in adapting to changes in software requirements in existing software testing methods, and proposes a software test case generation method based on semantic analysis and optimization algorithm.

[0005] The technical solution of the present invention is: a method for generating software test cases based on semantic analysis and optimization algorithm, comprising the following steps:

[0006] S1. Obtain a source code annotation dataset from an open source code hosting platform, and preprocess the source code annotations therein to obtain preprocessed data.

[0007] S2. Based on the latent semantic analysis method, the concepts in the annotations are extracted from the preprocessed data, and based on the TextRank algorithm, the keywords in the annotations are extracted from the preprocessed data.

[0008] S3. Optimize the selection and sorting of concepts and keywords based on the particle swarm optimization algorithm to generate a test case set.

[0009] S4. Update and maintain the test case set regularly.

[0010] Furthermore, in step S1, natural language processing technology is used to pre-process the source code annotations. The natural language processing technology includes text classification, named entity recognition and sentiment analysis.

[0011] Furthermore, the latent semantic analysis method in step S2 includes the following steps:

[0012] A1. Perform word segmentation on the text in the preprocessed data to obtain word vectors.

[0013] A2. Perform stemming and lemmatization on the word vector to obtain a standardized word vector.

[0014] A3. Remove stop words from the standardized word vector to obtain the cleaned word vector.

[0015] A4. Calculate the word frequency in the cleaned word vector and construct a word-document matrix.

[0016] A5. Perform singular value decomposition on the word-document matrix to obtain a singular value decomposition matrix.

[0017] A6. Perform dimensionality reduction processing on the singular value decomposition matrix to obtain a reduced-dimensional matrix.

[0018] A7. Perform concept representation based on the dimensionality reduction matrix to obtain the concepts in the annotations.

[0019] Furthermore, the formula for performing singular value decomposition in step A5 is:

[0020] ;

[0021] in represents the word-document matrix, represents the left singular vector matrix, represents a diagonal matrix of singular values, represents the right singular vector matrix.

[0022] Further, step A7 includes the following sub-steps:

[0023] A71. Map the dimensionality reduction matrix to the semantic space. Each vector in the dimensionality reduction matrix represents an annotation, and its coordinate value represents the distribution of the annotation in each latent semantic dimension.

[0024] A72. Analyze the distribution of vectors in the semantic space and identify patterns or clusters with significant features. The patterns or clusters correspond to the concepts contained in the annotation text.

[0025] A73. Define and describe the identified concepts based on the high-frequency words and phrases in the annotation text and the distribution characteristics in the semantic space.

[0026] Furthermore, the TextRank algorithm in step S2 includes the following steps:

[0027] B1. Construct the text in the preprocessed data into a directed graph ,in is a node set, representing the words in the text, is the set of connecting edges between nodes, indicating the similarity between words.

[0028] B2. Assign a weight to each node through iterative calculation.

[0029] B3. The words corresponding to the N nodes with the highest weights are used as keywords in the annotation, where N represents the preset number of keyword extractions.

[0030] Furthermore, the weight allocation formula in step B2 is:

[0031] ;

[0032] in represents the weight of node i at the t+1th iteration, d represents the damping factor, represents the set of all nodes pointing to node i, represents the weight of node j at the tth iteration, Represents the number of outgoing edges owned by node j.

[0033] Further, step S3 includes the following sub-steps:

[0034] S31. Use concepts and keywords as particles in the particle swarm optimization algorithm and initialize the particle swarm.

[0035] S32. Set the number of iterations and update the position and velocity of the particle in each iteration.

[0036] S33. In response to reaching the number of iterations, M particles with the highest fitness are selected from the final particle group as test cases to generate a test case set, where M represents a preset number of test cases.

[0037] Furthermore, the formula for updating the position and velocity of the particle in step S32 is:

[0038] ;

[0039] ;

[0040] in represents the position of particle a at the b+1th iteration, represents the position of particle a at the bth iteration, represents the velocity of particle a at the bth iteration, represents the velocity of particle a at the b+1th iteration, represents the inertia weight, represents cognitive parameters, represents social parameters, and Are all random numbers, indicating represents the optimal position of particle a, represents the best position among all particles.

[0041] The beneficial effects of the present invention are:

[0042] (1) Significantly improved automation: The present invention uses advanced natural language processing technologies, such as latent semantic analysis (LSA) and TextRank algorithm, to automatically extract key concepts and keywords from source code comments. Concept extraction and optimization can be completed without human intervention, greatly improving the automation level of test case generation.

[0043] (2) Highly targeted: The present invention can filter out irrelevant information by performing refined natural language processing on annotations, including text classification, named entity recognition, and sentiment analysis, ensuring that the data used to generate test cases are highly relevant, thereby generating more targeted test cases.

[0044] (3) Efficient case optimization mechanism: The present invention uses the PSO optimization algorithm to streamline test cases, reduce the time and resource consumption of test execution, and improve the quality and relevance of test cases.

[0045] (4) Strong dynamic adaptability: The present invention has a self-updating function and can automatically adjust test cases as software changes to maintain the timeliness and effectiveness of the test. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] Figure 1 The figure is a flow chart of a method for generating software test cases based on semantic analysis and optimization algorithm provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0047] Now, exemplary embodiments of the present invention will be described in detail with reference to the accompanying drawings. It should be understood that the embodiments shown and described in the accompanying drawings are only exemplary and are intended to explain the principles and spirit of the present invention, rather than to limit the scope of the present invention.

[0048] The embodiment of the present invention provides a method for generating software test cases based on semantic analysis and optimization algorithm, such as Figure 1 As shown, the following steps S1 to S4 are included:

[0049] S1. Obtain a source code annotation dataset from an open source code hosting platform, and preprocess the source code annotations therein to obtain preprocessed data.

[0050] In an embodiment of the present invention, a source code annotation dataset is composed of source code annotations in multiple software projects. These annotations usually include a developer's description of code functions and expected behaviors, which can be used as a basis for generating test cases.

[0051] In the embodiment of the present invention, natural language processing (NLP) technology is used to pre-process the source code comments. Natural language processing technology includes text classification (TC), named entity recognition (NER) and sentiment analysis (SA) to finely screen the collected comments. This process is aimed at removing all irrelevant content to ensure that the data finally used for analysis is highly targeted and effective.

[0052] S2. Based on the latent semantic analysis method, the concepts in the annotations are extracted from the preprocessed data, and based on the TextRank algorithm, the keywords in the annotations are extracted from the preprocessed data.

[0053] Latent semantic analysis (LSA) is a statistical analysis method used to identify hidden semantic structures in a document set. It includes the following steps A1~A7:

[0054] A1. Perform word segmentation on the text in the preprocessed data to obtain word vectors.

[0055] A2. Perform stemming and lemmatization on the word vector to obtain a standardized word vector.

[0056] A3. Remove stop words from the standardized word vector to obtain the cleaned word vector.

[0057] A4. Calculate the word frequency in the cleaned word vector and construct a word-document matrix.

[0058] A5. Perform singular value decomposition on the word-document matrix to obtain a singular value decomposition matrix.

[0059] In the embodiment of the present invention, the formula for performing singular value decomposition is:

[0060] ;

[0061] in represents the word-document matrix, represents the left singular vector matrix, represents a diagonal matrix of singular values, represents the right singular vector matrix.

[0062] In LSA, the vectors corresponding to the first k largest singular values ​​are usually retained to form a low-dimensional matrix , which can reduce the dimension of the data while maintaining the main semantic information.

[0063] A6. Perform dimensionality reduction processing on the singular value decomposition matrix to obtain a reduced-dimensional matrix.

[0064] A7. Perform concept representation based on the dimensionality reduction matrix to obtain the concepts in the annotations.

[0065] Step A7 includes the following sub-steps A71 to A73:

[0066] A71. Map the dimensionality reduction matrix to the semantic space. Each vector in the dimensionality reduction matrix represents an annotation, and its coordinate value represents the distribution of the annotation in each latent semantic dimension.

[0067] A72. Analyze the distribution of vectors in the semantic space and identify patterns or clusters with significant features that correspond to the concepts contained in the annotated text.

[0068] A73. Define and describe the identified concepts based on the high-frequency words and phrases in the annotation text and the distribution characteristics in the semantic space to ensure that the concepts are clear and easy to understand.

[0069] TextRank is an unsupervised learning method based on the PageRank algorithm, which is used for text summarization and keyword extraction. It includes the following steps B1~B3:

[0070] B1. Construct the text in the preprocessed data into a directed graph ,in is a node set, representing the words in the text, is the set of connecting edges between nodes, indicating the similarity between words.

[0071] B2. Assign a weight to each node through iterative calculation.

[0072] In the embodiment of the present invention, the weight distribution formula is:

[0073] ;

[0074] in represents the weight of node i at the t+1th iteration, d represents the damping factor, represents the set of all nodes pointing to node i, represents the weight of node j at the tth iteration, Represents the number of outgoing edges owned by node j.

[0075] B3. The words corresponding to the N nodes with the highest weights are used as keywords in the annotation, where N represents the preset number of keyword extractions.

[0076] S3. Optimize the selection and sorting of concepts and keywords based on the particle swarm optimization algorithm to generate a test case set.

[0077] The Particle Swarm Optimization (PSO) algorithm simulates group behavior to find the best solution, moves particles in the search space, and iterates and updates the search strategy based on the interaction between particles and experience to achieve the optimization effect. The most relevant and effective concepts and keywords are selected through the PSO algorithm to form the basis of the test case.

[0078] Step S3 includes the following sub-steps S31 to S33:

[0079] S31. Use concepts and keywords as particles in the particle swarm optimization algorithm and initialize the particle swarm.

[0080] S32. Set the number of iterations and update the position and velocity of the particle in each iteration.

[0081] In the embodiment of the present invention, the formula for updating the position and velocity of a particle is:

[0082] ;

[0083] ;

[0084] in represents the position of particle a at the b+1th iteration, represents the position of particle a at the bth iteration, represents the velocity of particle a at the bth iteration, represents the velocity of particle a at the b+1th iteration, represents the inertia weight, represents cognitive parameters, represents social parameters, and Are all random numbers, indicating represents the optimal position of particle a, represents the best position among all particles.

[0085] S33. In response to reaching the number of iterations, M particles with the highest fitness are selected from the final particle group as test cases to generate a test case set, where M represents a preset number of test cases.

[0086] In the embodiment of the present invention, after the preliminary test cases are generated by the PSO algorithm, new cases that ensure the validity of the test cases are generated by an automated tool and added to the existing test case set.

[0087] S4. Update and maintain the test case set regularly.

[0088] In the embodiment of the present invention, the test case set is regularly updated and maintained to adapt to the updates and changes of the software and ensure the effectiveness and integrity of the test. The LSA, TextRank and PSO algorithms are reapplied to the updated test case set to select the most effective and software defect-detecting test cases, and the test case set is optimized based on the latest software changes.

[0089] The present invention uses advanced natural language processing technologies, such as text classification, named entity recognition and sentiment analysis, combined with latent semantic analysis, TextRank algorithm and particle swarm optimization algorithm, to extract key information from software requirement documents, intelligently generate test cases, and further optimize case sets to ensure coverage of all key functional points, while reducing redundant and invalid tests, thereby improving test efficiency and cost-effectiveness. The present invention can respond to instant changes in software iterations, automatically adjust and update test cases, greatly optimize the test process, reduce manual operations of testers, ensure the stability and security of the software system, and effectively improve the efficiency and accuracy of testing work.

[0090] Those skilled in the art will appreciate that the embodiments described herein are intended to help readers understand the principles of the present invention, and should be understood that the protection scope of the present invention is not limited to such specific statements and embodiments. Those skilled in the art can make various other specific variations and combinations that do not deviate from the essence of the present invention based on the technical revelations disclosed by the present invention, and these variations and combinations are still within the protection scope of the present invention.

Claims

1. A method for generating software test cases based on semantic analysis and optimization algorithm, characterized in that: The following steps are involved: S1. Obtain a source code annotation dataset from an open source code hosting platform, and preprocess the source code annotations therein to obtain preprocessed data; S2, extracting concepts in annotations from preprocessed data based on latent semantic analysis, and extracting keywords in annotations from preprocessed data based on TextRank algorithm; S3, optimizing the selection and sorting of concepts and keywords based on the particle swarm optimization algorithm, and generating a test case set; S4. Update and maintain the test case set regularly.

2. The method for generating software test cases based on semantic analysis and optimization algorithm according to claim 1, characterized in that: In step S1, natural language processing technology is used to pre-process the source code annotations, and the natural language processing technology includes text classification, named entity recognition and sentiment analysis.

3. The method for generating software test cases based on semantic analysis and optimization algorithm according to claim 1, characterized in that: The potential semantic analysis method in step S2 comprises the following steps: A1. Perform word segmentation on the text in the preprocessed data to obtain word vectors; A2. Stemming and lemmatization are performed on the word vector to obtain a standardized word vector. A3. Remove stop words from the standardized word vector to obtain the cleaned word vector; A4. Calculate the word frequency in the cleaned word vectors and construct a word-document matrix. A5. Perform singular value decomposition on the word-document matrix to obtain a singular value decomposition matrix; A6. Perform dimensionality reduction processing on the singular value decomposition matrix to obtain a dimensionality reduction matrix; A7. Perform concept representation based on the dimensionality reduction matrix to obtain the concepts in the annotations.

4. The method for generating software test cases based on semantic analysis and optimization algorithm according to claim 3, characterized in that: The formula for performing singular value decomposition in step A5 is: ; in represents the word-document matrix, represents the left singular vector matrix, represents a diagonal matrix of singular values, represents the right singular vector matrix.

5. The method for generating software test cases based on semantic analysis and optimization algorithm according to claim 3, characterized in that: The step A7 comprises the following sub-steps: A71. Map the dimension reduction matrix to the semantic space. Each vector in the dimension reduction matrix represents an annotation, and its coordinate value represents the distribution of the annotation in each potential semantic dimension. A72. Analyze the distribution of vectors in the semantic space and identify patterns or clusters with significant characteristics, wherein the patterns or clusters correspond to concepts contained in the annotation text; A73. Define and describe the identified concepts based on the high-frequency words and phrases in the annotation text and the distribution characteristics in the semantic space.

6. The method for generating software test cases based on semantic analysis and optimization algorithm according to claim 1, characterized in that: The TextRank algorithm in step S2 includes the following steps: B1. Construct the text in the preprocessed data into a directed graph ,in is a node set, representing the words in the text, is the set of connecting edges between nodes, indicating the similarity between words; B2. Assign a weight to each node through iterative calculation; B3. The words corresponding to the N nodes with the highest weights are used as keywords in the annotation, where N represents the preset number of keyword extractions.

7. The method for generating software test cases based on semantic analysis and optimization algorithm according to claim 6, characterized in that: The weight distribution formula in step B2 is: ; in represents the weight of node i at the t+1th iteration, d represents the damping factor, represents the set of all nodes pointing to node i, represents the weight of node j at the tth iteration, Represents the number of outgoing edges owned by node j.

8. The method for generating software test cases based on semantic analysis and optimization algorithm according to claim 1, characterized in that: The step S3 comprises the following sub-steps: S31, using concepts and keywords as particles in a particle swarm optimization algorithm, and initializing the particle swarm; S32, setting the number of iterations, and updating the position and velocity of the particle in each iteration; S33. In response to reaching the number of iterations, M particles with the highest fitness are selected from the final particle group as test cases to generate a test case set, where M represents a preset number of test cases.

9. The method for generating software test cases based on semantic analysis and optimization algorithm according to claim 8, characterized in that: The formula for updating the position and velocity of the particle in step S32 is: ; ; in represents the position of particle a at the b+1th iteration, represents the position of particle a at the bth iteration, represents the velocity of particle a at the bth iteration, represents the velocity of particle a at the b+1th iteration, represents the inertia weight, represents cognitive parameters, represents social parameters, and Are all random numbers, indicating represents the optimal position of particle a, represents the best position among all particles.

Citation Information

Patent Citations

  • Method and device for text classification

    CN101634983A

  • Test case generation method and device, computer equipment and storage medium

    CN117573549A

  • Test case generation model construction method and test case generation method and device

    CN117609050A

  • Code verification method and device, equipment and storage medium

    CN118796656A

  • Keyword extraction model training method, keyword extraction method, and computer device

    WO2020114429A1