Test case generation method and device, computer program product and electronic equipment
Through weighting algorithms and semantic graph construction technology based on semantic distance, the problems of low efficiency and insufficient accuracy of test cases are solved, the accuracy and generation efficiency of test cases are improved, and the testing needs are fully covered.
Patent Information
- Application Number
- CN202411534540.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-30
- Publication Date
- 2024-12-03
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In the prior art, the generation efficiency of test cases is low and the accuracy is insufficient, resulting in large workloads and low accuracy of testers.
A weighting algorithm based on semantic distance is used to extract keywords of document information, and entity recognition and relationship extraction are combined with test case templates to build a test case semantic graph, and target test cases are generated.
It improves the accuracy and relevance of keywords, enhances the correlation between the generated test cases and the user input document information, improves the accuracy and usability of test cases, simplifies the test case generation process, and fully covers the test requirements.
Smart Images

Figure CN119065984A_ABST
Abstract
Description
Background Art
[0002] In the field of software testing, writing test cases is an important and tedious task.
[0003] In the related art, test case writing requires testers to manually write according to test requirements, which is labor-intensive; test cases have limitations, the accuracy of test cases is low, and the generation efficiency of test cases is low. Summary of the invention
[0004] The purpose of the present disclosure is to provide a test case generation method, a test case generation device, a computer program product and an electronic device, thereby at least to a certain extent overcoming the problems of low test case generation efficiency and low accuracy caused by the limitations and defects of related technologies.
[0005] According to one aspect of the present disclosure, a test case generation method is provided, comprising: obtaining document information and a test case template of an object to be tested; performing keyword extraction on the document information based on a weighted algorithm of semantic distance to obtain test case keywords; performing entity recognition and relationship extraction on the test case template to determine test case entities and semantic relationships of the test cases to construct a test case semantic graph; classifying the test cases according to the test case keywords, test case entities and semantic relationships to obtain classification results, and inputting the classification results and the test case semantic graph into the test case template to generate a target test case for the object to be tested.
[0006] In an exemplary embodiment of the present disclosure, a weighted algorithm based on semantic distance is used to extract keywords from document information to obtain test case keywords, including: performing text preprocessing on the document information to obtain text, text collection, text topic and vocabulary collection corresponding to the document information; traversing the vocabulary collection to obtain the word frequency-inverse file frequency of each word in the vocabulary collection in the document; determining the semantic distance between the word and the text topic; and determining a weighted algorithm based on semantic distance according to the word frequency-inverse file frequency and the semantic distance to perform keyword extraction.
[0007] In an exemplary embodiment of the present disclosure, determining the semantic distance between a vocabulary and a text topic includes: if the data volume of the vocabulary set is greater than or equal to the data volume threshold, determining the semantic distance between the vocabulary and the text topic through a word embedding model; if the data volume of the vocabulary set is less than the data volume threshold, determining the semantic distance between the vocabulary and the text topic through a semantic network.
[0008] In an exemplary embodiment of the present disclosure, the semantic distance between vocabulary and text topics is determined through a word embedding model, including: obtaining a word vector file based on document information after text preprocessing; converting the word vector file into a dictionary, and searching from the dictionary to obtain word vectors corresponding to the vocabulary and text topics; determining the similarity between the vocabulary and the text topic to determine the semantic distance.
[0009] In an exemplary embodiment of the present disclosure, the semantic distance between a word and a text topic is determined through a semantic network, including: using an interface of the semantic network to find a synonym set of the word and the text topic in the semantic network; determining the shortest path connecting the synonym set of the word and the text topic in the semantic network through the interface of the semantic network, and determining the semantic distance based on the shortest path.
[0010] In an exemplary embodiment of the present disclosure, a weighted algorithm based on semantic distance is determined according to the word frequency-reverse file frequency and the semantic distance to perform keyword extraction, including: determining a weighted algorithm based on semantic distance according to the word frequency-reverse file frequency and the semantic distance to determine a weight value for each word; extracting keywords from multiple words according to the weight values.
[0011] In an exemplary embodiment of the present disclosure, entity recognition and relationship extraction are performed on the test case template to determine the test case entities and the semantic relationships in the test cases to construct a test case semantic graph, including: using named entity recognition to identify the test case entities in the test case template; identifying the semantic relationships between the test case entities and multiple test case structures in the test case template through relationship extraction; and constructing a test case semantic graph based on the semantic relationships.
[0012] According to one aspect of the present disclosure, a test case generation device is provided, including: a document acquisition module, used to acquire document information and a test case template of an object to be tested; a keyword extraction module, used to extract keywords from the document information based on a weighted algorithm of semantic distance to obtain test case keywords; a semantic relationship determination module, used to perform entity recognition and relationship extraction on the test case template, determine the test case entities and the semantic relationships of the test cases, and construct a test case semantic graph; a test case determination module, used to classify the test cases according to the test case keywords, the test case entities and the semantic relationships to obtain a classification result, and input the classification result and the test case semantic graph into the test case template to generate a target test case for the object to be tested.
[0013] According to one aspect of the present disclosure, a computer program product is provided, including a computer program, wherein when the computer program is executed by a processor, the test case generating method described in any one of the above is implemented.
[0014] According to one aspect of the present disclosure, there is provided an electronic device, including: a processor; and A memory for storing executable instructions of the processor; wherein the processor is configured to execute any one of the test case generation methods described above by executing the executable instructions.
[0015] In the technical solution provided in the embodiments of the present disclosure, on the one hand, by extracting keywords from document information using a weighted algorithm based on semantic distance, the importance of vocabulary in a document can be more accurately evaluated, and the accuracy of keywords and the relevance of keywords to text topics are improved. On the other hand, since the correlation between test case keywords and document information input by the user is higher, the correlation between the generated target test case and the document information input by the user is improved, and the accuracy and availability of the target test case are improved. On another hand, since the target test case can be automatically generated based on the test case keywords, test case entities and semantic relationships in combination with the test case template, the generation efficiency and comprehensiveness of the test case are improved, and the test requirements can be fully covered.
[0016] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The accompanying drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the specification are used to explain the principles of the present disclosure. Obviously, the accompanying drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without creative work.
[0018] Figure 1 A flowchart of a test case generation method in an embodiment of the present disclosure is schematically shown.
[0019] Figure 2 The flowchart of extracting keywords in the embodiment of the present disclosure is schematically shown.
[0020] Figure 3 The overall framework diagram for generating test cases in the embodiment of the present disclosure is schematically shown.
[0021] Figure 4 The specific process diagram of test case generation in the embodiment of the present disclosure is schematically shown.
[0022] Figure 5 The block diagram of the test case generating device in the embodiment of the present disclosure is schematically shown.
[0023] Figure 6The block diagram of the electronic device according to the embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION
[0024] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as being limited to the examples set forth herein; on the contrary, these embodiments are provided so that the present disclosure will be more comprehensive and complete, and the concepts of the example embodiments are fully conveyed to those skilled in the art. The described features, structures, or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced while omitting one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known technical solutions are not shown or described in detail to avoid obscuring various aspects of the present disclosure.
[0025] In addition, the accompanying drawings are only schematic illustrations of the present disclosure and are not necessarily drawn to scale. The same reference numerals in the figures represent the same or similar parts, and their repeated description will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or implemented in one or more hardware modules or integrated circuits, or implemented in different networks and / or processor devices and / or microcontroller devices.
[0026] In order to solve the above technical problems, the present disclosure provides a test case generation method, which can be applied to any type of automated test scenario or software test scenario to generate test cases for implementing automated testing or software testing. Figure 1 As shown in , the test case generation method mainly includes the following steps: In step S110, the document information of the object to be tested and the test case template are obtained; In step S120, keyword extraction is performed on the document information based on a weighted algorithm of semantic distance to obtain test case keywords; In step S130, entity recognition and relationship extraction are performed on the test case template to determine the test case entities and semantic relationships to construct a test case semantic graph; In step S140, test cases are classified according to test case keywords, test case entities and semantic relationships to obtain classification results, and the classification results and test case semantic graphs are filled into the test case template to generate target test cases for the object to be tested.
[0027] The technical solution provided in the embodiments of the present disclosure, on the one hand, can more accurately evaluate the importance of vocabulary in a document by extracting keywords from document information through a weighted algorithm based on semantic distance, thereby improving the accuracy of keywords and the relevance of keywords to text topics. On the other hand, since the correlation between the test case keywords and the document information input by the user is higher, the correlation between the generated target test case and the document information input by the user is improved, thereby improving the accuracy and availability of the target test case. On another hand, since the target test case can be automatically generated based on the test case keywords, test case entities and semantic relationships in combination with the test case template, the generation efficiency and comprehensiveness of the test case are improved, and the test requirements can be fully covered.
[0028] Next, refer to Figure 1 The test case generation method in the embodiment of the present disclosure is specifically described as shown in FIG.
[0029] In step S110, the document information of the object to be tested and the test case template are obtained.
[0030] In the disclosed embodiments, the object to be tested may be any type of object. Document information input by a user may be collected, and the document information may include an interface document and a user manual of the object to be tested, and may also include other information related to the object to be tested. A test case template refers to a template for generating a test case. For different objects to be tested, their test templates may be the same or different, and are not specifically limited here.
[0031] Exemplarily, the document information generally includes information such as interface data. The test case template is used to represent the information included in the test case, for example, it may include test items, function names, module names, error codes, test titles, preconditions, inputs, test steps, expected outputs, expected results, test results, etc.
[0032] In step S120, a weighted algorithm based on semantic distance is used to extract keywords from the document information to obtain test case keywords.
[0033] In the disclosed embodiment, before keyword extraction, text preprocessing may be performed first. Exemplarily, the received document information may be subjected to text cleaning and word segmentation processing to obtain text, text set, text theme and vocabulary set corresponding to the document information. In addition, the test case structure recognition may be performed on the test case template to obtain multiple test case structures in the test case template, and the multiple test case structures may be, for example, test steps and expected results, etc.
[0034] The steps for text preprocessing of document information may include: removing irrelevant information such as HTML tags, special characters, comments, etc. from the document information through regular expressions, and removing stop words (such as "de", "shi", etc.) to obtain the text and text set; using the HanLP tool to tokenize the text to obtain the text theme and vocabulary set. In addition, different parts in the test case template are identified by matching the test case template through regular expressions to realize the recognition of the test case structure in the test case template, such as identifying the test steps and expected results in the test case template.
[0035] After completing the text preprocessing of the document information, keyword extraction can be performed on the preprocessed document information of the text based on a weighted algorithm of semantic distance to obtain test case keywords. In some embodiments, first, the TF-IDF (Term Frequency_Inverse Document Frequency) of each vocabulary in the vocabulary set can be calculated, and further, the semantic distance between the vocabulary and the text theme can be calculated. The TF-IDF of each vocabulary is corrected based on the semantic distance to adjust the weight value of the vocabulary, and keyword extraction is performed based on the weight value of the vocabulary.
[0036] Figure 2 Schematically shows the flowchart of keyword extraction, refer to Figure 2 as shown in, mainly includes the following steps: In step S210, obtain the text, text set, text theme, and vocabulary set corresponding to the document information; In step S220, traverse the vocabulary set to obtain the term frequency-inverse document frequency of each vocabulary in the vocabulary set in the document; In step S230, determine the semantic distance between the vocabulary and the text theme; In step S240, determine the weighted algorithm based on semantic distance according to the term frequency-inverse document frequency and semantic distance, and perform keyword extraction according to the weighted algorithm based on semantic distance.
[0037] In the embodiments of the present disclosure, based on the text, text set, and vocabulary set obtained through text preprocessing, traverse the vocabulary set, and use the basic TF-IDF algorithm to multiply the term frequency value TF of each vocabulary by the inverse frequency value IDF to obtain the term frequency-inverse document frequency TF-IDF of each vocabulary in the vocabulary set, that is, the TF-IDF value of each vocabulary in the document (text). The specific algorithm is shown in formula (1): Formula (1) Among them, is the vocabulary, is the text, is a collection of texts. The word frequency is used to indicate how often a term (keyword) appears in a text. The TF-IDF value is used to evaluate the importance of a word to a document set or one of the documents in a corpus. The TF-IDF value is used to filter out common words and retain important words.
[0038] Next, we can define the vocabulary With text theme The semantic distance between Can be used to optimize vocabulary weights.
[0039] When determining the semantic distance, a word embedding model or a semantic network can be selected to determine the semantic distance between a word and a text topic according to the size relationship between the data volume of the vocabulary set and the data volume threshold. In some embodiments, if the data volume of the vocabulary set is greater than or equal to the data volume threshold The semantic distance is calculated through the word embedding model; if the data volume of the vocabulary set is less than the data volume threshold, the semantic distance is calculated through the semantic network. is a vocabulary set, The data volume threshold for the custom vocabulary set can be set to 1000, 5000 or other values. Test cases with vocabulary data volume exceeding the data volume threshold are complex test cases.
[0040] If the amount of data in the vocabulary set is greater than or equal to the data amount threshold , the semantic distance calculation through the word embedding model can include the following steps: Step 1: Get the word vector file, use the document information obtained after text preprocessing as the training corpus, get the word vector file, and load the word embedding model, such as the GloVe model.
[0041] Among them, GloVe (Global Vectors for Word Representation) is a method for learning word vectors by training a large amount of text data, which specifically includes the following steps: collect text data as a training corpus; traverse the entire training corpus, count the number of co-occurrences of each pair of words, and form a word co-occurrence matrix, in which each element represents the number of times two words co-occur in the same context; define the loss function, and the loss function of GloVe is designed to minimize the dot product between two word vectors and the square difference of their co-occurrence times in the word co-occurrence matrix. The goal of this loss function is to make the word vector learned by the model reflect the co-occurrence information in the dot product space; start training, first randomly initialize the word vector of each word, use the stochastic gradient descent algorithm to adjust the parameters of the word vector to minimize the loss function, and optimize the word vector through multiple iterations until the loss function converges or reaches the preset training round; after the training is completed, each word corresponds to a learned word vector, and these word vectors are saved as files, usually stored in text form, to obtain the word vector file.
[0042] Step 2: read the word vector file and convert the word vector file into a dictionary. For example, the word vector file can be converted into a dictionary.
[0043] Step 3: Search the dictionary to obtain the word vectors corresponding to the vocabulary and text topics.
[0044] Step 4: Calculate the cosine value of the angle between the word vectors corresponding to the vocabulary and the text topic, and measure the similarity between the vocabulary and the text topic based on the cosine value of the angle.
[0045] Among them, the cosine of the angle is a method to measure the similarity of the directions of two vectors. In the vector space, the cosine of the angle between two non-zero vectors can be obtained by dividing the dot product (inner product) of the two vectors by the product of their moduli (lengths). The value range of the cosine of the angle is [−1,1]. When the directions of the two vectors are exactly the same (that is, the angle is 0 degrees), the cosine value is 1; when the directions of the two vectors are completely opposite (that is, the angle is 180 degrees), the cosine value is -1; when the two vectors are perpendicular, the cosine value is 0. Therefore, the closer the cosine of the angle is to 1, the closer the directions of the two vectors are and the higher the similarity; the closer the value is to -1, the lower the similarity. The semantic distance is further determined based on the similarity. .
[0046] If the amount of data in the vocabulary set is less than the data amount threshold ,The process of calculating semantic distance through semantic network can include the following steps: Step 1: Use the interface API of the semantic network WordNet to find the synonym sets of the two words to be compared in the semantic network WordNet; the two words to be compared may include words and text topics.
[0047] The semantic network WordNet is a large dictionary database that organizes words into a network according to their semantic relationships.
[0048] Step 2: Use the interface API of the semantic network WordNet to find the shortest path of the synonym set connecting the vocabulary and the text topic in the semantic network WordNet.
[0049] Step 3: Determine the semantic distance based on the shortest path. The shortest path represents the distance between the word and the text topic in the semantic network. The shorter the path length, the closer the semantics of the two words are; the longer the path length, the greater the semantic difference between the two words, and the semantic distance is derived from this.
[0050] In the disclosed embodiment, a word embedding model or a semantic network is selected to determine the semantic distance between a word and a text topic through the comparison result between the data volume of a vocabulary set and the data volume threshold. The semantic network represents the semantic relationship between words through a synonym set and a semantic relationship network, and has a strong understanding of the basic semantic relationship between words. Although the word embedding model requires relatively more resources and time, it can measure the semantic similarity between words through the distance in the vector space. This method can capture the subtle differences between words and can more comprehensively reflect the semantic relationship between words, thereby improving the accuracy of the semantic distance.
[0051] After determining the semantic distance, the word frequency-reverse file frequency can be corrected based on the calculated semantic distance to obtain a weighted algorithm based on semantic distance to correct the weight value of the vocabulary. Exemplarily, the TF-IDF weighted algorithm based on semantic distance can be determined according to the product of the word frequency-reverse file frequency and the inverse of the semantic distance to obtain the weight value of the vocabulary. In addition, the semantic distance and the word frequency-reverse file frequency can be combined in other ways to obtain the weight value of the vocabulary. No specific limitation is made here, as long as the weight value is negatively correlated with the semantic distance. By adjusting the weight value of the vocabulary in combination with the semantic distance and the word frequency-reverse file frequency, it is possible to make the vocabulary with stronger relevance obtain a higher weight value. The TF-IDF weighted algorithm based on semantic distance can be shown as formula (2): Formula (2) in, Used to represent the weight value of the vocabulary, is a small positive number used to prevent division by zero.
[0052] After obtaining the weight values of the words, the words whose weight values meet the screening conditions can be determined as test case keywords. For example, the words whose weight values are greater than the weight threshold can be used as test case keywords, or the words ranked in the top N positions can be used as test case keywords, which are not specifically limited here.
[0053] In the disclosed embodiment, the weight value of the vocabulary is corrected by the TF-IDF weighted algorithm based on the semantic distance, and the keyword extraction is performed on the document information after text preprocessing based on the weight value to obtain the test case keywords. By introducing the semantic distance to optimize the weight value of the vocabulary, the weight value of the vocabulary with low relevance to the topic can be reduced, the extraction of redundant keywords can be reduced, the vocabulary that is strongly related to the text topic can be more accurately identified, and the relevance between the keywords and the document information input by the user can be improved.
[0054] Continue to refer Figure 1 As shown in , in step S130 , entity recognition and relationship extraction are performed on the test case template to determine the test case entities and the semantic relationships of the test cases to construct a test case semantic graph.
[0055] In the disclosed embodiment, entity recognition can be performed on the test case template to obtain the test case entity in the test case template. The test case entity can be, for example, a function name, a module name, and an error code in the test case template. Exemplarily, entity recognition can be performed by named entity recognition to obtain the test case entity in the test case template, or the test case entity in the test case template can be identified by other methods, which are not specifically limited here.
[0056] Relationship extraction refers to the extraction of semantic relationships. Relationship extraction can be performed on test case templates to obtain semantic relationships therein, such as obtaining the semantic relationship between a test case entity in a test case template and multiple test case structures, such as obtaining the semantic relationship between a test case entity and test steps and test case structures such as expected results.
[0057] Further, a test case semantic graph can be constructed based on the semantic relationship between the entity and the multiple test case structures, so as to establish an association between the test case entity and the multiple test case structures in the test case template through the test case semantic graph, thereby determining the test case structure and logic of the test case template. Exemplarily, the test case entity can be used as a node, and each test case structure that has a semantic relationship with the test case entity can be used as a child node to construct a test case semantic graph.
[0058] Continue to refer Figure 1As shown in , in step S140, test cases are classified according to test case keywords, test case entities and semantic relationships to obtain classification results, and the classification results and test case semantic graphs are input into the test case template to generate target test cases for the object to be tested.
[0059] In the disclosed embodiment, test case classification can be performed based on test case keywords, extracted test case entities, extracted semantic relationships, etc. to obtain classification results. For example, classification can be performed based on semantic relationships, such as taking the same or similar semantic relationships as a category to obtain classification results.
[0060] Further, based on the test case template input by the user, the classification results and the test case semantic graph can be filled into the test case template, and a new test case can be generated as a target test case and output. Exemplarily, the test case template can include different modules, and the different modules can be arranged in order. The test case semantic graph can be a collection of different modules, which may also include multiple modules, but the arrangement order of multiple modules is not fixed. For example, the first position can be a test result, the second position can be a test function, and so on.
[0061] Based on this, the classification results and the test case semantic graph can be filled into the test case template according to the arrangement order of the test case template, so as to generate the target test case related to the document information.
[0062] In the disclosed embodiment, since the correlation between the test case keywords and the document information input by the user is higher, the correlation between the generated target test case and the document information input by the user is improved, and the accuracy and availability of the target test case are improved. In addition, since the test case semantic graph can be extracted and the target test case is generated based on the test case keywords, test case entities and test case semantic graph, the problem of being unable to fully cover all software requirements in the related art is avoided, and all contents in the test case template can be covered, avoiding information omissions, and improving the integrity and accuracy of the test case. Since the test case can be automatically generated according to the document information, the problem of complex test case update process during the software update process is avoided, the test case update process is simplified, and the test case update efficiency is improved.
[0063] In the disclosed embodiments, the text preprocessing, keyword extraction, test case entity recognition, and test case classification modules are strengthened to achieve a deeper analysis of the test case structure, semantic extraction, and the output of the test case, and by using keywords extracted based on the semantic distance TF-IDF weighted algorithm, the generated test cases will be more relevant to the text input by the user and have higher usability.
[0064] Figure 3 The overall flow chart for generating test cases is shown schematically in Figure 3 As shown in , it mainly includes the following steps: In step S310, the test case template and document information such as the interface document and user manual of the object under test are obtained.
[0065] In step S320, the document information is subjected to text preprocessing, and the test case structure is recognized for the test case template. The text preprocessing includes text cleaning and word segmentation.
[0066] In step S330, keyword extraction is performed on the document information to obtain test case keywords. Specifically, keyword extraction is performed using a TF-IDF weighted algorithm based on semantic distance.
[0067] For example, input a document related to virtualization technology, whose text topic can be virtualization technology. The basic TF-IDF algorithm is used to extract keywords from the document, and keywords such as "virtualization", "virtual machine", and "resource allocation" are extracted; then the semantic distance between the keywords and the text topic is calculated. Although "resource allocation" appears less frequently in the document, the calculated semantic distance between "resource allocation" and "virtualization technology" is very close, so a comprehensive score is obtained and the weight of "resource allocation" is strengthened. Based on this, "resource allocation" can be used as a test case keyword.
[0068] In step S340, entity recognition and relationship extraction are performed on the test case template to obtain a test case entity and a semantic relationship between the test case entity and a plurality of test case structures.
[0069] In step S350, the test cases are classified and output. Specifically, the test cases are classified according to features such as test case keywords, test case entities and semantic relationships to obtain classification results. Based on the test case template input by the user, the classification results and the test case semantic graph are injected to generate and output new test cases.
[0070] In the above process, by calculating the semantic similarity between words to improve the TF-IDF value, the importance of words in the document can be more accurately evaluated, the accuracy of keywords and the relevance of keywords to text topics can be improved. Based on this, the accuracy of the TF-IDF weighted algorithm based on semantic distance has been improved in tasks such as text classification, clustering, and similarity calculation. It can better capture the semantic relationship between documents, thereby returning more relevant and accurate results. Because semantic information is taken into account, the TF-IDF weighted algorithm based on semantic distance can handle more complex text processing tasks.
[0071] Figure 4The specific flow chart for generating test cases is shown schematically. Figure 4 As shown in , it mainly includes the following steps: In step S402, document information and test case templates are collected.
[0072] In step S404, text preprocessing is performed on the document information, and test case structure recognition is performed on the test case template.
[0073] In step S406, keyword extraction is performed on the document information after text preprocessing to obtain test case keywords. Specifically, the test case keywords are extracted using a TF-IDF weighted algorithm based on semantic distance. The main steps include: In step S4060, the TF-IDF value is calculated.
[0074] In step S4062, the semantic distance is determined. The process of determining the semantic distance may include steps S4064 to S4068. Among them: In step S4064, it is determined whether the data volume of the vocabulary set is greater than the data volume threshold. If yes, the process goes to step S4066; if no, the process goes to step S4068.
[0075] In step S4066, the semantic distance is determined based on the word embedding model.
[0076] In step S4068, a semantic network is constructed to calculate the semantic distance.
[0077] In step S408, the weight value of the vocabulary is adjusted in combination with the TF-IDF value and the semantic distance to obtain the test case keywords.
[0078] In step S410, entity recognition and relationship extraction are performed on the test case template to obtain the test case entity and the semantic relationship between the test case entity and the test case structure.
[0079] In step S412, the test cases are classified and output.
[0080] In the disclosed embodiment, by generating test cases based on the semantic distance TF-IDF weighted algorithm, the method can automatically extract key information from the test requirements and generate test cases that meet the test specifications and requirements based on this. By improving the accuracy and generation efficiency of test cases based on the semantic distance TF-IDF weighted algorithm, the workload of testers is reduced and the test quality and efficiency are improved.
[0081] The present disclosure also provides a test case generation device. Figure 5 As shown, the test case generating device 500 mainly includes the following modules: The document acquisition module 501 is used to acquire the document information of the object to be tested and the test case template; A keyword extraction module 502 is used to extract keywords from the document information based on a weighted algorithm of semantic distance to obtain test case keywords; The semantic relationship determination module 503 is used to perform entity recognition and relationship extraction on the test case template, determine the test case entities and the semantic relationship of the test case, so as to construct a test case semantic graph; The test case determination module 504 is used to classify the test cases according to the test case keywords, test case entities and semantic relationships to obtain classification results, and input the classification results and the test case semantic graph into the test case template to generate the target test case of the object to be tested.
[0082] In an exemplary embodiment of the present disclosure, a keyword extraction is performed on document information based on a weighted algorithm of semantic distance to obtain test case keywords, including: performing text preprocessing on the document information to obtain text, text collection, text topic and vocabulary collection corresponding to the document information; Traverse the vocabulary set to obtain the word frequency-inverse file frequency of each word in the vocabulary set in the document; determine the semantic distance between the word and the text topic; determine a weighted algorithm based on semantic distance according to the word frequency-inverse file frequency and the semantic distance to perform keyword extraction.
[0083] In an exemplary embodiment of the present disclosure, determining the semantic distance between a vocabulary and a text topic includes: if the data volume of the vocabulary set is greater than or equal to the data volume threshold, determining the semantic distance between the vocabulary and the text topic through a word embedding model; if the data volume of the vocabulary set is less than the data volume threshold, determining the semantic distance between the vocabulary and the text topic through a semantic network.
[0084] In an exemplary embodiment of the present disclosure, the semantic distance between vocabulary and text topics is determined through a word embedding model, including: obtaining a word vector file based on document information after text preprocessing; converting the word vector file into a dictionary, and searching from the dictionary to obtain word vectors corresponding to the vocabulary and text topics; determining the similarity between the vocabulary and the text topic to determine the semantic distance.
[0085] In an exemplary embodiment of the present disclosure, the semantic distance between a word and a text topic is determined through a semantic network, including: using an interface of the semantic network to find a synonym set of the word and the text topic in the semantic network; determining the shortest path connecting the synonym set of the word and the text topic in the semantic network through the interface of the semantic network, and determining the semantic distance based on the shortest path.
[0086] In an exemplary embodiment of the present disclosure, a weighted algorithm based on semantic distance is determined according to the word frequency-inverse document frequency and the semantic distance to perform keyword extraction, including: A weighted algorithm based on semantic distance is determined according to word frequency-inverse document frequency and semantic distance to determine the weight value of each word; and keywords are extracted from multiple words according to the weight values.
[0087] In an exemplary embodiment of the present disclosure, entity recognition and relationship extraction are performed on the test case template to determine the test case entities and the semantic relationships in the test cases to construct a test case semantic graph, including: using named entity recognition to identify the test case entities in the test case template; identifying the semantic relationships between the test case entities and multiple test case structures in the test case template through relationship extraction; and constructing a test case semantic graph based on the semantic relationships.
[0088] It should be noted that the specific details of each module in the above-mentioned test case generation device have been described in detail in the corresponding test case generation method, so they will not be repeated here.
[0089] It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied.
[0090] In addition, although the steps of the method in the present disclosure are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps, etc.
[0091] In an exemplary embodiment of the present disclosure, an electronic device capable of implementing the above method is also provided.
[0092] Those skilled in the art will appreciate that various aspects of the present disclosure may be implemented as systems, methods or program products. Therefore, various aspects of the present disclosure may be specifically implemented in the following forms, namely: complete hardware implementation, complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software, which may be collectively referred to herein as "circuits", "modules" or "systems".
[0093] Refer to the following Figure 6The electronic device 600 according to this embodiment of the present disclosure is described. Figure 6 The electronic device 600 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0094] like Figure 6 As shown, the electronic device 600 is in the form of a general computing device. The components of the electronic device 600 may include but are not limited to: at least one processing unit 610, at least one storage unit 620, a bus 630 connecting different system components (including the storage unit 620 and the processing unit 610), and a display unit 640.
[0095] The storage unit stores program codes, which can be executed by the processing unit 610, so that the processing unit 610 performs the steps according to various exemplary embodiments of the present disclosure described in the above “Exemplary Method” section of this specification. For example, the processing unit 610 can perform the following steps: Figure 1 Follow the steps shown in .
[0096] The storage unit 620 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 6201 and / or a cache memory unit 6202 , and may further include a read-only memory unit (ROM) 6203 .
[0097] The storage unit 620 may also include a program / utility 6204 having a set (at least one) of program modules 6205, such program modules 6205 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0098] Bus 630 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
[0099] The electronic device 600 may also communicate with one or more external devices 700 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 600, and / or communicate with any device that enables the electronic device 600 to communicate with one or more other computing devices (e.g., routers, modems, etc.). This communication may be performed through an input / output (I / O) interface 650. In addition, the electronic device 600 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) through a network adapter 660. As shown, the network adapter 660 communicates with other modules of the electronic device 600 through a bus 630. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 600, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, etc.
[0100] It should be noted that, in some embodiments of the present disclosure, a computer program product is also provided. The computer program product includes a computer program. When the computer program is executed by a processor, the above method is implemented.
[0101] In one embodiment, a computer program product may be a tangible product containing a computer program, such as a computer-readable storage medium storing a computer program. The readable storage medium may be a storage medium based on electrical, magnetic, optical, electromagnetic, infrared, and other signals, including but not limited to: random access memory (RAM), read-only memory (ROM), magnetic tape, floppy disk, flash memory (Flash), mechanical hard disk (HDD), solid state drive (SSD), and the like. Exemplarily, a computer program product may be implemented as a non-volatile storage medium storing a computer program, such as a read-only memory, a NAND flash memory (Nand Flash), and the like. In one embodiment, a computer program product may be an intangible product containing a computer program. Exemplarily, a computer program product may be implemented as a virtual digital product, such as a digital file such as an executable file, an installation package, etc. storing a computer program.
[0102] The code of the computer program can be written in one or more programming languages. Programming languages such as C language, Java, C++, etc. The program code can be executed completely on the user computing device, or partially on the user computing device, or as a separate software package, or partially on the user computing device and partially on the remote computing device, or completely on the remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, such as a local area network (LAN), a wide area network (WAN), etc., or can be connected to an external computing device (for example, through an Internet connection provided by an operator).
[0103] The computer program may be carried or transmitted via electrical, magnetic, optical, electromagnetic, infrared, or other signals. The electronic device may convert the signal carrying the computer program into a digital signal, thereby running the computer program. When the computer program runs on the electronic device, its code is used to enable the electronic device to execute (more specifically, enable the processor of the electronic device to execute) the method steps of various exemplary embodiments of the present disclosure.
[0104] Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes a number of instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the implementation of the present disclosure.
[0105] In addition, the above-mentioned figures are only schematic illustrations of the processes included in the method according to the exemplary embodiments of the present disclosure, and are not intended to be limiting. It is easy to understand that the processes shown in the above-mentioned figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.
[0106] It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied.
[0107] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing what is disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary technical means in the art that are not disclosed in the present disclosure. The specification and embodiments are to be considered merely as exemplary, and the true scope and spirit of the present disclosure are indicated by the claims.
[0108] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A test case generation method, characterized in that: include: Get the document information and test case template of the object to be tested; Extracting keywords from the document information based on a weighted algorithm of semantic distance to obtain test case keywords; Performing entity recognition and relationship extraction on the test case template to determine the test case entities and the semantic relationships of the test cases to construct a test case semantic graph; The test cases are classified according to the test case keywords, the test case entities and the semantic relationships to obtain classification results, and the classification results and the test case semantic graph are input into the test case template to generate the target test case of the object to be tested.
2. The test case generation method according to claim 1, characterized in that: The weighted algorithm based on semantic distance extracts keywords from the document information to obtain test case keywords, including: Performing text preprocessing on the document information to obtain text, text set, text topic and vocabulary set corresponding to the document information; Traversing the vocabulary set, obtaining the word frequency-inverse document frequency of each word in the vocabulary set in the document; Determine the semantic distance between words and the subject of the text; A weighted algorithm based on semantic distance is determined according to the word frequency-inverse document frequency and the semantic distance to perform keyword extraction.
3. The test case generation method according to claim 2, characterized in that: Determining the semantic distance between the vocabulary and the text topic includes: If the data volume of the vocabulary set is greater than or equal to the data volume threshold, the semantic distance between the vocabulary and the text topic is determined through the word embedding model; If the data volume of the vocabulary set is less than the data volume threshold, the semantic distance between the vocabulary and the text topic is determined through the semantic network.
4. The test case generation method according to claim 3, characterized in that: Determining the semantic distance between a word and a text topic through a word embedding model includes: Obtain word vector files based on document information after text preprocessing; Convert the word vector file into a dictionary, and search from the dictionary to obtain word vectors corresponding to vocabulary and text topics; Determine the similarity between words and text topics to determine semantic distance.
5. The test case generation method according to claim 3, characterized in that: Determining the semantic distance between the vocabulary and the text topic through the semantic network includes: Use the semantic network interface to find synonym sets for words and text topics in the semantic network; The shortest path connecting the synonym sets of the vocabulary and the text subject is determined in the semantic network through the interface of the semantic network, and the semantic distance is determined based on the shortest path.
6. The test case generation method according to claim 2, characterized in that: The step of determining a weighted algorithm based on semantic distance according to the word frequency-inverse file frequency and the semantic distance to extract keywords includes: Determining a weighting algorithm based on semantic distance according to the word frequency-inverse document frequency and the semantic distance to determine a weight value of each word; The keywords are extracted from a plurality of vocabularies according to the weight values.
7. The test case generation method according to claim 1, characterized in that: The performing entity recognition and relationship extraction on the test case template to determine the test case entities and the semantic relationships in the test case to construct a test case semantic graph includes: Use named entity recognition to identify test case entities in test case templates; Identify the semantic relationship between the test case entity and multiple test case structures of the test case template by relationship extraction; A test case semantic graph is constructed based on the semantic relationship.
8. A test case generating device, characterized in that: include: Document acquisition module, used to obtain document information and test case templates of the object to be tested; A keyword extraction module, used to extract keywords from the document information based on a weighted algorithm of semantic distance to obtain test case keywords; A semantic relationship determination module, used to perform entity recognition and relationship extraction on the test case template, determine the test case entities and the semantic relationship of the test case, so as to construct a test case semantic graph; The test case determination module is used to classify the test cases according to the test case keywords, the test case entities and the semantic relationships to obtain classification results, and input the classification results and the test case semantic graph into the test case template to generate the target test case of the object to be tested.
9. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the test case generation method according to any one of claims 1 to 7 is implemented.
10. An electronic device, characterized in that: include: processor; as well as A memory, configured to store executable instructions of the processor; The processor is configured to execute the test case generating method according to any one of claims 1 to 7 by executing the executable instructions.
Citation Information
Patent Citations
Test case generation method and device, server and storage medium
CN109857671A
Keyword extraction method and device, electronic equipment and storage medium
CN111767713A
Test case generation method and device, electronic equipment and computer readable medium
CN113448869A
Intention verbal skill test method and device, equipment and storage medium
CN113791981A
Cited By
Research and development project repetition analysis method and device, electronic equipment and storage medium
CN120706430A
