本申请要求于2023年03月06日提交中国国家知识产权局、申请号为202310207427.8、发明名称为“一种测试用例生成方法及相关系统”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application filed with the State Intellectual Property Office of China on March 6, 2023, with application number 202310207427.8 and invention name “A test case generation method and related system”, the entire contents of which are incorporated by reference in this application.
技术领域Technical Field
本申请涉及测试技术领域,尤其涉及一种测试用例生成方法、系统、计算设备集群、计算机可读存储介质以及计算机程序产品。The present application relates to the field of testing technology, and in particular to a test case generation method, system, computing device cluster, computer-readable storage medium, and computer program product.
背景技术Background Art
随着移动互联网、云计算、人工智能等新一代技术的兴起,软件的规模和复杂性正在不断扩大,软件安全保障的压力也越来越大。在众多安全保障技术中,静态分析技术可以在不运行软件的前提下通过解析软件的代码逻辑以较低的成本发现软件中潜在的安全风险,因而得到了广泛的利用。With the rise of new generation technologies such as mobile Internet, cloud computing, and artificial intelligence, the scale and complexity of software are constantly expanding, and the pressure on software security is also increasing. Among the many security assurance technologies, static analysis technology can discover potential security risks in software at a low cost by analyzing the code logic of the software without running the software, and has therefore been widely used.
静态分析工具包括底层框架和多个检查器。其中,每个检查器可以对应一条检查规则。底层框架负责解析输入代码,并以特定的数据结构,例如是抽象语法树、控制流图存储代码。检查器在此基础上按照检查规则检测输入代码,寻找其中隐藏的错误。Static analysis tools include an underlying framework and multiple checkers. Each checker can correspond to a check rule. The underlying framework is responsible for parsing the input code and storing the code in a specific data structure, such as an abstract syntax tree or a control flow graph. Based on this, the checker detects the input code according to the check rules to find hidden errors.
传统的静态分析工具中,检查器和底层框架的耦合度较高,开发者通常需要掌握底层框架的原理来编写检查器,而底层框架的逻辑往往较为复杂,增加了编写难度。为了提升开发效率、实现检查器和底层框架的解耦,新型的静态分析工具大多采用基于(domainspecific language,DSL)的检查器开发模型。相对于底层框架,DSL的学习成本较低,开发者只需掌握DSL的语法即可进行检查器的开发。In traditional static analysis tools, the coupling between the checker and the underlying framework is high. Developers usually need to master the principles of the underlying framework to write the checker, and the logic of the underlying framework is often complex, which increases the difficulty of writing. In order to improve development efficiency and decouple the checker from the underlying framework, most new static analysis tools use a checker development model based on domain-specific language (DSL). Compared with the underlying framework, the learning cost of DSL is lower, and developers only need to master the syntax of DSL to develop the checker.
基于软件工程规范,检查器开发完成后,通常还需要进行测试。上述基于DSL的方案虽然降低了检查器的开发成本,但繁琐的测试用例开发逐渐成为整个开发流程中的效率瓶颈。Based on software engineering specifications, after the checker is developed, it is usually necessary to test it. Although the above DSL-based solution reduces the development cost of the checker, the cumbersome test case development gradually becomes an efficiency bottleneck in the entire development process.
发明内容Summary of the invention
本申请提供了一种测试用例生成方法,该方法能够提升测试开发效率,并帮助用户自动标注符合检查器检查逻辑的错误代码片段,提升验证效率。本申请还提供了测试用例生成系统、计算设备集群、计算机可读存储介质以及计算机程序产品。The present application provides a test case generation method, which can improve the test development efficiency and help users automatically mark the error code fragments that conform to the checker check logic, thereby improving the verification efficiency. The present application also provides a test case generation system, a computing device cluster, a computer-readable storage medium, and a computer program product.
第一方面,本申请提供一种测试用例生成方法。该方法可以由测试用例生成系统执行。测试用例生成系统用于生成检查器的测试用例,检查器用于对输入代码进行静态分析。测试用例生成系统可以是软件系统,该软件系统可以是独立软件,如独立组件、独立云服务,该软件系统也可以插件等形式集成于其他软件,如集成在程序分析引擎。该软件系统可以部署在计算设备集群中,计算设备集群执行软件系统的程序代码,从而执行测试用例生成方法。测试用例生成系统也可以是具有测试用例生成功能的硬件系统,该硬件系统运行时,执行本申请的测试用例生成方法。In a first aspect, the present application provides a test case generation method. The method can be executed by a test case generation system. The test case generation system is used to generate test cases for a checker, and the checker is used to perform static analysis on the input code. The test case generation system can be a software system, and the software system can be independent software, such as an independent component, an independent cloud service, and the software system can also be integrated into other software in the form of a plug-in, such as an integrated program analysis engine. The software system can be deployed in a computing device cluster, and the computing device cluster executes the program code of the software system, thereby executing the test case generation method. The test case generation system can also be a hardware system with a test case generation function, and when the hardware system is running, it executes the test case generation method of the present application.
测试用例生成系统通过解析检查器的代码,基于代码中定义的错误程序节点以及关联的查询条件,自动生成用于验证检查器正确性的代码片段,提升测试开发效率,并帮助用户自动标注符合检查器检查逻辑的错误代码片段,提升验证效率。进一步地,待测语言为编译语言(也称作编译型语言),即输入代码通过编译语言,如通用编译语言编写,测试用例生成系统还可以通过识别代码中涉及到的外部组件(如external library),自动生成外部组件对应的编译配置文件,从而帮助用户生成完整的用于测试的项目工程(测试用例)。The test case generation system automatically generates code snippets for verifying the correctness of the checker based on the error program nodes defined in the code and the associated query conditions by parsing the checker code, thereby improving the test development efficiency and helping users to automatically mark the error code snippets that conform to the checker's check logic to improve the verification efficiency. Furthermore, the language to be tested is a compiled language (also called a compiled language), that is, the input code is written in a compiled language, such as a general compiled language. The test case generation system can also automatically generate the compilation configuration files corresponding to the external components by identifying the external components involved in the code (such as external library), thereby helping users to generate a complete project project (test case) for testing.
该方法中,测试用例生成系统通过解析检查器的代码,基于代码中定义的错误程序节点以及关联的查询条件,自动生成用于验证检查器正确性的代码片段,提升测试开发效率,并帮助用户自动标注符合检查器检查逻辑的错误代码片段,提升验证效率。In this method, the test case generation system parses the checker code and automatically generates code snippets for verifying the correctness of the checker based on the erroneous program nodes defined in the code and the associated query conditions, thereby improving test development efficiency and helping users automatically mark erroneous code snippets that conform to the checker's inspection logic, thereby improving verification efficiency.
在一些可能的实现方式中,测试用例生成系统可以根据用户配置的测试预言的输出格式,生成测试用例的测试预言。如此可以实现根据用户需求生成满足需求的测试预言。In some possible implementations, the test case generation system may generate a test oracle for the test case according to the output format of the test oracle configured by the user, so as to generate a test oracle that meets the user's needs.
在一些可能的实现方式中,测试用例生成系统可以根据用户配置的所述测试预言的输出格式,生成所述第一代码片段的注释。其中,测试用例的测试预言包括所述第一代码片段的注释。或者,测试用例生成系统可以根据用户配置的所述测试预言的输出格式,生成独立于第一代码片段的预言文件。In some possible implementations, the test case generation system may generate an annotation of the first code snippet according to the output format of the test oracle configured by the user. The test oracle of the test case includes the annotation of the first code snippet. Alternatively, the test case generation system may generate a prophecy file independent of the first code snippet according to the output format of the test oracle configured by the user.
其中,注释形式的测试预言在代码片段附近位置,方便用户进行测试、验证,独立的预言文件方便快速定位测试预言,便于用户对测试预言进行修改、维护。Among them, the test prophecy in the form of comments is located near the code snippet, which is convenient for users to test and verify. The independent prophecy file facilitates the quick location of the test prophecy and the user to modify and maintain the test prophecy.
在一些可能的实现方式中,输入代码可以通过编译语言编写。编译语言(Compiledlanguage)是一种程式语言类型,通过编译器来实现。它不像解释型语言(也称直译语言)一样,由解释器(也称直译器)将程式码一句一句执行,而是以编译器,先将程式码编译为机器码,再加以执行。例如,编译语言可以包括但不限于JAVA、C或C++。相应地,测试用例生成系统还可以根据用户配置的编译工具,生成所述测试用例的编译配置文件。In some possible implementations, the input code can be written in a compiled language. Compiled language is a type of programming language that is implemented by a compiler. Unlike an interpreted language (also called a literal translation language), where the program code is executed sentence by sentence by an interpreter (also called a translator), a compiler is used to compile the program code into machine code before executing it. For example, compiled languages may include but are not limited to JAVA, C, or C++. Accordingly, the test case generation system can also generate a compilation configuration file for the test case according to the compilation tool configured by the user.
该方法能够实现自动生成编译配置脚本等编译配置文件,简化了测试过程,提升了测试效率。This method can automatically generate compilation configuration files such as compilation configuration scripts, simplify the testing process, and improve testing efficiency.
在一些可能的实现方式中,测试用例生成系统在根据用户配置的编译工具,生成测试用例的编译配置文件时,可以根据用户配置的编译工具,生成与编译工具对应的编译配置文件的模板。当检查器的代码中包括外部组件的引用信息,测试用例生成系统获取所述外部组件的编译信息,并将所述外部组件的编译信息添加至所述模板中,获得所述编译配置文件。In some possible implementations, when the test case generation system generates a compilation configuration file of the test case according to the compilation tool configured by the user, it can generate a template of the compilation configuration file corresponding to the compilation tool according to the compilation tool configured by the user. When the code of the checker includes reference information of an external component, the test case generation system obtains the compilation information of the external component, and adds the compilation information of the external component to the template to obtain the compilation configuration file.
该方法通过识别检查器的代码中涉及到的外部组件,自动生成外部组件对应的编译配置文件,帮助用户生成完整的用于测试的项目工程,提高测试效率。This method identifies the external components involved in the checker code and automatically generates compilation configuration files corresponding to the external components, helping users generate a complete project for testing and improving testing efficiency.
在一些可能的实现方式中,当检查器的代码中不包括外部组件的引用信息,例如是与外部组件匹配不成功,测试用例生成系统可以将与编译工具对应的编译配置文件的模板确定为编译配置文件。该方法支持识别检查器的代码中涉及到的外部组件,在未识别到外部组件的情况下,直接根据与编译工具对应的编译配置文件的模板确定编译配置文件,提高测试效率。In some possible implementations, when the checker code does not include reference information of the external component, for example, the match with the external component is unsuccessful, the test case generation system can determine the template of the compilation configuration file corresponding to the compilation tool as the compilation configuration file. This method supports identifying the external components involved in the checker code, and when the external components are not identified, directly determining the compilation configuration file according to the template of the compilation configuration file corresponding to the compilation tool, thereby improving the test efficiency.
在一些可能的实现方式中,所述错误程序节点包括方法声明节点、变量使用节点、赋值表达式节点中的一种或多种。具体地,错误程序节点为能够引起检查器告警的程序节点。检查器用于对输入代码(例如待测程序的代码)进行静态分析,在静态分析时,检查器可以识别出待测程序的代码中的程序节点,基于程序节点进行静态分析。考虑到不同检查器的检查规则或检查逻辑不同,检查器的代码中可以定义与检查规则或检查逻辑对应的错误程序节点,例如是上述方法声明节点(或者函数声明节点)、变量使用节点、赋值表达式节点中的一种或多种。In some possible implementations, the error program node includes one or more of a method declaration node, a variable use node, and an assignment expression node. Specifically, an error program node is a program node that can cause an alarm in the checker. The checker is used to perform static analysis on the input code (e.g., the code of the program to be tested). During static analysis, the checker can identify the program nodes in the code of the program to be tested and perform static analysis based on the program nodes. Taking into account that the inspection rules or inspection logic of different checkers are different, the error program nodes corresponding to the inspection rules or inspection logic can be defined in the code of the checker, such as one or more of the above-mentioned method declaration nodes (or function declaration nodes), variable use nodes, and assignment expression nodes.
该方法通过识别方法声明节点、变量使用节点、赋值表达式节点可以为构造正例代码片段、反例代码片段提供参考,从而实现自动生成测试用例。The method can provide references for constructing positive example code snippets and counterexample code snippets by identifying method declaration nodes, variable use nodes, and assignment expression nodes, thereby realizing automatic generation of test cases.
在一些可能的实现方式中,错误程序节点关联的查询条件是与错误程序节点相关的、用于判别是否触发告警的条件。该查询条件可以通过条件表达式进行表示,例如查询条件可以为函数名为xxx,参数数量不大于n。In some possible implementations, the query condition associated with the error program node is a condition related to the error program node and used to determine whether to trigger an alarm. The query condition can be represented by a conditional expression, for example, the query condition can be that the function name is xxx and the number of parameters is not greater than n.
该方法通过识别错误程序节点关联的查询条件,可以为构造正例代码片段、反例代码片段提供参考,从而实现自动生成测试用例。By identifying the query conditions associated with the erroneous program nodes, this method can provide a reference for constructing positive example code snippets and negative example code snippets, thereby realizing automatic generation of test cases.
在一些可能的实现方式中,所述检查器的代码为领域特定语言(domain specificlanguage,DSL)代码。其中,DSL是专门针对特定应用领域的计算机语言,包括但不限于HTML或Maven。In some possible implementations, the code of the checker is a domain specific language (DSL) code, wherein DSL is a computer language specifically for a specific application domain, including but not limited to HTML or Maven.
由于DSL的学习成本较低,开发者只需掌握DSL的语法即可进行检查器的开发,降低了检查器的开发成本。Since DSL has a low learning cost, developers only need to master the syntax of DSL to develop the checker, which reduces the development cost of the checker.
第二方面,本申请提供一种测试用例生成系统。所述测试用例生成系统用于生成检查器的测试用例,所述检查器用于对输入代码进行静态分析,所述系统包括:In a second aspect, the present application provides a test case generation system. The test case generation system is used to generate test cases for a checker, the checker is used to perform static analysis on input code, and the system includes:
解析子系统,用于获取所述检查器的代码,对所述检查器的代码进行解析,获得所述检查器的代码中定义的错误程序节点以及所述错误程序节点关联的查询条件,所述错误程序节点为能够引起所述检查器告警的程序节点;A parsing subsystem, used to obtain the code of the checker, parse the code of the checker, obtain an error program node defined in the code of the checker and a query condition associated with the error program node, wherein the error program node is a program node that can cause the checker to issue an alarm;
生成子系统,用于根据所述错误程序节点以及所述查询条件,生成所述测试用例的源文件,所述测试用例的源文件包括符合所述查询条件的第一代码片段以及不符合所述查询条件的第二代码片段;A generating subsystem, configured to generate a source file of the test case according to the error program node and the query condition, wherein the source file of the test case includes a first code fragment that meets the query condition and a second code fragment that does not meet the query condition;
所述生成子系统,还用于生成所述测试用例的测试预言,所述测试预言指示所述第一代码片段为引起所述检查器告警的代码片段。The generation subsystem is further configured to generate a test oracle for the test case, wherein the test oracle indicates that the first code snippet is a code snippet that causes the checker to raise an alarm.
在一些可能的实现方式中,所述生成子系统具体用于:In some possible implementations, the generating subsystem is specifically used for:
根据用户配置的所述测试预言的输出格式,生成所述测试用例的测试预言。Generate a test oracle for the test case according to an output format of the test oracle configured by a user.
在一些可能的实现方式中,所述生成子系统具体用于:In some possible implementations, the generating subsystem is specifically used for:
根据用户配置的所述测试预言的输出格式,生成所述第一代码片段的注释,所述测试用例的测试预言包括所述第一代码片段的注释;或者,Generate a comment for the first code snippet according to an output format of the test oracle configured by a user, wherein the test oracle of the test case includes the comment for the first code snippet; or
根据用户配置的所述测试预言的输出格式,生成独立于所述第一代码片段的预言文件。A prediction file independent of the first code snippet is generated according to an output format of the test prediction configured by a user.
在一些可能的实现方式中,所述输入代码通过编译语言编写,所述生成子系统还用于:In some possible implementations, the input code is written in a compiled language, and the generation subsystem is further used for:
根据用户配置的编译工具,生成所述测试用例的编译配置文件。Generate a compilation configuration file for the test case according to the compilation tool configured by the user.
在一些可能的实现方式中,所述生成子系统具体用于:In some possible implementations, the generating subsystem is specifically used for:
根据用户配置的编译工具,生成与所述编译工具对应的编译配置文件的模板;Generate a template of a compilation configuration file corresponding to the compilation tool according to the compilation tool configured by the user;
当所述检查器的代码中包括外部组件的引用信息,获取所述外部组件的编译信息,并将所述外部组件的编译信息添加至所述模板中,获得所述编译配置文件。When the code of the checker includes reference information of an external component, the compilation information of the external component is obtained, and the compilation information of the external component is added to the template to obtain the compilation configuration file.
在一些可能的实现方式中,所述错误程序节点包括方法声明节点、变量使用节点、赋值表达式节点中的一种或多种。In some possible implementations, the erroneous program node includes one or more of a method declaration node, a variable use node, and an assignment expression node.
在一些可能的实现方式中,所述检查器的代码为领域特定语言DSL代码。In some possible implementations, the code of the checker is a domain specific language (DSL) code.
第三方面,本申请提供一种计算设备集群。所述计算设备集群包括至少一台计算设备,所述至少一台计算设备包括至少一个处理器和至少一个存储器。所述至少一个处理器、所述至少一个存储器进行相互的通信。所述至少一个处理器用于执行所述至少一个存储器中存储的指令,以使得计算设备或计算设备集群执行如第一方面或第一方面的任一种实现方式所述的测试用例生成方法。In a third aspect, the present application provides a computing device cluster. The computing device cluster includes at least one computing device, and the at least one computing device includes at least one processor and at least one memory. The at least one processor and the at least one memory communicate with each other. The at least one processor is used to execute instructions stored in the at least one memory, so that the computing device or the computing device cluster executes the test case generation method described in the first aspect or any implementation of the first aspect.
第四方面,本申请提供一种计算机可读存储介质,所述计算机可读存储介质中存储有指令,所述指令指示计算设备或计算设备集群执行上述第一方面或第一方面的任一种实现方式所述的测试用例生成方法。In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores instructions, wherein the instructions instruct a computing device or a computing device cluster to execute the test case generation method described in the first aspect or any one of the implementations of the first aspect.
第五方面,本申请提供了一种包含指令的计算机程序产品,当其在计算设备或计算设备集群上运行时,使得计算设备或计算设备集群执行上述第一方面或第一方面的任一种实现方式所述的测试用例生成方法。In a fifth aspect, the present application provides a computer program product comprising instructions, which, when executed on a computing device or a computing device cluster, enables the computing device or the computing device cluster to execute the test case generation method described in the first aspect or any one of the implementations of the first aspect.
本申请在上述各方面提供的实现方式的基础上,还可以进行进一步组合以提供更多实现方式。Based on the implementations provided in the above aspects, the present application can also be further combined to provide more implementations.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
为了更清楚地说明本申请实施例的技术方法,下面将对实施例中所需使用的附图作以简单地介绍。In order to more clearly illustrate the technical method of the embodiments of the present application, the drawings required for use in the embodiments are briefly introduced below.
图1为本申请实施例提供的一种测试用例生成系统的架构示意图;FIG1 is a schematic diagram of the architecture of a test case generation system provided in an embodiment of the present application;
图2为本申请实施例提供的一种测试用例生成方法的流程图;FIG2 is a flow chart of a test case generation method provided in an embodiment of the present application;
图3为本申请实施例提供的一种测试用例生成方法的应用场景示意图;FIG3 is a schematic diagram of an application scenario of a test case generation method provided in an embodiment of the present application;
图4为本申请实施例提供的一种源文件、测试预言的示意图;FIG4 is a schematic diagram of a source file and a test prediction provided by an embodiment of the present application;
图5为本申请实施例提供的一种编译配置脚本的示意图;FIG5 is a schematic diagram of a compilation configuration script provided in an embodiment of the present application;
图6为本申请实施例提供的一种计算设备的结构示意图;FIG6 is a schematic diagram of the structure of a computing device provided in an embodiment of the present application;
图7为本申请实施例提供的一种计算设备集群的结构示意图;FIG7 is a schematic diagram of the structure of a computing device cluster provided in an embodiment of the present application;
图8为本申请实施例提供的另一种计算设备集群的结构示意图;FIG8 is a schematic diagram of the structure of another computing device cluster provided in an embodiment of the present application;
图9为本申请实施例提供的又一种计算机集群的结构示意图。FIG. 9 is a schematic diagram of the structure of another computer cluster provided in an embodiment of the present application.
具体实施方式DETAILED DESCRIPTION
本申请实施例中的术语“第一”、“第二”仅用于描述目的,而不能理解为指示或暗示相对重要性或者隐含指明所指示的技术特征的数量。由此,限定有“第一”、“第二”的特征可以明示或者隐含地包括一个或者更多个该特征。The terms "first" and "second" in the embodiments of the present application are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features.
首先对本申请实施例中所涉及到的一些技术术语进行介绍。First, some technical terms involved in the embodiments of the present application are introduced.
静态分析,也称静态代码分析,作为一种软件验证活动,它不要求执行代码,而是通过分析源代码实现质量、可靠性和安全性目的。使用静态分析,可以实现以较低的成本识别可能危害应用安全的缺陷和安全漏洞,因而在软件测试领域得到广泛应用。Static analysis, also known as static code analysis, is a software verification activity that does not require code execution, but achieves quality, reliability, and security goals by analyzing source code. Static analysis can be used to identify defects and security vulnerabilities that may endanger application security at a low cost, so it is widely used in the field of software testing.
静态分析工具包括底层框架和多个检查器。底层框架负责解析输入代码(例如是待测试软件的源代码),以特定的数据结构,如抽象语法树、控制流图存储上述输入代码,检查器为静态分析工具中基于某种检查规则检测输入代码中潜在问题的功能模块。每个检查器可以对应一条检查规则。Static analysis tools include an underlying framework and multiple checkers. The underlying framework is responsible for parsing the input code (for example, the source code of the software to be tested) and storing the input code in a specific data structure, such as an abstract syntax tree or a control flow graph. The checker is a functional module in the static analysis tool that detects potential problems in the input code based on certain check rules. Each checker can correspond to one check rule.
检查器可以采用领域特定语言(domain specific language,DSL)开发。领域特定语言可以是专门针对特定应用领域的计算机语言。在一些示例中,领域特定语言可以包括用于显示网页的超文本标记语言(Hyper Text Markup Language,HTML),在另一些示例中,领域特定语言可以包括用于编译配置的Maven。The checker may be developed using a domain specific language (DSL). A domain specific language may be a computer language specifically targeted at a specific application domain. In some examples, the domain specific language may include Hyper Text Markup Language (HTML) for displaying web pages, and in other examples, the domain specific language may include Maven for compiling configurations.
按照软件工程规范,开发工作结束后需要对项目进行测试,检查器亦不例外。显然,检查器的测试输入可以是一个包括源文件(可以使用待测语言编写,包括错误代码片段以便于检查器检测)的工程项目。此外,错误代码片段的信息可以进行特殊标注以便测试程序进行结果验证。According to software engineering specifications, the project needs to be tested after the development work is completed, and the checker is no exception. Obviously, the test input of the checker can be an engineering project including source files (which can be written in the language to be tested, including error code snippets for the checker to detect). In addition, the information of the error code snippet can be specially marked to facilitate the test program to verify the results.
目前,开发者通常是采用基于DSL的程序分析引擎提供的领域特定语言编写检查器。在测试检查器时,开发者需按照可以按照程序分析引擎提供的测试框架设置测试包、测试文件,再调用程序分析引擎运行测试。Currently, developers usually use a domain-specific language provided by a program analysis engine based on a DSL to write a checker. When testing the checker, the developer needs to set up a test package and test files according to the test framework provided by the program analysis engine, and then call the program analysis engine to run the test.
虽然程序分析引擎提供了测试框架,但开发者需要自行准备测试用例的源文件和测试预言(test oracle),整个测试过程非常繁琐,开发效率低。换言之,基于DSL的程序分析引擎降低了检查器的开发成本,但测试成本并未显著降低,繁琐的测试用例开发逐渐成为整个检查器开发流程中的效率瓶颈,难以满足业务需求。Although the program analysis engine provides a test framework, developers need to prepare the source files and test oracles of the test cases by themselves. The entire test process is very cumbersome and the development efficiency is low. In other words, the DSL-based program analysis engine reduces the development cost of the checker, but the testing cost is not significantly reduced. The cumbersome test case development gradually becomes an efficiency bottleneck in the entire checker development process, making it difficult to meet business needs.
有鉴于此,本申请提供一种测试用例生成方法。该方法可以由测试用例生成系统执行。测试用例生成系统用于生成检查器的测试用例,检查器用于对输入代码进行静态分析。测试用例生成系统可以是软件系统,该软件系统可以是独立软件,如独立组件、独立云服务,该软件系统也可以插件等形式集成于其他软件,如集成在程序分析引擎。该软件系统可以部署在计算设备集群中,计算设备集群执行软件系统的程序代码,从而执行测试用例生成方法。测试用例生成系统也可以是具有测试用例生成功能的硬件系统,该硬件系统运行时,执行本申请的测试用例生成方法。In view of this, the present application provides a test case generation method. The method can be executed by a test case generation system. The test case generation system is used to generate test cases for a checker, and the checker is used to perform static analysis on the input code. The test case generation system can be a software system, and the software system can be an independent software, such as an independent component, an independent cloud service, and the software system can also be integrated into other software in the form of a plug-in, such as an integration in a program analysis engine. The software system can be deployed in a computing device cluster, and the computing device cluster executes the program code of the software system, thereby executing the test case generation method. The test case generation system can also be a hardware system with a test case generation function, and when the hardware system is running, it executes the test case generation method of the present application.
具体地,测试用例生成系统可以获取检查器的代码,对检查器的代码进行解析,获得检查器的代码中定义的错误程序节点以及错误程序节点关联的查询条件。错误程序节点为能够引起检查器告警的程序节点。测试用例生成系统可以根据错误程序节点以及查询条件,生成测试用例的源文件,测试用例的源文件包括符合查询条件的第一代码片段(通常是错误代码片段,也称作反例代码片段)以及不符合查询条件的第二代码片段(通常是正确代码片段,也称作正例代码片段)。测试用例系统还生成测试用例的测试预言,该测试预言指示上述第一代码片段为引起检查器告警的代码片段。Specifically, the test case generation system can obtain the code of the checker, parse the code of the checker, and obtain the error program node defined in the code of the checker and the query condition associated with the error program node. The error program node is a program node that can cause the checker to alarm. The test case generation system can generate the source file of the test case based on the error program node and the query condition. The source file of the test case includes a first code fragment that meets the query condition (usually an error code fragment, also called a counterexample code fragment) and a second code fragment that does not meet the query condition (usually a correct code fragment, also called a positive example code fragment). The test case system also generates a test prediction for the test case, which indicates that the above-mentioned first code fragment is a code fragment that causes the checker to alarm.
该方法中,测试用例生成系统通过解析检查器的代码,基于代码中定义的错误程序节点以及关联的查询条件,自动生成用于验证检查器正确性的代码片段,提升测试开发效率,并帮助用户自动标注符合检查器检查逻辑的错误代码片段,提升验证效率。进一步地,待测语言为编译语言(也称作编译型语言),即输入代码通过编译语言,如通用编译语言编写,测试用例生成系统还可以通过识别代码中涉及到的外部组件(如externallibrary),自动生成外部组件对应的编译配置文件,从而帮助用户生成完整的用于测试的项目工程(测试用例)。In this method, the test case generation system automatically generates code snippets for verifying the correctness of the checker based on the error program nodes defined in the code and the associated query conditions by parsing the checker code, thereby improving the test development efficiency and helping users to automatically mark the error code snippets that conform to the checker's check logic, thereby improving the verification efficiency. Furthermore, the language to be tested is a compiled language (also called a compiled language), that is, the input code is written in a compiled language, such as a general compiled language. The test case generation system can also automatically generate a compilation configuration file corresponding to the external component by identifying the external component (such as an external library) involved in the code, thereby helping users to generate a complete project project (test case) for testing.
为了使得本申请的技术方案更加清楚、易于理解,下面结合附图对本申请的系统架构进行介绍。In order to make the technical solution of the present application clearer and easier to understand, the system architecture of the present application is introduced below with reference to the accompanying drawings.
参见图1所示的测试用例生成系统的架构示意图,测试用例生成系统10包括解析子系统100和生成子系统200。其中,解析子系统100用于获取检查器的代码(如DSL代码),对检查器的代码进行解析,获得检查器的代码中定义的错误程序节点以及所述错误程序节点关联的查询条件。生成子系统200用于根据错误程序节点以及查询条件,生成所述测试用例的源文件。测试用例的源文件包括符合查询条件的第一代码片段以及不符合查询条件的第二代码片段,以及生成测试用例的测试预言,测试预言指示第一代码片段为引起所述检查器告警的代码片段。Referring to the schematic diagram of the test case generation system shown in FIG1 , the test case generation system 10 includes a parsing subsystem 100 and a generating subsystem 200. The parsing subsystem 100 is used to obtain the code of the checker (such as DSL code), parse the code of the checker, and obtain the error program node defined in the code of the checker and the query condition associated with the error program node. The generating subsystem 200 is used to generate the source file of the test case according to the error program node and the query condition. The source file of the test case includes a first code fragment that meets the query condition and a second code fragment that does not meet the query condition, as well as a test prediction for generating the test case, and the test prediction indicates that the first code fragment is the code fragment that causes the checker to alarm.
具体地,解析子系统100包括节点类型识别模块102和查询条件识别模块104,节点类型识别模块102用于对检查器的代码进行识别,获得检查器的代码中定义的错误程序节点,查询条件识别模块104用于对检查器的代码进行识别,获得错误程序节点关联的查询条件。生成子系统200包括正反例代码片段生成模块202、源文件生成模块204、测试预言生成模块206,正反例代码片段生成模块202用于根据错误程序节点和关联条件生成正例代码片段和反例代码片段,正例代码片段为符合查询条件的第一代码片段,反例代码片段为不符合所述查询条件的第二代码片段,源文件生成模块204用于根据正例代码片段和反例代码片段,生成测试用例的源文件,测试预言生成模块206用于生成测试用例的测试预言,测试预言指示正例代码片段为引起检查器告警的代码片段。Specifically, the parsing subsystem 100 includes a node type identification module 102 and a query condition identification module 104. The node type identification module 102 is used to identify the code of the checker and obtain the error program node defined in the code of the checker. The query condition identification module 104 is used to identify the code of the checker and obtain the query condition associated with the error program node. The generation subsystem 200 includes a positive and negative example code fragment generation module 202, a source file generation module 204, and a test prediction generation module 206. The positive and negative example code fragment generation module 202 is used to generate a positive example code fragment and a negative example code fragment according to the error program node and the associated condition. The positive example code fragment is a first code fragment that meets the query condition, and the negative example code fragment is a second code fragment that does not meet the query condition. The source file generation module 204 is used to generate a source file of a test case according to the positive example code fragment and the negative example code fragment. The test prediction generation module 206 is used to generate a test prediction of the test case, and the test prediction indicates that the positive example code fragment is a code fragment that causes the checker to alarm.
在一些可能的实现方式中,生成子系统200还可以包括编译配置生成模块208。编译配置生成模块208用于生成测试用例的编译配置文件。其中,编译配置文件可以是编译配置脚本。具体地,编译配置生成模块208可以在待测预言为编译语言,如检查器的输入代码为编译语言编写的代码时,生成测试用例的编译配置文件。其中,编译配置生成模块208可以根据用户配置的编译工具,生成与编译工具对应的编译配置文件的模板,基于该模板获得编译配置文件。In some possible implementations, the generation subsystem 200 may further include a compilation configuration generation module 208. The compilation configuration generation module 208 is used to generate a compilation configuration file for the test case. The compilation configuration file may be a compilation configuration script. Specifically, the compilation configuration generation module 208 may generate a compilation configuration file for the test case when the predicted language to be tested is a compilation language, such as when the input code of the checker is a code written in a compilation language. The compilation configuration generation module 208 may generate a template of a compilation configuration file corresponding to the compilation tool according to the compilation tool configured by the user, and obtain the compilation configuration file based on the template.
进一步地,解析子系统100还包括外部组件识别模块106,外部组件识别模块106用于对检查器的代码进行识别,获得检查器的代码中外部组件的引用信息(如果存在)。其中,外部组件的引用信息可以包括包名、类名、方法名中的一种或多种。生成子系统200还包括外部组件匹配模块210,外部组件识别模块210用于根据外部组件的引用信息,在仓库(例如是远程仓库)中匹配外部组件,获得外部组件的编译信息。相应地,编译配置生成模块208可以将外部组件的编译信息添加至编译配置文件的模板,获得编译配置文件。Furthermore, the parsing subsystem 100 also includes an external component identification module 106, which is used to identify the code of the checker and obtain the reference information of the external component in the code of the checker (if it exists). Among them, the reference information of the external component may include one or more of the package name, class name, and method name. The generation subsystem 200 also includes an external component matching module 210, which is used to match the external component in a warehouse (for example, a remote warehouse) according to the reference information of the external component to obtain the compilation information of the external component. Accordingly, the compilation configuration generation module 208 can add the compilation information of the external component to the template of the compilation configuration file to obtain the compilation configuration file.
本申请实施例的测试用例生成系统10可以从逻辑上分为三层,自底向上包括解析层、应用层和用户层。解析层包括上述解析子系统100,是测试用例生成的基础,解析层通过对检查器的代码进行拆解、分析,获得生成测试用例的各种必要元素。应用层和用户层包括上述生成子系统200,应用层利用解析层解析的必要元素直接生成组成测试用例的各个部件,这些部件通过用户层以完整测试用例的形式直接展示给用户。The test case generation system 10 of the embodiment of the present application can be logically divided into three layers, including a parsing layer, an application layer, and a user layer from bottom to top. The parsing layer includes the above-mentioned parsing subsystem 100, which is the basis for test case generation. The parsing layer obtains various necessary elements for generating test cases by disassembling and analyzing the code of the checker. The application layer and the user layer include the above-mentioned generation subsystem 200. The application layer directly generates the various components that make up the test case using the necessary elements parsed by the parsing layer, and these components are directly displayed to the user in the form of a complete test case through the user layer.
下面结合实施例,对本申请提供的测试用例生成方法进行详细介绍。The test case generation method provided by the present application is described in detail below in conjunction with the embodiments.
参见图2所示的测试用例生成方法的流程图,该方法包括如下步骤:Referring to the flowchart of the test case generation method shown in FIG2 , the method comprises the following steps:
S201:测试用例生成系统10获取检查器的代码。S201: The test case generation system 10 obtains the code of the checker.
检查器可以是基于某种检查规则检测输入代码中潜在问题的功能模块。根据开发方式不同,检查器可以分为不同类型。例如,检查器可以是基于领域特定语言DSL开发的检查器。换言之,检查器的代码可以是DSL代码。其中,DSL是专门针对特定应用领域的计算机语言,包括但不限于HTML或Maven。A checker can be a functional module that detects potential problems in input code based on certain checking rules. Checkers can be divided into different types according to different development methods. For example, a checker can be a checker developed based on a domain-specific language DSL. In other words, the code of the checker can be DSL code. Among them, DSL is a computer language specifically for a specific application field, including but not limited to HTML or Maven.
S203:测试用例生成系统10对检查器的代码进行解析,获得检查器的代码中定义的错误程序节点以及错误程序节点关联的查询条件。S203: The test case generation system 10 parses the code of the checker to obtain the error program nodes defined in the code of the checker and the query conditions associated with the error program nodes.
错误程序节点为能够引起检查器告警的程序节点。检查器用于对输入代码(待测程序的代码)进行静态分析,在静态分析时,检查器可以识别出待测程序的代码中的程序节点,基于程序节点进行静态分析。考虑到不同检查器的检查规则或检查逻辑不同,检查器的代码中可以定义与检查规则或检查逻辑对应的错误程序节点。在一些示例中,程序错误节点可以包括方法声明节点(例如是函数声明节点)、变量使用节点、赋值表达式节点中的一种或多种。An error program node is a program node that can cause an alarm in the checker. The checker is used to perform static analysis on the input code (the code of the program to be tested). During static analysis, the checker can identify the program nodes in the code of the program to be tested and perform static analysis based on the program nodes. Taking into account the different inspection rules or inspection logic of different checkers, error program nodes corresponding to the inspection rules or inspection logic can be defined in the code of the checker. In some examples, the program error node may include one or more of a method declaration node (for example, a function declaration node), a variable use node, and an assignment expression node.
具体地,测试用例生成系统10可以通过对检查器的代码进行语义识别,获得检查器的代码中定义的错误程序节点。在另一些示例中,测试用例生成系统10可以通过识别检查器的代码中的关键字,获得检查器的代码中定义的错误程序节点。Specifically, the test case generation system 10 can obtain the error program node defined in the checker code by semantically identifying the checker code. In other examples, the test case generation system 10 can obtain the error program node defined in the checker code by identifying keywords in the checker code.
错误程序节点关联的查询条件具体是与错误程序节点相关的、用于判别是否触发告警的条件。该查询条件可以通过条件表达式进行表示,例如查询条件可以为函数名为xxx,参数数量不大于n。The query condition associated with the error program node is specifically a condition related to the error program node and used to determine whether to trigger an alarm. The query condition can be represented by a conditional expression, for example, the query condition can be that the function name is xxx and the number of parameters is not greater than n.
S205:测试用例生成系统10根据错误程序节点以及查询条件,生成测试用例的源文件。S205: The test case generation system 10 generates a source file of the test case according to the error program node and the query condition.
测试用例的源文件包括符合查询条件的第一代码片段以及不符合查询条件的第二代码片段。其中,第一代码片段为正例代码片段,第二代码片段为反例代码片段。测试用例生成系统10可以根据错误程序节点以及查询条件生成初始化的正例代码片段和初始化的反例代码片段,然后基于配置的正反例数量、补全正反例代码片段的关键词库,从关键词库中选择关键词对初始化的正列代码片段、初始化的反例代码片段分别进行补全,生成相应数量的正列代码片段和反例代码片段。其中,正反例数量、补全正反例代码片段的关键词库可以预先设置,也可以在使用过程中设置,本实施例对此不作限制。The source file of the test case includes a first code snippet that meets the query condition and a second code snippet that does not meet the query condition. Among them, the first code snippet is a positive example code snippet, and the second code snippet is a negative example code snippet. The test case generation system 10 can generate an initialized positive example code snippet and an initialized negative example code snippet according to the error program node and the query condition, and then based on the configured number of positive and negative examples and the keyword library for completing the positive and negative example code snippets, select keywords from the keyword library to complete the initialized positive column code snippet and the initialized negative example code snippet respectively, and generate a corresponding number of positive column code snippets and negative example code snippets. Among them, the number of positive and negative examples and the keyword library for completing the positive and negative example code snippets can be pre-set or set during use, and this embodiment does not limit this.
在生成正例代码片段和反例代码片段后,测试用例生成系统10可以将正例代码片段和反例代码片段拼装,以生成测试用例的源文件。进一步地,测试用例生成系统10还可以补充缺失信息,如调用导入语句,从而获得完整的源文件。其中,不同语言对应的调用导入语句可以不同,以Java为例,调用导入语句可以为import语句。After generating the positive example code snippet and the counterexample code snippet, the test case generation system 10 can assemble the positive example code snippet and the counterexample code snippet to generate a source file of the test case. Further, the test case generation system 10 can also supplement the missing information, such as calling import statements, to obtain a complete source file. Among them, the calling import statements corresponding to different languages can be different. Taking Java as an example, the calling import statement can be an import statement.
S207:测试用例生成系统10生成测试用例的测试预言。S207: The test case generation system 10 generates a test oracle for the test case.
在程序分析场景中,测试预言指的是决定被测代码片段是否为问题代码片段的判断机制。在本实施例中,正例代码片段为能够引起检查器告警的代码片段,基于此,测试用例生成系统10可以根据正例代码片段,生成测试预言。测试预言指示正例代码片段(如上述第一代码片段)为引起检查器告警的代码片段。In the program analysis scenario, test prediction refers to a judgment mechanism that determines whether the tested code snippet is a problematic code snippet. In this embodiment, the positive code snippet is a code snippet that can cause the checker to warn. Based on this, the test case generation system 10 can generate a test prediction based on the positive code snippet. The test prediction indicates that the positive code snippet (such as the first code snippet mentioned above) is a code snippet that causes the checker to warn.
具体地,测试用例生成系统10可以根据用户配置的测试预言的输出格式,生成测试用例的测试预言。在一些示例中,用户配置的测试预言的输出格式可以为注释,测试用例生成系统10可以根据用户配置的所述测试预言的输出格式,生成第一代码片段的注释,该注释指示第一代码片段为引起检查器告警的代码片段。相应地,测试用例的测试预言包括上述第一代码片段的注释。在另一些示例中,用户配置的测试语音的输出格式可以为独立的预言文件,进一步地,用户还可以配置预言文件的格式或路径,例如用户可以配置语言文件的格式为可扩展标记语言(Extensible Markup Language,XML),测试用例生成系统10根据用户配置的测试预言的输出格式,生成独立于第一代码片段的预言文件。需要说明的是,测试用例生成系统10也可以设置预言文件的默认格式或默认路径,用户未配置预言文件的格式或路径时,测试用例生成系统10可以根据默认格式或默认路径,生成预言文件。通过测试预言,开发者可以获知告警的基本信息,例如:正例代码片段的位置信息、告警描述。Specifically, the test case generation system 10 can generate a test prophecy of the test case according to the output format of the test prophecy configured by the user. In some examples, the output format of the test prophecy configured by the user can be a comment, and the test case generation system 10 can generate a comment of the first code snippet according to the output format of the test prophecy configured by the user, and the comment indicates that the first code snippet is a code snippet that causes the checker alarm. Correspondingly, the test prophecy of the test case includes the comment of the above-mentioned first code snippet. In other examples, the output format of the test voice configured by the user can be an independent prophecy file. Further, the user can also configure the format or path of the prophecy file. For example, the user can configure the format of the language file to be Extensible Markup Language (XML), and the test case generation system 10 generates a prophecy file independent of the first code snippet according to the output format of the test prophecy configured by the user. It should be noted that the test case generation system 10 can also set a default format or default path for the prophecy file. When the user does not configure the format or path of the prophecy file, the test case generation system 10 can generate a prophecy file according to the default format or default path. Through the test prophecy, the developer can obtain the basic information of the alarm, such as: the location information of the positive example code snippet and the alarm description.
S209:测试用例生成系统10根据用户配置的编译工具,生成测试用例的编译配置文件。S209: The test case generation system 10 generates a compilation configuration file of the test case according to the compilation tool configured by the user.
输入代码可以是采用编译语言编写,也可以采用解释型语言编写。当输入代码采用编译语言编写,例如是通过Java编写,测试用例生成系统10可以根据用户的编译工具,生成测试用例的编译配置文件。The input code may be written in a compiled language or an interpreted language. When the input code is written in a compiled language, such as Java, the test case generation system 10 may generate a compilation configuration file of the test case according to the user's compilation tool.
编译配置文件可以是一种可执行脚本文件,例如为编译配置脚本。编译配置文件用于帮助开发要在多种不同计算机上运行的程序。它将用户计算机上的库与程序所需的库进行匹配,然后再从源代码进行编译。通常情况下,编译配置脚本可以命名为configure。A compile configuration file can be an executable script file, such as a compile configuration script. A compile configuration file is used to help develop programs to run on a variety of different computers. It matches the libraries on the user's computer with the libraries required by the program before compiling from the source code. Typically, the compile configuration script can be named configure.
具体地,测试用例生成系统10可以根据用户配置的编译工具,生成与编译工具对应的编译配置文件(如编译配置脚本)的模板。当检查器的代码(如DSL代码)中包括外部组件的引用信息,测试用例生成系统10可以获取外部组件的编译信息,例如是根据外租组件的引用信息在远程仓库中搜索外部组件,获得外部组件的编译信息,并将外部组件的编译信息添加至模板中,获得编译配置脚本。当检查器的代码中不包括外部组件的引用信息,测试用例生成系统10可以将该模板确定为编译配置文件。Specifically, the test case generation system 10 can generate a template of a compilation configuration file (such as a compilation configuration script) corresponding to the compilation tool according to the compilation tool configured by the user. When the code of the checker (such as DSL code) includes reference information of an external component, the test case generation system 10 can obtain the compilation information of the external component, for example, searching for the external component in a remote warehouse according to the reference information of the outsourced component, obtaining the compilation information of the external component, and adding the compilation information of the external component to the template to obtain the compilation configuration script. When the code of the checker does not include reference information of the external component, the test case generation system 10 can determine the template as a compilation configuration file.
需要说明的是,正反例数量、补全正反例代码片段的关键词库、测试预言的格式以及用于进行外部组件匹配的远程仓库等配置项可以预先配置,以便于一键生成测试用例,也可以在生成测试用例的各个步骤根据实际场景进行配置。It should be noted that configuration items such as the number of positive and negative examples, the keyword library for completing positive and negative example code snippets, the format of test predictions, and the remote repository for external component matching can be pre-configured to facilitate one-click generation of test cases, or they can be configured according to actual scenarios at each step of generating test cases.
基于上述内容描述可知,本申请实施例的测试用例生成方法通过解析检查器的代码,基于代码中定义的错误程序节点以及关联的查询条件,自动生成用于验证检查器正确性的代码片段,提升测试开发效率,并帮助用户自动标注符合检查器检查逻辑的错误代码片段,提升验证效率。此外,该方法支持自动生成编译配置文件,从而帮助用户生成可编译的测试用例。如此,既降低了检查器的开发成本,也通过自动生成测试用例,例如是自动生成测试用例的源文件、测试预言、编译配置文件,显著降低了测试成本。Based on the above description, the test case generation method of the embodiment of the present application automatically generates code snippets for verifying the correctness of the checker based on the error program nodes defined in the code and the associated query conditions by parsing the code of the checker, thereby improving the test development efficiency and helping users to automatically mark the error code snippets that conform to the checker's check logic, thereby improving the verification efficiency. In addition, the method supports the automatic generation of compilation configuration files, thereby helping users to generate compilable test cases. In this way, the development cost of the checker is reduced, and the testing cost is significantly reduced by automatically generating test cases, such as automatically generating source files, test predictions, and compilation configuration files for test cases.
接下来结合一具体应用场景,对本申请的测试用例生成方法进行介绍。Next, the test case generation method of this application is introduced in conjunction with a specific application scenario.
参见图3所示的测试用例生成方法的应用场景示意图,测试用例生成系统10获取检查器的DSL代码,对DSL代码进行节点类型解析,获得DSL代码中定义的错误程序节点,以及对DSL代码进行查询条件解析,获得DSL代码中定义的错误程序节点关联的查询条件,并对DSL代码进行外部组件分析,获得外部组件分析结果。Referring to the application scenario diagram of the test case generation method shown in FIG3 , the test case generation system 10 obtains the DSL code of the checker, performs node type analysis on the DSL code, obtains the erroneous program nodes defined in the DSL code, performs query condition analysis on the DSL code, obtains the query conditions associated with the erroneous program nodes defined in the DSL code, and performs external component analysis on the DSL code to obtain external component analysis results.
然后测试用例生成系统10可以根据错误程序节点以及错误程序节点关联的查询条件构造正例代码片段和反例代码片段。如图3所示,测试用例生成系统10可以构造正例代码片段1至n和反例代码片段1至n,需要说明的是,测试用例生成系统10生成的代码片段数量未达到设置的正例数量和反例数量时,还可以进行缺失片段补充。接着,测试用例生成系统10可以将正例代码片段、反例代码片段进行拼装,生成测试用例的源文件。测试用例系统10可以基于源文件中的正例代码片段,进一步生成测试用例的测试预言。Then the test case generation system 10 can construct positive example code snippets and counterexample code snippets according to the error program node and the query conditions associated with the error program node. As shown in Figure 3, the test case generation system 10 can construct positive example code snippets 1 to n and counterexample code snippets 1 to n. It should be noted that when the number of code snippets generated by the test case generation system 10 does not reach the set number of positive examples and counterexamples, the missing snippets can also be supplemented. Then, the test case generation system 10 can assemble the positive example code snippets and the counterexample code snippets to generate the source file of the test case. The test case system 10 can further generate the test prediction of the test case based on the positive example code snippets in the source file.
为了便于理解,下面结合一示例对生成源文件以及生成测试预言的过程示例说明。如图4所示,DSL代码中定义的错误程序节点包括函数声明节点,该函数声明节点关联的查询条件为函数名为calculate且函数的参数数量为1。测试用例生成系统10可以根据上述函数声明节点以及关联的查询条件构造两个正例代码片段和两个反例代码片段,如图4中的正例1(函数名、参数数量均符合条件)、正例2(函数名、参数数量均符合条件)和反例1(函数名不符合条件)、反例2(参数数量不符合条件)。然后测试用例生成系统10将上述正例代码片段、反例代码片段拼装,从而生成源文件。其中,源文件中的类名、包名可以由用户配置。此外,源文件中还可以包括版权声明(注释形式),用户可以配置该版权声明,以便于测试用例生成系统10以注释方式添加版权声明至源文件。然后测试用例生成系统10可以以注释的形式将测试预言添加到正例代码片段上,该注释指示了问题代码片段(如正例代码片段)的位置,例如为当前行加一。For ease of understanding, the following is an example of the process of generating source files and generating test predictions. As shown in Figure 4, the error program node defined in the DSL code includes a function declaration node, and the query condition associated with the function declaration node is that the function name is calculate and the number of parameters of the function is 1. The test case generation system 10 can construct two positive example code fragments and two negative example code fragments according to the above function declaration nodes and the associated query conditions, such as positive example 1 (function name and number of parameters meet the conditions), positive example 2 (function name and number of parameters meet the conditions) and negative example 1 (function name does not meet the conditions), negative example 2 (number of parameters does not meet the conditions) in Figure 4. Then the test case generation system 10 assembles the above positive example code fragments and negative example code fragments to generate a source file. Among them, the class name and package name in the source file can be configured by the user. In addition, the source file can also include a copyright statement (in the form of comments), and the user can configure the copyright statement so that the test case generation system 10 adds the copyright statement to the source file in the form of comments. Then the test case generation system 10 may add the test prediction to the positive example code snippet in the form of a comment, where the comment indicates the location of the problematic code snippet (such as the positive example code snippet), for example, by adding one to the current line.
测试用例生成系统10还可以根据外部组件分析结果是否涉及外部组件,采用不同方式生成编译配置脚本。当外部组件分析结果表征DSL代码涉及外部组件,测试用例生成系统10可以截取DSL代码中的外部组件的引用信息,并在远程仓库中搜索对应的外部组件,将匹配成功的外部组件的编译信息添加到编译配置脚本的模板,形成编译配置脚本,从而生成完整的测试用例。当外部组件分析结果表征DSL代码不涉及外部组件,测试用例生成系统10可以直接将编译配置脚本的模板,确定为编译配置脚本。The test case generation system 10 can also generate a compilation configuration script in different ways according to whether the external component analysis result involves an external component. When the external component analysis result indicates that the DSL code involves an external component, the test case generation system 10 can intercept the reference information of the external component in the DSL code, search for the corresponding external component in the remote repository, and add the compilation information of the successfully matched external component to the template of the compilation configuration script to form a compilation configuration script, thereby generating a complete test case. When the external component analysis result indicates that the DSL code does not involve an external component, the test case generation system 10 can directly determine the template of the compilation configuration script as the compilation configuration script.
为了便于理解,下面结合一示例对生成编译配置脚本的过程示例说明。首先,测试用例生成系统10根据用户配置的编译工具,生成编译脚本模板。图5的示例中,编译工具为maven,编译脚本模板为maven编译模板。然后,测试用例生成系统10根据DSL代码的外部组件分析结果,生成编译配置脚本。该示例中,外部组件分析结果表征DSL代码涉及外部组件,测试用例生成系统10从远程仓库中匹配和DSL代码中外部组件的引用信息相对应的外部组件,然后将匹配成功的外部组件的编译信息添加到maven编译模板中,生成最终的编译配置脚本。For ease of understanding, the process of generating a compilation configuration script is described below with an example. First, the test case generation system 10 generates a compilation script template based on the compilation tool configured by the user. In the example of Figure 5, the compilation tool is Maven, and the compilation script template is a Maven compilation template. Then, the test case generation system 10 generates a compilation configuration script based on the external component analysis results of the DSL code. In this example, the external component analysis results indicate that the DSL code involves external components. The test case generation system 10 matches the external components corresponding to the reference information of the external components in the DSL code from the remote repository, and then adds the compilation information of the successfully matched external components to the Maven compilation template to generate the final compilation configuration script.
本申请还提供一种测试用例生成系统10,如图1所示,测试用例生成系统10用于生成检查器的测试用例,检查器用于对输入代码进行静态分析,该系统10包括:The present application also provides a test case generation system 10, as shown in FIG1 , the test case generation system 10 is used to generate a test case for a checker, the checker is used to perform static analysis on an input code, and the system 10 includes:
解析子系统100,用于获取所述检查器的代码,对所述检查器的代码进行解析,获得所述检查器的代码中定义的错误程序节点以及所述错误程序节点关联的查询条件,所述错误程序节点为能够引起所述检查器告警的程序节点;The parsing subsystem 100 is used to obtain the code of the checker, parse the code of the checker, obtain the error program node defined in the code of the checker and the query condition associated with the error program node, wherein the error program node is a program node that can cause the checker to issue an alarm;
生成子系统200,用于根据所述错误程序节点以及所述查询条件,生成所述测试用例的源文件,所述测试用例的源文件包括符合所述查询条件的第一代码片段以及不符合所述查询条件的第二代码片段;A generating subsystem 200, configured to generate a source file of the test case according to the error program node and the query condition, wherein the source file of the test case includes a first code segment that meets the query condition and a second code segment that does not meet the query condition;
所述生成子系统200,还用于生成所述测试用例的测试预言,所述测试预言指示所述第一代码片段为引起所述检查器告警的代码片段。The generating subsystem 200 is further configured to generate a test oracle for the test case, wherein the test oracle indicates that the first code snippet is a code snippet that causes the checker to raise an alarm.
示例性地,上述解析子系统100、生成子系统200可以通过硬件实现,或者可以通过软件实现。Exemplarily, the above-mentioned parsing subsystem 100 and generating subsystem 200 may be implemented by hardware or by software.
其中,当通过软件实现时,解析子系统100、生成子系统200可以是运行在计算机设备上的应用程序,如计算引擎等。进一步地,该应用程序还可以通过虚拟化服务进行虚拟化。虚拟化服务可以包括虚拟机(virtual machine,VM)服务、裸金属服务器(bare metalserver,BMS)服务以及容器(container)服务。其中,VM服务可以是通过虚拟化技术在多个物理主机上虚拟出虚拟机(virtual machine,VM)资源池以为用户按需提供VM进行使用的服务。BMS服务是在多个物理主机上虚拟出BMS资源池以为用户按需提供BMS进行使用的服务。容器服务是在多个物理主机上虚拟出容器资源池以为用户按需提供容器进行使用的服务。VM是模拟出来的一台虚拟的计算机,也即逻辑上的一台计算机。BMS是一种可弹性伸缩的高性能计算服务,计算性能与传统物理机无差别,具有安全物理隔离的特点。容器是一种内核虚拟化技术,可以提供轻量级的虚拟化,以达到隔离用户空间、进程和资源的目的。应理解,上述虚拟化服务中的VM服务、BMS服务以及容器服务仅仅是作为具体的事例,在实际应用中,虚拟化服务还可以其他轻量级或者重量级的虚拟化服务,此处不作具体限定。Among them, when implemented by software, the parsing subsystem 100 and the generating subsystem 200 can be applications running on a computer device, such as a computing engine, etc. Further, the application can also be virtualized through a virtualization service. Virtualization services may include virtual machine (VM) services, bare metal server (BMS) services, and container services. Among them, the VM service can be a service that virtualizes a virtual machine (VM) resource pool on multiple physical hosts through virtualization technology to provide users with VMs on demand for use. The BMS service is a service that virtualizes a BMS resource pool on multiple physical hosts to provide users with BMS on demand for use. The container service is a service that virtualizes a container resource pool on multiple physical hosts to provide users with containers on demand for use. VM is a simulated virtual computer, that is, a logical computer. BMS is a high-performance computing service that can be elastically scalable, and its computing performance is no different from that of a traditional physical machine, and it has the characteristics of secure physical isolation. Containers are a kernel virtualization technology that can provide lightweight virtualization to achieve the purpose of isolating user space, processes, and resources. It should be understood that the VM service, BMS service and container service in the above-mentioned virtualization services are only specific examples. In actual applications, virtualization services can also be other lightweight or heavyweight virtualization services, which are not specifically limited here.
当通过硬件实现时,解析子系统100、生成子系统200中可以包括至少一个计算设备,如服务器等。或者,解析子系统100、生成子系统200也可以是利用专用集成电路(application-specific integrated circuit,ASIC)实现、或可编程逻辑器件(programmable logic device,PLD)实现的设备等。其中,上述PLD可以是复杂程序逻辑器件(complex programmable logical device,CPLD)、现场可编程门阵列(field-programmable gate array,FPGA)、通用阵列逻辑(generic array logic,GAL)或其任意组合实现。When implemented by hardware, the parsing subsystem 100 and the generating subsystem 200 may include at least one computing device, such as a server, etc. Alternatively, the parsing subsystem 100 and the generating subsystem 200 may also be implemented by using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The PLD may be a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL) or any combination thereof.
进一步地,解析子系统100包括节点类型识别模块102和查询条件识别模块104。节点类型识别模块102用于对检查器的代码进行识别,获得检查器的代码中定义的错误程序节点,查询条件识别模块104用于对检查器的代码进行识别,获得错误程序节点关联的查询条件。Furthermore, the parsing subsystem 100 includes a node type identification module 102 and a query condition identification module 104. The node type identification module 102 is used to identify the code of the checker and obtain the error program node defined in the code of the checker, and the query condition identification module 104 is used to identify the code of the checker and obtain the query condition associated with the error program node.
与解析子系统100类似,节点类型识别模块102和查询条件识别模块104可以通过硬件实现,或者可以通过软件实现。Similar to the parsing subsystem 100 , the node type identification module 102 and the query condition identification module 104 may be implemented by hardware or software.
当通过软件实现时,节点类型识别模块102和查询条件识别模块104可以是运行在计算机设备上的应用程序,如计算引擎等。进一步地,该应用程序还可以通过虚拟化服务进行虚拟化。例如,节点类型识别模块102可以是用于实现节点类型识别的容器(服务),查询条件识别模块104可以是用于实现查询条件识别的容器(服务)。当通过硬件实现时,节点类型识别模块102和查询条件识别模块104可以包括至少一个计算设备,如服务器等。或者节点类型识别模块102和查询条件识别模块104可以是通过利用ASIC或PLD实现的设备。When implemented by software, the node type identification module 102 and the query condition identification module 104 may be an application program running on a computer device, such as a computing engine, etc. Further, the application program may also be virtualized through a virtualization service. For example, the node type identification module 102 may be a container (service) for implementing node type identification, and the query condition identification module 104 may be a container (service) for implementing query condition identification. When implemented by hardware, the node type identification module 102 and the query condition identification module 104 may include at least one computing device, such as a server, etc. Alternatively, the node type identification module 102 and the query condition identification module 104 may be devices implemented by utilizing an ASIC or a PLD.
生成子系统200包括正反例代码片段生成模块202、源文件生成模块204、测试预言生成模块206。正反例代码片段生成模块202用于根据错误程序节点和关联条件生成正例代码片段和反例代码片段,正例代码片段为符合查询条件的第一代码片段,反例代码片段为不符合所述查询条件的第二代码片段。源文件生成模块204用于根据正例代码片段和反例代码片段,生成测试用例的源文件。测试预言生成模块206用于生成测试用例的测试预言,测试预言指示正例代码片段为引起检查器告警的代码片段。The generation subsystem 200 includes a positive and negative example code snippet generation module 202, a source file generation module 204, and a test prediction generation module 206. The positive and negative example code snippet generation module 202 is used to generate a positive example code snippet and a negative example code snippet according to the error program node and the associated conditions, the positive example code snippet is a first code snippet that meets the query condition, and the negative example code snippet is a second code snippet that does not meet the query condition. The source file generation module 204 is used to generate a source file of a test case according to the positive example code snippet and the negative example code snippet. The test prediction generation module 206 is used to generate a test prediction for the test case, and the test prediction indicates that the positive example code snippet is a code snippet that causes the checker to alarm.
与生成子系统200类似,正反例代码片段生成模块202、源文件生成模块204、测试预言生成模块206可以通过硬件实现,或者可以通过软件实现。Similar to the generation subsystem 200, the positive and negative example code snippet generation module 202, the source file generation module 204, and the test prediction generation module 206 may be implemented by hardware or by software.
当通过软件实现时,正反例代码片段生成模块202、源文件生成模块204、测试预言生成模块206可以是运行在计算机设备上的应用程序,如计算引擎等。进一步地,该应用程序还可以通过虚拟化服务进行虚拟化。例如,正反例代码片段生成模块202可以是用于实现正反例生成的容器(服务),源文件生成模块204可以是用于实现源文件生成的容器(服务),测试预言生成模块206可以是用于实现测试预言生成的容器(服务)。当通过硬件实现时,正反例代码片段生成模块202、源文件生成模块204、测试预言生成模块206可以包括至少一个计算设备,如服务器等。或者正反例代码片段生成模块202、源文件生成模块204、测试预言生成模块206可以是通过利用ASIC或PLD实现的设备。When implemented by software, the positive and negative example code snippet generation module 202, the source file generation module 204, and the test prediction generation module 206 can be applications running on a computer device, such as a computing engine, etc. Further, the application can also be virtualized through a virtualization service. For example, the positive and negative example code snippet generation module 202 can be a container (service) for implementing positive and negative example generation, the source file generation module 204 can be a container (service) for implementing source file generation, and the test prediction generation module 206 can be a container (service) for implementing test prediction generation. When implemented by hardware, the positive and negative example code snippet generation module 202, the source file generation module 204, and the test prediction generation module 206 can include at least one computing device, such as a server, etc. Or the positive and negative example code snippet generation module 202, the source file generation module 204, and the test prediction generation module 206 can be devices implemented by using ASIC or PLD.
在一些可能的实现方式中,生成子系统200具体用于:In some possible implementations, the generating subsystem 200 is specifically used for:
根据用户配置的所述测试预言的输出格式,生成所述测试用例的测试预言。Generate a test oracle for the test case according to an output format of the test oracle configured by a user.
在一些可能的实现方式中,所述生成子系统200具体用于:In some possible implementations, the generating subsystem 200 is specifically used for:
根据用户配置的所述测试预言的输出格式,生成所述第一代码片段的注释,所述测试用例的测试预言包括所述第一代码片段的注释;或者,Generate a comment for the first code snippet according to an output format of the test oracle configured by a user, wherein the test oracle of the test case includes the comment for the first code snippet; or
根据用户配置的所述测试预言的输出格式,生成独立于所述第一代码片段的预言文件。A prediction file independent of the first code snippet is generated according to an output format of the test prediction configured by a user.
在一些可能的实现方式中,所述输入代码通过编译语言编写,所述生成子系统200还用于:In some possible implementations, the input code is written in a compiled language, and the generation subsystem 200 is further used to:
根据用户配置的编译工具,生成所述测试用例的编译配置文件。Generate a compilation configuration file for the test case according to the compilation tool configured by the user.
具体地,生成子系统200还可以包括编译配置生成模块208。编译配置生成模块208用于生成测试用例的编译配置文件。其中,编译配置文件可以是编译配置脚本。编译配置生成模块208可以在待测预言为编译语言,如检查器的输入代码为编译语言编写的代码时,生成测试用例的编译配置文件。其中,编译配置生成模块208可以根据用户配置的编译工具,生成与编译工具对应的编译配置文件的模板,基于该模板获得编译配置文件。Specifically, the generation subsystem 200 may further include a compilation configuration generation module 208. The compilation configuration generation module 208 is used to generate a compilation configuration file for the test case. The compilation configuration file may be a compilation configuration script. The compilation configuration generation module 208 may generate a compilation configuration file for the test case when the predicted language to be tested is a compilation language, such as when the input code of the checker is a code written in a compilation language. The compilation configuration generation module 208 may generate a template of a compilation configuration file corresponding to the compilation tool according to the compilation tool configured by the user, and obtain the compilation configuration file based on the template.
与正反例代码片段生成模块202、源文件生成模块204、测试预言生成模块206类似,编译配置生成模块208可以通过硬件实现,或者可以通过软件实现。在此不再赘述。Similar to the positive and negative example code snippet generation module 202, the source file generation module 204, and the test prediction generation module 206, the compilation configuration generation module 208 can be implemented by hardware or software, which will not be described in detail here.
在一些可能的实现方式中,所述生成子系统200具体用于:In some possible implementations, the generating subsystem 200 is specifically used for:
根据用户配置的编译工具,生成与所述编译工具对应的编译配置文件的模板;Generate a template of a compilation configuration file corresponding to the compilation tool according to the compilation tool configured by the user;
当所述检查器的代码中包括外部组件的引用信息,获取所述外部组件的编译信息,并将所述外部组件的编译信息添加至所述模板中,获得所述编译配置文件。When the code of the checker includes reference information of an external component, the compilation information of the external component is obtained, and the compilation information of the external component is added to the template to obtain the compilation configuration file.
具体地,生成子系统200还包括外部组件匹配模块210,外部组件识别模块210用于根据外部组件的引用信息,在仓库(例如是远程仓库)中匹配外部组件,获得外部组件的编译信息。相应地,编译配置生成模块208可以将外部组件的编译信息添加至编译配置文件的模板,获得编译配置文件。Specifically, the generation subsystem 200 further includes an external component matching module 210, which is used to match the external component in a warehouse (e.g., a remote warehouse) according to the reference information of the external component to obtain the compilation information of the external component. Accordingly, the compilation configuration generation module 208 can add the compilation information of the external component to the template of the compilation configuration file to obtain the compilation configuration file.
与正反例代码片段生成模块202、源文件生成模块204、测试预言生成模块206类似,外部组件匹配模块210可以通过硬件实现,或者可以通过软件实现。在此不再赘述。Similar to the positive and negative example code snippet generation module 202, the source file generation module 204, and the test prediction generation module 206, the external component matching module 210 can be implemented by hardware or software, which will not be described in detail here.
在一些可能的实现方式中,所述错误程序节点包括方法声明节点、变量使用节点、赋值表达式节点中的一种或多种。In some possible implementations, the erroneous program node includes one or more of a method declaration node, a variable use node, and an assignment expression node.
在一些可能的实现方式中,所述检查器的代码为领域特定语言DSL代码。In some possible implementations, the code of the checker is a domain specific language (DSL) code.
由于图1所示的测试用例生成系统10对应于图2至图5所示的测试用例生成方法,故图1所示的测试用例生成系统10的具体实现方式及其所具有的技术效果,可以参见前述实施例中的相关之处描述,在此不做赘述。Since the test case generation system 10 shown in FIG. 1 corresponds to the test case generation method shown in FIGS. 2 to 5 , the specific implementation method of the test case generation system 10 shown in FIG. 1 and its technical effects can be found in the relevant descriptions in the aforementioned embodiments and will not be repeated here.
本申请还提供一种计算设备600。如图6所示,计算设备600包括:总线602、处理器604、存储器606和通信接口608。处理器604、存储器606和通信接口608之间通过总线602通信。计算设备600可以是服务器或终端设备。应理解,本申请不限定计算设备600中的处理器、存储器的个数。The present application also provides a computing device 600. As shown in FIG6 , the computing device 600 includes: a bus 602, a processor 604, a memory 606, and a communication interface 608. The processor 604, the memory 606, and the communication interface 608 communicate with each other through the bus 602. The computing device 600 can be a server or a terminal device. It should be understood that the present application does not limit the number of processors and memories in the computing device 600.
总线602可以是外设部件互连标准(peripheral component interconnect,PCI)总线或扩展工业标准结构(extended industry standard architecture,EISA)总线等。总线可以分为地址总线、数据总线、控制总线等。为便于表示,图6中仅用一条线表示,但并不表示仅有一根总线或一种类型的总线。总线602可包括在计算设备600各个部件(例如,存储器606、处理器604、通信接口608)之间传送信息的通路。The bus 602 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, FIG6 is represented by only one line, but does not mean that there is only one bus or one type of bus. The bus 602 may include a path for transmitting information between various components of the computing device 600 (e.g., the memory 606, the processor 604, and the communication interface 608).
处理器604可以包括中央处理器(central processing unit,CPU)、图形处理器(graphics processing unit,GPU)、微处理器(micro processor,MP)或者数字信号处理器(digital signal processor,DSP)等处理器中的任意一种或多种。The processor 604 may include any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
存储器606可以包括易失性存储器(volatile memory),例如随机存取存储器(random access memory,RAM)。存储器606还可以包括非易失性存储器(non-volatilememory),例如只读存储器(read-only memory,ROM),快闪存储器,机械硬盘(hard diskdrive,HDD)或固态硬盘(solid state drive,SSD)。存储器606中存储有可执行的程序代码,处理器604执行该可执行的程序代码以实现前述测试用例生成方法。具体的,存储器606上存有测试用例生成系统10用于执行测试用例生成方法的指令。The memory 606 may include a volatile memory, such as a random access memory (RAM). The memory 606 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD) or a solid state drive (SSD). The memory 606 stores executable program code, and the processor 604 executes the executable program code to implement the aforementioned test case generation method. Specifically, the memory 606 stores instructions for the test case generation system 10 to execute the test case generation method.
通信接口608使用例如但不限于网络接口卡、收发器一类的收发模块,来实现计算设备600与其他设备或通信网络之间的通信。The communication interface 608 uses a transceiver module such as, but not limited to, a network interface card or a transceiver to implement communication between the computing device 600 and other devices or communication networks.
本申请实施例还提供了一种计算设备集群。该计算设备集群包括至少一台计算设备。该计算设备可以是服务器,例如是中心服务器、边缘服务器,或者是本地数据中心中的本地服务器。在一些实施例中,计算设备也可以是台式机、笔记本电脑或者智能手机等终端设备。The embodiment of the present application also provides a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device such as a desktop computer, a laptop computer, or a smart phone.
如图7所示,所述计算设备集群包括至少一个计算设备600。计算设备集群中的一个或多个计算设备600中的存储器606中可以存有相同的测试用例生成系统10用于执行测试用例生成方法的指令。As shown in Fig. 7, the computing device cluster includes at least one computing device 600. The memory 606 in one or more computing devices 600 in the computing device cluster may store the same instructions for executing the test case generation method by the test case generation system 10.
在一些可能的实现方式中,该计算设备集群中的一个或多个计算设备600也可以用于执行测试用例生成系统10用于执行测试用例生成方法的部分指令。换言之,一个或多个计算设备600的组合可以共同执行测试用例生成系统10用于执行测试用例生成方法的指令。In some possible implementations, one or more computing devices 600 in the computing device cluster may also be used to execute some instructions of the test case generation system 10 for executing the test case generation method. In other words, a combination of one or more computing devices 600 may jointly execute the instructions of the test case generation system 10 for executing the test case generation method.
需要说明的是,计算设备集群中的不同的计算设备600中的存储器606可以存储不同的指令,用于执行测试用例生成系统10的部分功能。It should be noted that the memory 606 in different computing devices 600 in the computing device cluster may store different instructions for executing partial functions of the test case generation system 10 .
图8示出了一种可能的实现方式。如图8所示,两个计算设备600A和600B通过通信接口608实现连接。计算设备600A中的存储器上存有用于执行解析子系统100的功能的指令。计算设备600B中的存储器上存有用于执行生成子系统200的功能的指令。换言之,计算设备600A和600B的存储器606共同存储了测试用例生成系统10用于执行测试用例生成方法的指令。FIG8 shows a possible implementation. As shown in FIG8 , two computing devices 600A and 600B are connected via a communication interface 608. The memory in computing device 600A stores instructions for executing the functions of parsing subsystem 100. The memory in computing device 600B stores instructions for executing the functions of generating subsystem 200. In other words, the memory 606 of computing devices 600A and 600B jointly stores instructions for test case generation system 10 to execute the test case generation method.
图8所示的计算设备集群之间的连接方式可以是考虑到本申请提供的测试用例生成方法需要大量算力进行正例代码片段生成、反例代码片段生成,当涉及外部组件时,还需要大量算力搜索或匹配外部组件的编译信息。因此,考虑将生成子系统200实现的功能交由计算设备600B执行。The connection mode between the computing device clusters shown in FIG8 can be considered that the test case generation method provided in the present application requires a large amount of computing power to generate positive code snippets and negative code snippets, and when external components are involved, a large amount of computing power is also required to search or match the compilation information of the external components. Therefore, it is considered that the functions implemented by the generation subsystem 200 are handed over to the computing device 600B for execution.
应理解,图8中示出的计算设备600A的功能也可以由多个计算设备600完成。同样,计算设备600B的功能也可以由多个计算设备600完成。It should be understood that the functions of the computing device 600A shown in FIG8 may also be completed by multiple computing devices 600. Similarly, the functions of the computing device 600B may also be completed by multiple computing devices 600.
在一些可能的实现方式中,计算设备集群中的一个或多个计算设备可以通过网络连接。其中,所述网络可以是广域网或局域网等等。图9示出了一种可能的实现方式。如图9所示,两个计算设备600C和600D之间通过网络进行连接。具体地,通过各个计算设备中的通信接口与所述网络进行连接。在这一类可能的实现方式中,计算设备600C中的存储器606中存有执行解析子系统100的功能的指令。同时,计算设备600D中的存储器606中存有执行生成子系统200的功能的指令。In some possible implementations, one or more computing devices in the computing device cluster can be connected via a network. Wherein, the network can be a wide area network or a local area network, etc. FIG. 9 shows a possible implementation. As shown in FIG. 9 , two computing devices 600C and 600D are connected via a network. Specifically, the network is connected via a communication interface in each computing device. In this type of possible implementation, the memory 606 in the computing device 600C stores instructions for executing the functions of the parsing subsystem 100. At the same time, the memory 606 in the computing device 600D stores instructions for executing the functions of the generation subsystem 200.
图9所示的计算设备集群之间的连接方式可以是考虑到本申请提供的测试用例生成方法需要大量算力进行正例代码片段生成、反例代码片段生成,当涉及外部组件时,还需要大量算力搜索或匹配外部组件的编译信息。因此考虑将生成子系统200实现的功能交由计算设备600D执行。The connection mode between the computing device clusters shown in FIG9 can be considered that the test case generation method provided in the present application requires a large amount of computing power to generate positive code snippets and negative code snippets, and when external components are involved, a large amount of computing power is also required to search or match the compilation information of the external components. Therefore, it is considered that the functions implemented by the generation subsystem 200 are handed over to the computing device 600D for execution.
应理解,图9中示出的计算设备600C的功能也可以由多个计算设备600完成。同样,计算设备600D的功能也可以由多个计算设备600完成。It should be understood that the functions of the computing device 600C shown in FIG9 may also be completed by multiple computing devices 600. Similarly, the functions of the computing device 600D may also be completed by multiple computing devices 600.
本申请实施例还提供了一种计算机可读存储介质。所述计算机可读存储介质可以是计算设备能够存储的任何可用介质或者是包含一个或多个可用介质的数据中心等数据存储设备。所述可用介质可以是磁性介质,(例如,软盘、硬盘、磁带)、光介质(例如,DVD)、或者半导体介质(例如固态硬盘)等。该计算机可读存储介质包括指令,所述指令指示计算设备执行上述应用于测试用例生成系统10用于执行测试用例生成方法。The embodiment of the present application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that can be stored by a computing device or a data storage device such as a data center containing one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk). The computer-readable storage medium includes instructions that instruct the computing device to execute the above-mentioned test case generation system 10 for executing the test case generation method.
本申请实施例还提供了一种包含指令的计算机程序产品。所述计算机程序产品可以是包含指令的,能够运行在计算设备上或被储存在任何可用介质中的软件或程序产品。当所述计算机程序产品在至少一个计算机设备上运行时,使得至少一个计算机设备执行上述测试用例生成方法。The embodiment of the present application also provides a computer program product including instructions. The computer program product may be software or a program product including instructions that can be run on a computing device or stored in any available medium. When the computer program product is run on at least one computer device, the at least one computer device executes the above test case generation method.
最后应说明的是:以上实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的保护范围。Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the protection scope of the technical solutions of the embodiments of the present invention.
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN2023102074278 | 2023-03-06 | ||
| CN202310207427 | 2023-03-06 |
| Publication Number | Publication Date |
|---|---|
| CN118642937Atrue CN118642937A (en) | 2024-09-13 |
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202310544891.6APendingCN118642937A (en) | 2023-03-06 | 2023-05-15 | A test case generation method and related system |
| Country | Link |
|---|---|
| CN (1) | CN118642937A (en) |
| Publication | Publication Date | Title |
|---|---|---|
| CN114041117B (en) | Continuous annotation of grammar graphs for code optimization | |
| US11650905B2 (en) | Testing source code changes | |
| US11675575B2 (en) | Checking source code validity at time of code update | |
| US10152309B2 (en) | Cross-library framework architecture feature sets | |
| CN109634869B (en) | Binary translation intermediate representation correctness testing method and device | |
| WO2021098148A1 (en) | Software compiling method and apparatus, and electronic device and storage medium | |
| CN108139891A (en) | Include suggesting for the missing of external file | |
| US9141351B2 (en) | Indicators for resources with idempotent close methods in software programs | |
| CN101859246A (en) | System and method for converting corresponding scripts according to different browsers | |
| WO2025103216A1 (en) | Code testing method and related system | |
| US10839124B1 (en) | Interactive compilation of software to a hardware language to satisfy formal verification constraints | |
| US20170075668A1 (en) | Methods and Systems for Generating Client-Server Applications for Target Devices | |
| WO2022127263A1 (en) | Code processing method and related device | |
| WO2019227899A1 (en) | Program calling decoupling | |
| WO2025081782A1 (en) | Code analysis method and related device | |
| US11366657B2 (en) | Inferring code deprecation from module deprecation | |
| CN118916070A (en) | Software dependency relation detection method and related equipment | |
| CN118642937A (en) | A test case generation method and related system | |
| CN111796832A (en) | Hot patch file generation method, device, equipment and storage medium | |
| TW200417924A (en) | WIN F-language interpreter | |
| US12417289B2 (en) | Systems and methods for detecting malware in obfuscated scripts | |
| CN118819487A (en) | A code checker generation method and related system | |
| CN119397544A (en) | Smart contract static analysis method and device | |
| US11972237B1 (en) | Member invocation declarative interception | |
| CN116069633B (en) | Code inspection methods, devices, electronic equipment and storage media |
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication |