Search

CN-122029522-A - Processing method and processing device for test cases

CN122029522ACN 122029522 ACN122029522 ACN 122029522ACN-122029522-A

Abstract

The application provides a processing method and a processing device of test cases, wherein the processing method comprises the steps of identifying semantic differences between M modified code files and corresponding M code files before modification to obtain M methods to be tested, wherein the methods to be tested are methods containing the semantic differences, determining N candidate test cases from a plurality of test cases of a test case set, wherein the N candidate test cases are used for testing the M methods to be tested, and the candidate test cases cover at least one method to be tested in the M methods to be tested. The scheme of the embodiment of the application is beneficial to identifying the method which needs to be tested, thereby improving the testing efficiency.

Inventors

  • WANG YAWEI
  • Parville Petrochenko
  • Olga Lukanova
  • Dennis Jenischenko

Assignees

  • 华为云计算技术有限公司

Dates

Publication Date
20260512
Application Date
20240607
Priority Date
20231010

Claims (20)

  1. A method for processing a test case, comprising: Acquiring m input modified code files, wherein m is a positive integer; Identifying semantic differences between the M modified code files and the corresponding M code files before modification to obtain M methods to be tested, wherein the methods to be tested are methods containing the semantic differences, and M is a positive integer; N candidate test cases are determined from a plurality of test cases in a test case set, the N candidate test cases are used for testing the M methods to be tested, the candidate test cases cover at least one method to be tested in the M methods to be tested, and N is a positive integer.
  2. The processing method of claim 1, wherein the determining N candidate test cases from the plurality of test cases in the test case set comprises: Determining the N candidate test cases from the plurality of test cases according to the importance of the plurality of test cases, wherein the importance of the plurality of candidate test cases is respectively based on first weight values of one or more methods to be tested covered by the plurality of test cases and/or second weight values of one or more methods to be tested covered by the plurality of test cases, the first weight values of the methods to be tested indicate the influence range of the methods to be tested in the test case set, and the second weight values of the methods to be tested indicate the influence range of the methods to be tested in the m modified code files.
  3. The processing method according to claim 2, wherein an influence range of the method to be tested in the test case set is based on a number of test cases in which the method to be tested is covered in the test case set, or an influence range of the method to be tested in the m modified code files is based on a number of code files containing the method to be tested in the m modified code files.
  4. A processing method according to claim 2 or 3, characterized in that the importance of the plurality of test cases is based on the maximum value of the first weight value of the one or more methods to be tested covered by the plurality of test cases and/or the maximum value of the second weight value of the one or more methods to be tested covered by the plurality of test cases, respectively.
  5. A process according to any one of claims 2 to 4, further comprising: and outputting the sequencing results of the N candidate test cases, wherein the sequencing results of the N candidate test cases are determined according to the importance degree of the N candidate test cases.
  6. The processing method according to any one of claims 2 to 5, wherein importance of the N candidate test cases is used to indicate priority of execution order of the N candidate test cases.
  7. The processing method according to any one of claims 1 to 6, characterized in that the processing method further comprises: acquiring a test case covered method data file, wherein the test case covered method data file is used for indicating a method for covering the plurality of test cases, the test case covered method data file is generated based on the execution process of the plurality of test cases, and The determining N candidate test cases from the plurality of test cases in the test case set includes: And determining N candidate test cases from a plurality of test cases in the test case set according to the method data file covered by the test cases.
  8. The processing method of claim 7, wherein the test case overlay method data file is updated based on execution of the plurality of test cases.
  9. The processing method according to any one of claims 1 to 8, wherein the identifying semantic differences between the M modified code files and the corresponding M pre-modified code files to obtain M methods to be tested comprises: Analyzing m modified code files to obtain method declaration trees of the m modified code files, wherein the method declaration trees of the m modified code files are respectively used for indicating declarations of methods in the m modified code files and calling relations between the methods in the m modified code files; Acquiring method declaration trees of the m code files before modification, wherein the method declaration trees of the m code files before modification are respectively used for indicating declarations of methods in the m code files before modification and calling relations between the methods in the m code files before modification; And obtaining the M methods to be tested according to the comparison results of the method statement tree of the M modified code files and the method statement tree of the M modified code files.
  10. The processing method according to any one of claims 1 to 9, characterized in that the modified first code file of the M modified code files comprises an addition of a first method and a deletion of a second method compared to the code modification of the first code file before modification, the first method and the second method not belonging to the M methods to be tested in case the structure of the abstract syntax tree AST of the first method and the structure of the AST of the second method are the same.
  11. The processing method according to any one of claims 1 to 10, characterized in that the code modification of the modified second code file of the M modified code files compared to the code modification of the pre-modified second code file comprises a modification of a third method, which does not belong to the M methods to be tested, in case the structure of the AST of the third method before modification and the structure of the AST of the third method after modification are identical.
  12. The processing method according to any one of claims 1 to 11, characterized in that the code modification of the modified third code file of the M modified code files compared to the pre-modified third code file comprises a deletion of dead code in a fourth method or a homofunctional reconstruction of part or all of the code in the fourth method, which does not belong to the M methods to be tested.
  13. A test case processing apparatus, comprising: The first acquisition module is used for acquiring m input modified code files, wherein m is a positive integer; The processing module is used for identifying semantic differences between the M modified code files and the corresponding M code files to obtain M methods to be tested, wherein the methods to be tested are methods containing the semantic differences, and M is a positive integer; The screening module is used for determining N candidate test cases from a plurality of test cases in the test case set, wherein the N candidate test cases are used for testing the M methods to be tested, the candidate test cases cover at least one method to be tested in the M methods to be tested, and N is a positive integer.
  14. The processing apparatus of claim 13, wherein the screening module is specifically configured to: Determining the N candidate test cases from the plurality of test cases according to the importance of the plurality of test cases, wherein the importance of the plurality of candidate test cases is respectively based on first weight values of one or more methods to be tested covered by the plurality of test cases and/or second weight values of one or more methods to be tested covered by the plurality of test cases, the first weight values of the methods to be tested indicate the influence range of the methods to be tested in the test case set, and the second weight values of the methods to be tested indicate the influence range of the methods to be tested in the m modified code files.
  15. The processing device of claim 14, wherein an influence range of the method to be tested in the test case set is based on a number of test cases in the test case set covering the method to be tested, or an influence range of the method to be tested in the m modified code files is based on a number of code files containing the method to be tested in the m modified code files.
  16. The processing apparatus according to claim 14 or 15, wherein the importance of the plurality of test cases is based on a maximum value of a first weight value of the one or more methods under test covered by the plurality of test cases and/or a maximum value of a second weight value of the one or more methods under test covered by the plurality of test cases, respectively.
  17. The processing apparatus according to any one of claims 14 to 16, further comprising an output module for: and outputting the sequencing results of the N candidate test cases, wherein the sequencing results of the N candidate test cases are determined according to the importance degree of the N candidate test cases.
  18. The processing apparatus according to any one of claims 14 to 17, wherein importance of the N candidate test cases is used to indicate priority of execution order of the N candidate test cases.
  19. The processing apparatus according to any one of claims 13 to 18, characterized in that the processing apparatus further comprises: A second obtaining module, configured to obtain a test case covered method data file, where the test case covered method data file is used to indicate a method of covering the multiple test cases, the test case covered method data file is generated based on execution processes of the multiple test cases, and The screening module is specifically used for: And determining N candidate test cases from a plurality of test cases in the test case set according to the method data file covered by the test cases.
  20. The processing device of claim 19, wherein the test case overlay method data file is updated based on execution of the plurality of test cases.

Description

Processing method and processing device for test cases The application claims priority to russian federal patent application No. 2023125824, the russian federal patent application entitled "processing method and processing apparatus for test cases", filed 10/2023, the entire contents of which are incorporated herein by reference. Technical Field The present application relates to the field of testing technologies, and in particular, to a method and an apparatus for processing a test case. Background Unit testing is one of the important means to ensure the code quality of software. Large projects typically have a large number of unit test cases to ensure the quality of the code. After the code has been altered, it may be necessary to test again. However, after the code is changed, the test case corresponding to the changed code may not be accurately located, or the test scope of the influence of the changed code may not be evaluated. To ensure the quality of the code, all test cases may need to be executed, which may affect the test efficiency. Especially for large projects, executing a large number of unaffected test runs can severely increase the time cost, affecting the efficiency of the test. Disclosure of Invention The application provides a processing method and a processing device for test cases, which are beneficial to improving the test efficiency. The first aspect provides a processing method of test cases, which comprises the steps of obtaining input M modified code files, wherein M is a positive integer, identifying semantic differences between the M modified code files and corresponding M code files before modification to obtain M methods to be tested, wherein the methods to be tested are methods containing the semantic differences, M is a positive integer, determining N candidate test cases from a plurality of test cases of a test case set, wherein the N candidate test cases are used for testing the M methods to be tested, and the candidate test cases cover at least one method to be tested in the M methods to be tested, and N is a positive integer. According to the scheme of the embodiment of the application, the test cases are screened based on the context of code modification, namely, semantic differences generated by code modification are identified, the affected test range is determined according to the method of semantic change, namely, the range of the test cases is determined, the execution of the test cases which are not affected is avoided, the method of practically changing the test, namely, the method of testing is ensured, so that the test time is shortened, the test efficiency is improved, and meanwhile, the scheme is also beneficial to avoiding the waste of resources. With reference to the first aspect, in some implementation manners of the first aspect, determining N candidate test cases from among a plurality of test cases in the test case set includes determining N candidate test cases from among the plurality of test cases according to importance levels of the plurality of test cases, where the importance levels of the plurality of candidate test cases are respectively based on first weight values of one or more methods to be tested covered by the plurality of test cases and/or second weight values of one or more methods to be tested covered by the plurality of test cases, where the first weight values of the methods to be tested indicate an influence range of the methods to be tested in the test case set, and the second weight values of the methods to be tested indicate an influence range of the methods to be tested in m modified code files. In the scheme of the embodiment of the application, the importance of the test case is related to the influence range of the method to be tested covered by the test case on the test case level, namely, the importance of the test case is determined based on the coverage degree of the method to be tested covered by the test case, so that the test case with larger influence range can be executed, the method with larger influence on the test case level can be tested, the code quality can be guaranteed, and the reasonable utilization of resources can be guaranteed. In the scheme of the embodiment of the application, the importance of the test case is related to the influence range of the method to be tested covered by the test case on the code modification layer, namely, the importance of the test case is determined based on the number of times the method covered by the test case is submitted to be modified, and the method with larger influence range on the code modification layer is preferentially ensured to be tested, so that the quality of codes is ensured, and the reasonable utilization of resources is ensured. With reference to the first aspect, in some implementations of the first aspect, an influence range of a method to be tested in the test case set is based on a number of test cases covering the method to be tested in the test case s