| Software testing can effectively improve the efficiency of software development and the reliability of the system.With the increase in software scale and complexity,the efficiency of manual testing is getting lower and lower.By contrast,using automated testing tools can reduce a lot of tedious work and improve the efficiency of testing.As an important part of software testing,unit testing can take the lead in discovering problems within the module and is the basis of the entire software testing.Therefore,it has important theoretical and practical value for the development of automated unit testing tools.The automation of test case generation directly affects the degree of automation of unit testing tools.In object-oriented programs,complex data types represented by classes have problems such as unfixed structure and complex constraint relationships.The analysis of complex data types is a major difficulty in test case generation.Most of the existing research focuses on the analysis of the values of simple type variables,but does not consider the impact of data types on the execution path,resulting in the low accuracy of the static representation of complex types by the existing test case generation methods.In particular,the lack of analysis of the type range of class objects makes it difficult to further improve the unit test coverage of such programs.This paper conducts research on this problem,and the main research contents include the following three points:(1)Research on symbol table for classes in C++In static analysis,the symbol table is used to record the attributes of each variable,function and class and the relationship between them,so that the required information can be quickly obtained during subsequent test case generation and execution.Aiming at the characteristics of classes,this paper uses stacks to manage the hierarchical relationship between symbol tables,defines the structure of the corresponding symbol table entries of variables,functions and classes,and gives the extraction method of function input variables based on the symbol table and abstract syntax tree,making it applicable to the automated testing tool of C++ programs.(2)Research on abstract memory model of class and simulation algorithm of operation semanticsIn order to improve the code coverage of the test case,it is necessary to extract the constraint information in the function,narrow the type range of the class objects and the value range of each variable in the test case.This paper proposes an abstract memory model of class,uses it to record semantic and constraint information in program,and designs a simulation algorithm of operation semantics of class to update the corresponding memory model with static analysis.According to the commonality of the class and the characteristics of the instance,the abstract memory model of the class is divided into the abstract memory model of the class type and the abstract memory model of the class object.The former is used to record the constraint information of static variable,and the latter is used to record the constraint information of non-static variable.The operations related to classes include object creation,member access and type conversion.This paper analyzes each operation in turn,and designs the corresponding simulation algorithm of operation semantics.(3)Research on path-based random test case generation methodIn order to improve the efficiency of testing,this paper optimizes the random test based on the input domain and studies the random test based on the path.In the path analysis,through symbolic execution,the corresponding abstract memory models are constructed,the semantic and constraint information in the path is extracted,and the actual types of the class objects are limited,so as to avoid the generation of useless test cases.Under the premise of ensuring coverage,prune the set of test cases.Finally,the paper implements the above methods based on the test case generation module in the test tool CTS-CPP.The experimental results show the feasibility of the class-oriented symbol table,the abstract memory model of the class and the simulation algorithm of operation semantics.Compared with the random test based on the input domain,the path-based random test can improve the utilization of test cases,thereby improving the efficiency of C++ unit testing. |