CN109359036A - Test method, device, computer readable storage medium and computer equipment - Google Patents
Test method, device, computer readable storage medium and computer equipment Download PDFInfo
- Publication number
- CN109359036A CN109359036A CN201811117059.3A CN201811117059A CN109359036A CN 109359036 A CN109359036 A CN 109359036A CN 201811117059 A CN201811117059 A CN 201811117059A CN 109359036 A CN109359036 A CN 109359036A
- Authority
- CN
- China
- Prior art keywords
- function
- class
- simulation
- macro
- analog
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/3668—Software testing
- G06F11/3672—Test management
- G06F11/3684—Test management for test design, e.g. generating new test cases
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/3668—Software testing
- G06F11/3672—Test management
- G06F11/3688—Test management for test execution, e.g. scheduling of test suites
Abstract
This application involves a kind of test method, device, computer readable storage medium and computer equipments, which comprises test case corresponding to compiling tested code;The objective function that the tested code is called when including for compiling the test case;When the objective function is called, by executing jump instruction corresponding with the objective function, analog function corresponding with the objective function is jumped to;The objective function is identical as the analog function function;The analog function is executed, the return value of the analog function is obtained;The test result of the tested code is determined according to the return value.Scheme provided by the present application has wide applicability.
Description
Technical field
This application involves field of computer technology, more particularly to a kind of test method, device, computer-readable storage medium
Matter and computer equipment.
Background technique
It, usually will be to the computer journey write in the development process of computer program with the development of computer technology
Sequence is tested, to check whether the computer program write realizes expected function.Currently, needing to adjust in computer program
With other function, and when the function can not call due to various reasons, usually substituted by simulating the function true
Object is tested.However, current analog form has certain limitation, it is typically only capable to for the void in computer program
Function is simulated.
Summary of the invention
Based on this, it is necessary to there is the technical issues of certain limitation for current analog form, provide a kind of survey
Method for testing, device, computer readable storage medium and computer equipment.
A kind of test method, comprising:
Compile test case corresponding to tested code;The tested code includes for compiling the test case
When the objective function that calls;
When the objective function is called, by executing jump instruction corresponding with the objective function, jump to and
The corresponding analog function of the objective function;The objective function is identical as the analog function function;
The analog function is executed, the return value of the analog function is obtained;
The test result of the tested code is determined according to the return value.
A kind of test device, comprising:
Collector, for compiling test case corresponding to tested code;The tested code includes for compiling
The objective function called when translating the test case;
Jump module, for being jumped by the way that execution is corresponding with the objective function when the objective function is called
Instruction, jumps to analog function corresponding with the objective function;The objective function is identical as the analog function function;
Execution module obtains the return value of the analog function for executing the analog function;
Processing module, for determining the test result of the tested code according to the return value.
A kind of computer readable storage medium is stored with computer program, when the computer program is executed by processor,
So that the processor executes the step of above-mentioned test method.
A kind of computer equipment, including memory and processor, the memory are stored with computer program, the calculating
When machine program is executed by the processor, so that the step of processor executes above-mentioned test method.
Above-mentioned test method, device, computer readable storage medium and computer equipment, objective function are tested codes
The function called required for realizing, when compiling test case corresponding to tested code, when needing invocation target function,
No longer it is to call the objective function, but jump to calling analog function identical with objective function function, passes through analog function
The interaction with tested code is simulated, return value is obtained, the test result of tested code can be determined according to return value.This
Sample, analog function are not inherited from any class, can test the tested code for calling all kinds of functions, greatly widen
Application range.
Detailed description of the invention
Fig. 1 is the flow diagram of test method in one embodiment;
Fig. 2 is the code schematic diagram of function call in one embodiment;
Fig. 3 is the schematic diagram of compiled code in one embodiment;
Fig. 4 is in one embodiment by code comparison's schematic diagram of Mock class and Mock class;
Fig. 5 is in another embodiment by code comparison's schematic diagram of Mock class and Mock class;
Fig. 6 is in another embodiment by code comparison's schematic diagram of Mock class and Mock class;
Fig. 7 is in another embodiment by code comparison's schematic diagram of Mock class and Mock class;
Fig. 8 is in another embodiment by code comparison's schematic diagram of Mock class and Mock class;
Fig. 9 is in another embodiment by code comparison's schematic diagram of Mock class and Mock class;
Figure 10 is the logic diagram of test method in one embodiment;
Figure 11 is the structural block diagram of test device in one embodiment;
Figure 12 is the structural block diagram of test device in another embodiment;
Figure 13 is the structural block diagram of computer equipment in one embodiment.
Specific embodiment
It is with reference to the accompanying drawings and embodiments, right in order to which the objects, technical solutions and advantages of the application are more clearly understood
The application is further elaborated.It should be appreciated that specific embodiment described herein is only used to explain the application, and
It is not used in restriction the application.
Test method provided by each embodiment of the application can be applied to various computer equipments, such as fixed terminal or shifting
Dynamic terminal, mobile terminal such as mobile phone, tablet computer or wearable electronic etc..These computer equipments can be based on various behaviour
Make system, for example, Windows operating system, (SuSE) Linux OS or Android operation system etc..
As shown in Figure 1, in one embodiment, providing a kind of test method.The present embodiment is mainly applied in this way
It is illustrated in based on the computer equipment of (SuSE) Linux OS.Referring to Fig.1, which specifically comprises the following steps:
S102 compiles test case corresponding to tested code;When tested code includes for compiler test use-case
The objective function of calling.
Wherein, tested code is to need tested computer program.Test case is for testing tested code
Whether the computer program of expectation function is realized.In the particular embodiment, tested code and test case may each be base
In the computer program that Object-Oriented Programming Languages are write.Object-Oriented Programming Languages are specifically such as C Plus Plus (The
C++Programming Language).Objective function is the letter that tested code needs to call during realizing function
Number.
Specifically, computer equipment can be begun through corresponding to compiler compiling tested code according to user instructions
Test case.It is appreciated that test case can be first copied to the catalogue of tested engineering by computer equipment according to user instructions
In.Here tested engineering is the engineering where tested code.This is because tested code during code tester
It is compiled together with test case, that is to say, that tested code can be compiled in compiler test use-case.
S104 by executing corresponding with objective function jump instruction, is jumped to and target when objective function is called
The corresponding analog function of function;Objective function is identical as analog function function.
It is more troublesome it is appreciated that objective function can not may be called or call due to various reasons.For example, target
Function is not yet realized, objective function is developed by other development teams or objective function structure is complicated.And it actually tested
Tested code is when realizing in journey, and is not concerned with how objective function is specifically realized, but focuses on the function of objective function,
The function of objective function is to return to different results according to after different input parameter processings.So, in this case, it tests
When tested code, analog one analog function identical with objective function function replaces target by the analog function
Function is interacted with tested code, to improve testing efficiency.That is, in this case, objective function be exactly need by
The function of simulation, the function simulated are exactly analog function.
Specifically, computer equipment can on the basis of normal function call process, need invocation target function and
Before objective function execution, the compiled code of modified objective function adds jump instruction corresponding with objective function, so that
When performance objective function, calling analog function corresponding with objective function is jumped to.Wherein, objective function institute is directed toward in jump instruction
The function address of corresponding analog function can jump to calling simulation corresponding with objective function from invocation target function in this way
Function.
In the embodiment of the present application, computer equipment is realized by hook variable and Hook Function by objective function and and mesh
The corresponding analog function association of scalar functions.Computer equipment records the function address of analog function by hook variable.In this way, meter
Calculating machine equipment can be by Hook Function before performance objective function, the code of modified objective function, is added and is directed toward objective function
The jump instruction of the function address of corresponding analog function.
Wherein, hook (HOOK) function is the program segment of processing event.Whenever the specific thing that triggering Hook Function is hooked
When part, Hook Function can intercept and capture the particular event and enforce other particular event.The specific thing that Hook Function hooks
The calling event of part such as objective function enforces other particular event and such as jumps mould corresponding to invocation target function
Pseudofunction jumps event.
Hook variable is the variable of Hook Function, for the function address of management simulation function.Analog function is to simulate
Object identical with objective function function.Objective function specifically can be by Mock function, and analog function specifically can be
Mock function.In assembly code, jump instruction specifically can be compilation JMP instruction.
Fig. 2 shows the code schematic diagrames of function call in one embodiment.With reference to Fig. 2, normalFunc is mesh in Fig. 2
Scalar functions, MocknormalFunc are analog function corresponding with objective function.It is corresponding after invocation target function under normal circumstances
Assembly code be the region Fig. 2 upper left " before Hook " code.It can be obvious with reference to Fig. 2 bottom left section and right half part
See, after Hook, when going to objective function, mould corresponding to the objective function is jumped to by assembly instruction
Pseudofunction.That is, invocation target function, what is actually executed is analog function corresponding with objective function.It is appreciated that figure
Assembly code shown in 2 is only used for for example, assembly code specifically used in actual scene may include than shown in Fig. 2
More or fewer contents.
S106 executes analog function, obtains the return value of analog function.
Wherein, the return value of analog function is the result that analog function returns.The return value of analog function may include mould
The data that return statement is returned in pseudofunction and/or the data exported by analog function.Specifically, computer equipment is being adjusted
, can be to objective function Transfer Parameters when with objective function, that is, objective function actually enters value.So jump call with
When the corresponding analog function of objective function, the parameter passed over can also be transferred to the analog function, in this way, analog function
Return to result corresponding with value is actually entered.
In one embodiment, the test method further include: by test it is macro setting analog function expectation input value and
Corresponding return value;Desired input value and corresponding return value are transferred to simulation administrative unit storage.S106 includes: to pass through mould
The input value received is transferred to simulation administrative unit by pseudofunction;Pass through the determination of simulation administrative unit and input value consistent phase
Hope input value, and using the determining corresponding return value of expectation input value as the return value of analog function.
It should be noted that macro involved in the embodiment of the present application, it is based on the macro of computer science, is that a kind of grammer replaces
It changes, for illustrating how input according to predefined rule is converted into corresponding output.This replacement is carried out in precompile, is claimed
Make macro expansion.
It tests macro for it is expected input value and corresponding return value for analog function setting.Testing macro specifically can be
EXPECT_CALL provided by the gmock test frame of google company publication etc. is macro.
The expectation input value and corresponding return value of analog function, that is, the expectation input value of objective function and corresponding
Return value.When the expectation input value of objective function is invocation target function, it is expected that passing to the input value of objective function.It is expected that defeated
Enter and be worth corresponding return value, is the value that expectation target function returns under the expectation input value.
It illustrates, it is assumed that code to be tested is function A, and objective function is function B.The function of function B is to work as input value
True value (True) is returned when greater than 10, otherwise returns to falsity (False);And code logic is to return very in function B in function A
When value, certain function is realized;Otherwise another function is realized.It can determine that function A passes to function from the realization logic of function A
The parameter value of B only has 9 and 11 two kind of situation.So, 9 and 11 be objective function expectation input value.9 corresponding return values are
False, 11 corresponding return values are True.
Simulation administrative unit is to be used to be managed collectively the expectation input value of each analog function in test frame and return accordingly
Return the module of value.The expectation input value and corresponding return value of different analog functions, pass through the function name and function of analog function
Parameter is distinguished.
Specifically, when macro to macro expansion test, the expectation of analog function is arranged in compiler test use-case in computer equipment
Input value and corresponding return value;Desired input value and corresponding return value are transferred to simulation administrative unit, simulation management is single
The expectation input value and corresponding return value of analog function, function name and function parameter with the analog function can will be arranged in member
Corresponding storage.In this way, analog function is transferred to simulation administrative unit after receiving input value, by the input value.Simulation management
Unit is determining with the consistent expectation input value of input value in the expectation input value being arranged for the analog function, and by the determining phase
Hope return value of the corresponding return value of input value as the analog function.
In the present embodiment, when simulating analog function corresponding with objective function, it is really real analog function is not needed
The existing specific algorithmic procedure of objective function, it is only necessary to the desired input of objective function is arranged with return to analog function, namely
It is to say that stencil function and objective function realize same function, can successfully carries out the test of tested code, improve survey
Try efficiency.
In one embodiment, by testing the macro expectation input value and corresponding return value that analog function is arranged, comprising:
Macro, generation Hook Function, setting function and analog function corresponding with objective function are generated by function;It is macro by testing, it adjusts
With the expectation input value and corresponding return value of setting function setup analog function;The test method further include: macro by testing
Call Hook Function that jump instruction corresponding with objective function is set.
Wherein, it is for carrying out the macro of function generation that function, which generates macro,.Function generates macro producible function
The corresponding analog function of scalar functions, Hook Function and setting function.Hook Function, for macro given birth to will to be generated by the same function
At analog function hook the objective function simulated to the analog function, in this way in the target for calling the analog function to be simulated
Function can jump and call the analog function.Function is set, macro simulation letter generated is generated by the same function for being arranged
Several expectation input values and corresponding return value.The function of Hook Function and setting function is realized through test macro-call triggering.
Specifically, it is macro that one or more functions generations are stated in the header file of Embedded test use-case, in compiling to function
When generating macro, macro expansion generates analog function corresponding with objective function, Hook Function and setting function.It is macro to testing compiling
When, macro expansion calls the expectation input value and corresponding return value of setting function setup analog function, and Hook Function is called to set
It sets jump instruction corresponding with objective function, jump instruction corresponding with objective function is set, that is, by objective function Hook
To analog function corresponding to objective function.
For example, function, which generates macro 1, generates analog function 1, Hook Function 1 and setting function 1.So, it is testing
When macro expansion, which is arranged the expectation input value and corresponding return value that analog function 1 is arranged in function 1, and calls
Jump instruction corresponding with objective function 1 is arranged in Hook Function 1, and goal function 1 is the target that analog function 1 is simulated
Function, it is exactly to hook analog function 1 to objective function 1 that jump instruction corresponding with objective function 1, which is arranged,.Generally it is exactly
By objective function 1Hook to analog function 1.
S108 determines the test result of tested code according to return value.
Specifically, based on the return value of analog function, it can determine that analog function whether is transferred in test process is expected
Parameter, and then can determine whether tested code realizes expectation function, whether logic problematic and which kind of problem etc.,
Obtain test result.
Above-mentioned test method, objective function are the functions called required for tested code is realized, are compiling tested generation
It is no longer to call the objective function, but jump to calling when needing invocation target function when test case corresponding to code
Analog function identical with objective function function, the interaction with tested code is simulated by analog function, obtains return value,
The test result of tested code can be determined according to return value.In this way, analog function is not inherited from any class, it can be to calling
The tested code of each class function is tested, and application range has greatly been widened.
In one embodiment, objective function is the member function of class.The test method further include: according to objective function institute
The header file of simulation class is generated in the header file of class;The header file for simulating class is used for Embedded test use-case;Pass through simulation class definition
Macro, the simulation class of class where generating objective function simultaneously generates hook variable;Hook variable is with being used for the function of management simulation function
Location;Macro generation analog function corresponding with objective function and Hook Function are generated by function;Objective function and analog function
Parameter type is identical with number of parameters;Hook Function is used to pass through hook Variable Control in invocation target function by jump instruction
Jump to calling analog function.
Wherein, class is the concept in Object-oriented Programming Design.The essence of class is a kind of data type.The composition of class includes
Data member and member function.Class can specifically include template class and non-template class.The member function of class can be static function,
Generic function, Virtual Function, non-Virtual Function or stencil function etc..
Specifically, whether computer equipment can check the objective function after determining the objective function in tested code
For the member function of class.If objective function is the member function of class, the header file of class where obtaining the objective function, according to
The header file generates the header file of simulation class, and when generating test case, will be in the header file Embedded test use-case that simulate class.
Wherein, when defining multiple classes in the header file of class where objective function, computer equipment can determine the class name of processing (also
It is the class name of class where objective function), only to generate the header file of the simulation class of objective function place class.
For example, the header file of simulation class is " Mockclass.h ", then, then sentence " # is added in test case
Include " Mockclass.h " " can will simulate the header file Embedded test use-case of class.
For example, python script can be performed in computer equipment, XXX.py file is executed.XXX.py file may include by
The header file of the class (class where objective function) of Mock function and the class name (class name of class where objective function) of processing.Wherein,
Header file by the class of Mock function be it is necessary, for generating the header file of corresponding Mock class;The class name of processing is optional
, this parameter is filtered by Mock class (by the class of Mock function).Due to may defining multiple classes in a header file
Name needs to increase if only needing to generate the Mock class of one in header file or certain classes (multiple class name spaces separate)
This parameter.
In a specific embodiment, in the header file of simulation class, class or function are stated using macro.This
Sample produces corresponding code in macro expansion.For example, being generated using function macro using simulation class defmacro statement simulation class
State the objective function of simulation.In this way, simulation class defmacro in macro expansion, that is, produces the simulation class of objective function place class
With hook variable etc.;Function generates macro in macro expansion, i.e., producible analog function corresponding with objective function and Hook Function
Deng.
In the header file for simulating class, for stating that class or the macro of function are that exploitation is good according to demand in advance.For example, mould
Quasi- class defmacro is to need the code generated to extract in instantiation according to simulation class.Developer is macro fixed by these
Justice is directly embedded into test case in header file when needed.For example, these macrodefinitions in mbase.h, are then being tested
#include " mbase.h " sentence is directly used in use-case.
In one embodiment, simulation class defmacro includes the first simulation class defmacro and the second simulation class defmacro;The
One simulation class defmacro is generated according to the common feature of each non-template class, for generating simulation class corresponding to non-template class.The
Two simulation class defmacros are generated according to the common feature of each template class, for generating simulation class corresponding to template class;Second mould
Quasi- class defmacro carries the template parameter quantity of template class.
Wherein, simulation class defmacro is used to generate the constructed fuction and destructor function of simulation class, and for defining simulation class
Static variable and hook class variable.First simulation class defmacro and the second simulation class defmacro are all simulation class defmacros, only
Both be respectively different being modeled is used when class is simulated it is macro.
The static variable of simulation class is used to access the instance objects of Mock class, can be macro by mock by testing in actual code
The pointer of the instance objects of class passes to the static variable of Mock class.It is appreciated that test mentioned above is macro will be simulation letter
The expectation input value and corresponding return value of number setting are transferred to simulation administrative unit to manage.Simulating administrative unit is then basis
The pointer of the instance objects of Mock class determines to be the macro expectation input value for the setting of which Mock class of test and corresponding return
Value is then distinguished by function name and the parameter of function when in Mock class including multiple Mock functions.In this way, in reality
When analog function being called to need to return the result, simulation administrative unit can quickly determine return value.
It include two class Hook functions in hook (Hook) class, it is a kind of by Mock function Hook to Mock function;It is another kind of
Unloading is by the Hook of Mock function.Hook class variable is the instance objects that Hook class example that is to say Hook class, is primarily used to
Management is by the function address etc. of mock function.The code of Hook class, which can be, writes completion in advance, and it is fixed in Mock class to need
Adopted Hook class instance objects.
It is appreciated that since template class includes template parameter, rather than template class does not then include template parameter;So it is used for sound
The simulation class defmacro of the simulation class of bright template class, it is different from for stating the simulation class defmacro of simulation class of non-template class.
The parameter of the two simulation class defmacros is also different.For stating the parameter packet of the simulation class defmacro of the simulation class of template class
It includes: simulating the class name and template parameter of class.For stating that the parameter of the simulation class defmacro of the simulation class of non-template class includes: mould
The class name of quasi- class.
It illustrates, it is assumed that the entitled Mockclass of class for simulating class, for stating that the simulation class of simulation class of template class is fixed
Macro justice is H2MOCK_HEAD%d_T, for stating that the simulation class defmacro of simulation class of non-template class is H2MOCK_HEAD.That
, when Mockclass is the simulation class of template class, then declarative statement is H2MOCK_HEAD2_T (Mockclass, T1, T2);
Wherein, %d=2 is indicated there are two template parameters, respectively T1 and T2.When Mockclass is the simulation class of non-template class, then
Declarative statement is H2MOCK_HEAD (Mockclass).
In the present embodiment, since template class and non-template class have differences, then respectively for template class and non-template class
The respectively corresponding simulation class defmacro of setting, to guarantee the smooth simulation of template class Yu non-template class.
In one embodiment, macro, generation analog function corresponding with objective function and Hook Function are generated by function,
It include: that the corresponding analog function of macro generation generic function and hook are generated by generic function when objective function is generic function
Subfunction;Generic function generates the type function of the macro function name for carrying generic function and generic function;When objective function is quiet
When state function, the corresponding analog function of macro generation static function and Hook Function are generated by static function;Static function generates
The type function of the macro function name for carrying static function and static function.
Wherein, it is for carrying out the macro of analog function generation that function, which generates macro,.Function generation is macro can also to generate hook letter
Number and the setting function that expectation input value and corresponding return value is set for analog function.
It is appreciated that simulation generates analog function corresponding to objective function, complete simulated target function is not needed
Specific calculating process, it is only necessary to the function of simulated target function.It namely needs through setting function setup according to target
The expectation input value and corresponding return value of analog function is arranged in the expectation input value and corresponding return value of function, so that
Analog function is identical as the function of objective function.
In order to keep storehouse to balance, computer equipment needs to keep objective function and target letter in simulated target function
The corresponding analog function of number is consistent in number of parameters and parameter type.In fact, static function compiling when
Time does not transmit this pointer, and generic function can then transmit this pointer in compiling.So, then it needs compiling for function
When whether transmit this pointer be respectively set different function generate it is macro, to guarantee when generating analog function, holding storehouse
Balance.
Wherein, it includes: function name and type function that function, which generates macro parameter,.Generic function generates macro in generation simulation
When function, increase the parameter of a simulation class, that is, this pointer of simulation class.
For example, it is HMOCK_STATIC_METHOD%d that static function, which generates macro, when simulating class is non-template class;
When simulating class is template class, it is HMOCK_STATIC_METHOD%d_T that static function, which generates macro,;When simulation class is non-template
When class, it is HMOCK_GENERAL_METHOD%d that generic function, which generates macro,;When simulating class is template class, generic function is generated
Macro is HMOCK_GENERAL_METHOD%d_T.%d is the number of parameters of function.
Assuming that objective function is int Tclass1 (int T1, int T2), then, when Tclass1 is under non-template class
When static function, then declarative statement is HMOCK_STATIC_METHOD2 (Tclass1, int (int, int));Wherein, %d=2
There are two parameters by representative function Tclass1.When Tclass1 is the static function under template class, then declarative statement is HMOCK_
STATIC_METHOD2_T (Tclass1, int (int, int));Wherein, there are two parameters by %d=2 representative function Tclass1.
When Tclass1 be non-template class under generic function when, then declarative statement be HMOCK_GENERAL_METHOD2 (Tclass1,
Int (int, int));Wherein, there are two parameters by %d=2 representative function Tclass1.When Tclass1 is general under template class
When function, then declarative statement is HMOCK_GENERAL_METHOD2_T (Tclass1, int (int, int));Wherein, %d=2
There are two parameters by representative function Tclass1.
Fig. 3 is the schematic diagram of compiled code in one embodiment.With reference to Fig. 3, which is the volume of generic function
Translate code.Wherein, normalFunc is by mock function, and mockNormalFunc is mock function.From code form, two
The number of parameters of person is inconsistent.But actually normalFunc also delivers 5 parameters, wherein further including an implicit parameter:
This pointer of class.So increasing a parameter by mock class, (t1 is by mock to &t1 in figure generating mock function
The variable of class) it is exactly by this pointer of mock class.The figure lower half portion is the compiled code of static function.Wherein,
StaticFunc is by mock function, and mockStaticFunc is mock function.At this point, actually and in form both 4
A parameter, reason are exactly that static function does not transmit this pointer when compiler compiling.
In the present embodiment, for the difference of generic function and the static function Transfer Parameters in compilation process, difference needle
Corresponding function is respectively set to generic function with static function and generates macro, to guarantee when construct analog function, holding is by mould
The consistency of pseudofunction and analog function in number of parameters.
In above-described embodiment, processing mode when to need the function that is modeled be the member function of class is proposed, to needs
Class where the function being modeled is simulated, and simulation class need not then be inherited from any other class, so as to various for calling
The tested code of type of functions is tested, and has extensive adaptability.
For example, in a specific embodiment, belonging to the definition of simulation class corresponding to the simulation class of non-template class
Macro is H2MOCK_HEAD, and macro parameter is the class name for simulating class;Belong to simulation class defmacro corresponding to the simulation class of template class
For H2MOCK_HEADH2MOCK_HEAD%d_T, wherein %d is template parameter quantity, macro parameter be simulate the class name of class with
Template parameter.When simulating class is non-template class, it is HMOCK_GENERAL_METHOD%d that generic function, which generates macro, wherein %d
For the number of parameters of generic function, macro parameter is the function name and type function of generic function;Static function generation is macro to be
HMOCK_STATIC_METHOD%d, wherein %d is the number of parameters of static function;Macro parameter is the function name of generic function
And type function.When simulating class is template class, it is HMOCK_GENERAL_METHOD%d_T that generic function, which generates macro,
Middle %d is the number of parameters of generic function, and macro parameter is the function name and type function of generic function;Static function generates macro
For HMOCK_STATIC_METHOD%d_T, wherein %d is the number of parameters of static function, and macro parameter is the letter of generic function
Several and type function.Certainly, these specific macro names be used for for example, not in actual use macro name into
Row limits.These are macro for stating in header file class or function.
Fig. 4 shows code comparison's schematic diagram in one embodiment by Mock class and Mock class.With reference to Fig. 4, can see
This is non-template class by Mock class out, and undefined stencil function, then Mock class is also non-template class, then uses H2MOCK_
HEAD is macro, which is the class name HMockTClass of Mock class.Having been given a definition one by Mock class includes 1 parameter
Generic function TClass1 and one include 2 parameters static function TClass2, then use HMOCK_GENERAL_
METHOD%d is macro to state generic function TClass1, and parameter is function name TClass1 and type function string, %d
There is 1 parameter for 1 expression generic function TClass1.Use the macro statement static function of HMOCK_STATIC_METHOD%d
TClass2, parameter is function name TClass2 and type function int, %d are that 2 expression static function TClass2 have 2 ginsengs
Number.It is appreciated that Fig. 4 right half part code is the partial code in Mock class header file.
Fig. 5 shows code comparison's schematic diagram in one embodiment by Mock class and Mock class.With reference to Fig. 5, can see
This is template class by Mock class out, then Mock class is also template class, then macro using H2MOCK_HEAD%d_T, which is
It is 4 expression templates for the class name HMockTClass of Mock class and template parameter T1, T2, T3 and T4 of template class, the macro middle %d
The number of parameter is 4.Given a definition one by Mock class include 3 parameters generic function classTemp1 and one include 4
The static function classTemp2 of a parameter then uses the macro statement generic function of HMOCK_GENERAL_METHOD%d_T
ClassTemp1, parameter is function name classTemp1 and type function string, %d are 3 expression generic functions
ClassTemp1 has 3 parameters.Use the macro statement static function classTemp2 of HMOCK_STATIC_METHOD%d_T, ginseng
Number is function name classTemp2 and type function string, %d are that 4 expression static function classTemp2 have 4 parameters.
In one embodiment, objective function includes stencil function.The generation step of the simulation class of class where stencil function
It include: to classify according to the number of parameters of stencil function to stencil function;Determine the quantity for the class categories that classification obtains;It is right
Each class categories are answered to generate simulation class respectively.
As mentioning in previous embodiment, since template class includes template parameter, non-template class does not include template parameter,
Then template class and non-template class are handled differently.At this point, stencil function includes template parameter, non-template function does not then include
Template parameter then also needs for stencil function and non-template function to be handled differently.Moreover, template included by different stencil functions
The quantity of parameter is different, then, in order to avoid occurring mistake when stencil function is called, then according to the number of parameters of stencil function
Difference, generate multiple simulation classes respectively.
Specifically, computer equipment is then pressed when the objective function for determining that tested code needs to call is stencil function
Classify according to the number of parameters of stencil function to stencil function;Determine the quantity for the class categories that classification obtains;It is corresponding each
Class categories generate simulation class respectively.Wherein, the corresponding class categories of a number of parameters.That is, stencil function
The type of number of parameters is identical as the quantity of simulation class generated, and computer equipment can state one kind in each simulation class respectively
The stencil function of number of parameters.
For example, the quantity of template parameter includes 1 and 2 two kinds of situations, then 2 simulation classes are generated.Wherein one
Statement includes the stencil function (quantity can be multiple) of 1 template parameter in a simulation class, is stated in another simulation class
Stencil function including 2 template parameters (quantity can be multiple).
It is appreciated that the simulation class that the class categories of corresponding each stencil function generate respectively is template class.Wherein, in mould
When class is non-template class where plate function, the template parameter quantity and the template parameter quantity phase of corresponding template function of template class
Together.For example, corresponding includes the simulation class that the stencil function of 1 template parameter generates, it is the template class for including 1 template parameter;
Corresponding includes the simulation class that the stencil function of 2 template parameters generates, and is the template class for including 2 template parameters.In template letter
When class is template class where number, the template parameter quantity of template class is the template parameter quantity and corresponding template of corresponding template function
The sum of the target component quantity of class where function.For example, class where stencil function includes 1 stencil function, then corresponding includes 1
The simulation class that the stencil function of template parameter generates, is the template class for including 2 template parameters;Corresponding includes 2 template parameters
Stencil function generate simulation class, be the template class for including 3 template parameters.
In one embodiment, objective function further includes non-template function.The generation of the simulation class of class where stencil function
Step further include: generate simulation class corresponding with non-template function.
Specifically, since non-template function does not include template parameter, also just there is no divide class by template parameter
Situation not to generate multiple simulation classes.A simulation class can only so be generated for each non-template function, in the simulation class
State each non-template function.
In one embodiment, when class where non-template function is template class, the simulation of corresponding non-template function generation
Class is also template class, and the template parameter quantity for simulating class is the template parameter quantity of class where non-template function.For example, non-template
Class where function includes 1 stencil function, then corresponds to the simulation class of non-template function generation, be the mould for including 1 template parameter
Plate class.
In above-described embodiment, since stencil function and non-template function have differences, joining between different stencil functions
It is had differences in number quantity, then respectively for stencil function and non-template function and the template letter including different parameters quantity
Respectively class is simulated in simulation to number accordingly, avoids the situation for occurring mistake when calling.
Fig. 6 shows code comparison's schematic diagram in one embodiment by Mock class and Mock class.With reference to Fig. 6, can see
Out this by Mock class be non-template class, the template class given a definition one include 1 template parameter general stencil function
FunTemp1 and static template function funTemp2 including 2 template parameters.So then need to generate 2 simulation classes,
And the two simulation classes are template class.HMOCK_GENERAL_ is used in wherein one simulation class HMockfunTemp1
The macro general stencil function funTemp1 of statement of METHOD%d_T, parameter is function name funTemp1 and type function string,
Its %d is that the 1 general stencil function funTemp1 of expression has 1 template parameter.Make in another simulation class HMockfunTemp2
With the macro statement static template function funTemp2 of HMOCK_STATIC_METHOD%d_T, parameter be function name funTemp2 and
Type function string, %d are that 2 expression static template function funTemp2 have 2 template parameters.
Fig. 7 shows code comparison's schematic diagram in one embodiment by Mock class and Mock class.With reference to Fig. 7, can see
Out this by Mock class be template class, the template class given a definition one include 1 parameter generic function ClassFunTemp1,
One generic function ClassFunTemp1 and a general stencil function including 2 template parameters including 2 parameters
ClassFunTemp2.So then need to generate 2 simulation classes, and the two simulation classes are template class.A simulation class wherein
The macro statement generic function ClassFunTemp1 of HMOCK_GENERAL_METHOD%d_T is used in HMockClassFunTemp,
Its parameter is function name ClassFunTemp1 and type function string, %d are 1 expression generic function ClassFunTemp1
There is 1 parameter.It can be seen that realizing function overloading here.ClassFunTemp1 (T p1) and ClassFunTemp1 (T p1,
Int P2), the function name of the two functions is identical, but parameter is different.In another simulation class HMockClassFunTemp2
Using the macro general stencil function ClassFunTemp2 of statement of HMOCK_GENERAL_METHOD%d_T, parameter is function name
ClassFunTemp2 and type function string, %d are that the 3 general stencil function ClassFunTemp2 of expression have 3 templates
Parameter.
In one embodiment, test method further include: pass through the of class where alias definition macro generation objective function
One alias;The macro class name for carrying objective function place class of alias definition;First alias is used to quote when invocation target function;Pass through
Simulation class defines the second alias of macro generation simulation class;Simulate the class name that class defmacro carries simulation class;Second alias is for adjusting
It is quoted when with analog function.
Wherein, the alias of class is the class name in addition defined for class.Specifically, it longer can be not easy to quote in the class name of class
When, it is the less alias of the other definition character of class in order to quoting.For example, the class of class is entitled where objective function
It can in addition be class defalias St when StudentXXXXXXXXxxxxxxx.
In the embodiment of the present application, by macro to be modeled class (objective function where class) and simulate class defalias.And
And it is used respectively when class is template class or non-template class different macro.It, can be exclusively by alias definition for being modeled class
Macro generation alias can then continue to use the simulation class referred in previous embodiment and define macro generation alias for simulating class.
It is non-template class by Mock class referring again to Fig. 4, then macro using H1MOCK_HEAD, which is by Mock
The class name TClass of class.It is template class by Mock class referring again to Fig. 5, then macro using H1MOCK_HEAD%d_T, the macro parameter
It is as 4 expression template parameters by the class name ClassTemp of Mock class and template parameter T1, T2, T3 and T4, the macro middle %d
Number is 4.
In one embodiment, class where objective function is nested class;The generation step of the simulation class of nested class includes: point
Not Sheng Cheng class where nested class and nested class simulation class;Wherein, the class name defmacro institute of the first alias of nested class is generated
The class name of carrying, the class name of class is nested with the class name of nested class where nested class obtains.
Wherein, nested class is nested class in class.Specifically, when handling nested class should by nested class separately as
One class is simulated.When class is nested class where objective function, computer equipment can generate nested class and nested class institute respectively
In the simulation class of class.
Fig. 8 shows code comparison's schematic diagram in one embodiment by Mock class and Mock class.With reference to Fig. 8, can see
It is out nested class by Mock class, class subClass is the nested class of class EmbedClass.Generate class EmbedClass respectively at this time
Simulation class and class subClass simulation class.Declarative statement in the simulation class of class EmbedClass can refer to aforementioned implementation
Macro use in example.In the simulation class of class subClass, when macro using H1MOCK_HEAD, it shall be noted that the macro parameter is
The class name obtained class name nested with the class name of nested class of class where nested class.Other macro uses are see also aforementioned implementation
Example.
In one embodiment, objective function is overall situation function;Method further include: generated according to the header file of objective function
Simulate the header file of class;The header file for simulating class is used for Embedded test use-case;By simulating class defmacro, simulation class and life are generated
At hook variable;Hook variable is used for the function address of management simulation function;Macro, generation and target letter are generated by static function
The corresponding analog function of number and Hook Function;Objective function is identical as the parameter type of analog function and number of parameters;Hook letter
Number, for jumping to calling analog function by jump instruction in invocation target function by hook Variable Control.
Wherein, overall situation function is defined in the function outside class.Specifically, computer equipment is in determining tested code
After objective function, can check the objective function whether overall situation function.If objective function is overall situation function, the overall situation letter is obtained
Several header files generates the header file of simulation class according to the header file, and when generating test case, will simulate the header file of class
In Embedded test use-case.
For example, python script can be performed in computer equipment, XXX.py file is executed.XXX.py file may include by
The header file of overall situation function, for generating the header file of corresponding Mock class.
It is appreciated that although overall situation function is defined in the function outside class, when being simulated to overall situation function,
It is first to generate a simulation class.Class and function are stated in simulation class again.Wherein, the statement of class can refer to class in previous embodiment
Statement.Since overall situation function is not the member function of class, then do not have to consider this pointer, then before the statement of function can refer to
State the function declaration of static function in embodiment.
When overall situation function is non-stencil function, simulation class corresponding to overall situation function is non-template class;Work as overall situation function
When being stencil function, simulation class corresponding to overall situation function is template class;When overall situation function not only included non-template overall situation function but also
When including template overall situation function, simulation class corresponding to overall situation function includes multiple.Wherein, each non-template overall situation function corresponding one
A simulation class, respectively the overall situation function of the template parameter including different number respectively corresponds to a simulation class.
In one embodiment, test method further include: macro fixed in the initial position addition of the simulation class of overall situation function
Justice;Macrodefinition is used to the alias definition of overall situation function be empty default alias;In the end position of the simulation class of overall situation function
Cancel macrodefinition.
It is appreciated that since overall situation function is not the member function of class, then being just then not required to there is no the class being modeled yet
Use be modeled class defalias alias definition it is macro.In this case, can by simulate class starting when macrodefinition it is other
It is macro then to cancel this in simulation class ending again for entitled sky.
Fig. 9 shows code comparison's schematic diagram in one embodiment by Mock class and Mock class.With reference to Fig. 9, hence it is evident that can
It include the overall situation function of non-template, but also the overall situation function including template to find out Fig. 9 left-half not only;So generating simulation class
When, then to overall situation function funWithoutNS1, funWithoutNS2 and funWithoutNS2 (overload function) of non-template,
The unified simulation class HMockFunctionWithoutNS1 for generating a non-template class, in the simulation class of generation
Under HMockFunctionWithoutNS1, macro HMOCK_STATIC_METHOD is generated to 3 non-templates by static function
Overall situation function is stated.To template overall situation function funWithoutNS3, the simulation class an of template class is generated
HMockFunctionWithoutNS2 passes through static function at the simulation class HMockFunctionWithoutNS2 of generation
Macro HMOCK_STATIC_METHOD is generated to state the overall situation function of 1 template.By the overall situation function of Mock due to not being
The member function of class, then not by the class name of Mock class, so it is macro not need alias definition: H1MOCK_HEAD and H1MOCK_
HEAD%d_T.So can be here empty ocName alias by #define ocName macrodefinition alias, then in Mock
It is macro that class ending cancels this by #undefocName again.
In above-described embodiment, processing mode when to need the function that is modeled be overall situation function is proposed, to needing by mould
Quasi- overall situation function creation simulation class, then functional simulation is carried out in simulation class, simulation class need not be inherited from any other class, from
And can be tested for the tested code of overall situation function, there is extensive adaptability.
It is appreciated that provide in the embodiment of the present application 5 groups it is customized macro.This five groups of macro uses can refer to aforementioned reality
Apply the description in example.Fig. 4 is specifically referred to Fig. 9.
First group macro: alias definition is macro, specific such as H1MOCK_HEAD and H1MOCK_HEAD%d_T.The two are macro to be all
For generating by the alias of Mock class.If being non-template class by Mock class, H1MOCK_HEAD is used, H1MOCK_HEAD's
Parameter is by the class name of Mock class;H1MOCK_HEAD%d_T is used if being template class by Mock class, and (wherein %d is template
The number of parameter), the parameter of H1MOCK_HEAD%d_T is by the class name of mock class and template parameter.
Second group macro: simulation class defmacro, specific such as H2MOCK_HEAD and H2MOCK_HEAD%d_T.This 2 macro to be all
For generating the alias of Mock class, generating Mock class constructor and destructor function and defining Mock class static variable, Hook
Class variable and the static example function of Mock class etc..If Mock class is non-template class, H2MOCK_HEAD, H2MOCK_ are used
The parameter of HEAD is the class name of Mock class;If Mock class is template class, using H2MOCK_HEAD%d_T, (wherein %d is
The number of template parameter), the parameter of H2MOCK_HEAD%d_T is the class name and template parameter of Mock class.
Third group is macro: static function generates macro, specific such as HMOCK_STATIC_METHOD%d and HMOCK_STATIC_
METHOD%d_T.This 2 macro Mock the function, (effects: the function mock of generation of Hook function to generate static function
On function hook to the function by mock) and setting Mock function expectation input value and corresponding return value setting function.
If Mock class is non-template class, HMOCK_STATIC_METHOD%d is used;If Mock class is template class, use
HMOCK_STATIC_METHOD%d_T.Wherein, %d is the number of parameters of static parameter, and static function generates macro parameter and is
The function name and type function of static function.
4th group macro: generic function generates macro, specific such as HMOCK_GENERAL_METHOD%d and HMOCK_GENERAL_
METHOD%d_T.This 2 macro Mock the function, (effects: the function mock of generation of Hook function to generate generic function
On function hook to the function by mock) and setting Mock function expectation input value and corresponding return value setting function.
After generic function Hook, in order to keep storehouse to balance, actually Mock function ratio is by one more than Mock function by mock class
This pointer parameter, so here macro also need in macroparameter to parameter reconfigure increase by one by mock class
Parameter, being just able to maintain could keep being balanced by the function storehouse of hook.Specifically use same HMOCK_STATIC_METHOD%d
It is macro with HMOCK_STATIC_METHOD%d_T.
5th group macro: static variable declarations are macro, specific such as HMOCK_TAIL and HMOCK_TAIL%d_T.This 2 macro main
For stating the static variable of a Mock class, this static variable is used to access the instance objects of Mock class.Design parameter makes
With same H2MOCK_HEAD and H2MOCK_HEAD%d_T.
Figure 10 shows the logic diagram of test method in one embodiment.With reference to Figure 10, computer equipment can first basis
User instruction automatically determines tested code, after determining tested code, then according to tested code building for being somebody's turn to do
The test case of tested code.
Computer equipment can position the objective function for needing to call, i.e., when constructing test case in tested code
By Mock function.Here the member function or overall situation function that can be class by Mock function, then computer equipment, that is, root
Mock class header file is generated according to by the header file of Mock class (class where Mock function) or overall situation function, and Embedded test is used
In example.For computer equipment in this way in compiler test use-case, macro in Mock class header file can expand into corresponding code.
Wherein, class can be template class or non-template class, and the member function of class can be static function, generic function, void
Function, non-Virtual Function or stencil function etc..Overall situation function can be stencil function or non-template function.The Mock class of generation
Macro Mock class or Mock function are stated in header file using provided herein.Specifically, in Mock class head text
In part, can be used that alias definition is macro states by Mock class, in macro expansion for by Mock class defalias;It can be used
Simulation class defmacro states Mock class, for Mock class defalias, to define Mock class static variable in macro expansion
With Hook class variable;It function generation is macro can be used to state Mock function, to generate Mock function, Hook in macro expansion
Function and setting function;It can be used that static variable declarations are macro states Mock class static variable, can deposit in macro expansion
Take the instance objects of Mock class.
It should be noted that in Mock class header file to class or function stated used in it is macro, with by Mock class,
Mock class and Mock functional dependence.For example, non-template class and target class, using different macro, static function is adopted with generic function
With different macro, it is specifically used which kind of macro can refer to previous embodiment.
Computer equipment start test i.e. compiler test use-case when, can be used test it is macro by defined in the test case
Mock class variable come call function generate macro generation setting function, to the function generate macro generation Mock function setup it is expected
Input value and corresponding return value, and the expectation input value of Mock function setup and corresponding return value are transferred to simulation management
Unit.Wherein, the pointer of Mock class variable can pass to the Mock class static variable in Mock class, pass through Mock class static variable
Manage Mock class variable, simulation administrative unit, that is, knowable is currently the desired value and expectation for which Mock class setting in this way
Return value.
Computer equipment also generates the Hook function of macro generation using test macro-call function, will generate macro generation by function
Mock function Hook to the Mock function simulated by Mock function.In this way, computer equipment is being called by Mock letter
It is jumped to when number and calls Mock function, and value will be actually entered and be transferred to Mock function, such Mock function will then receive
The value that actually enters be transferred to simulation administrative unit, the expectation that the value of actually entering and front are arranged simulation administrative unit inputs
Value is compared, and is returned as the return value that matched expectation input value is accordingly arranged, computer equipment is to according to the return value
Obtain the test result to code to be tested.
Wherein, the function address of Mock function can be transferred to Hook class variable management, in this way after generation by Mock function
Hook function to by Mock function, i.e., is collected Mock function Hook by the modification of Hook class variable by the starting of Mock function
Code jumps to the function address of Mock function.
It should be understood that although each step in the flow chart of the various embodiments described above is successively shown according to the instruction of arrow
Show, but these steps are not that the inevitable sequence according to arrow instruction successively executes.Unless expressly state otherwise herein, this
There is no stringent sequences to limit for the execution of a little steps, these steps can execute in other order.Moreover, above-mentioned each implementation
At least part step in example may include that perhaps these sub-steps of multiple stages or stage be not necessarily for multiple sub-steps
It is to execute completion in synchronization, but can execute at different times, the execution sequence in these sub-steps or stage
It is not necessarily and successively carries out, but can be at least part wheel of the sub-step or stage of other steps or other steps
Stream alternately executes.
As shown in figure 11, in one embodiment, a kind of test device 1100 is provided.Referring to Fig.1 1, the test device
1100 include: collector 1101, jump module 1102, execution module 1103 and processing module 1104.
Collector 1101, for compiling test case corresponding to tested code;Tested code includes for compiling
The objective function called when translating test case.
Jump module 1102, for when objective function is called, by executing jump instruction corresponding with objective function,
Jump to analog function corresponding with objective function;Objective function is identical as analog function function.
Execution module 1103 obtains the return value of analog function for executing analog function.
Processing module 1104, for determining the test result of tested code according to return value.
In one embodiment, collector 1101 be also used to by test it is macro setting analog function expectation input value and
Corresponding return value;Desired input value and corresponding return value are transferred to simulation administrative unit storage.Execution module 1103 is also
For the input value received to be transferred to simulation administrative unit by analog function;It determines and inputs by simulation administrative unit
It is worth consistent expectation input value, and using the determining corresponding return value of expectation input value as the return value of analog function.
In one embodiment, collector 1101 is also used to generate by function macro, generates Hook Function, setting function
With analog function corresponding with objective function;By test it is macro, call setting function setup analog function expectation input value and
Corresponding return value;By test macro-call Hook Function, jump instruction corresponding with objective function is set.
As shown in figure 12, in one embodiment, objective function is the member function of class.Test device 1100 further include:
Generation module 1105 generates the header file of simulation class for the header file according to class where objective function;Simulate the header file of class
For Embedded test use-case.Collector 1101 is also used to the simulation of class where generating objective function by simulating class defmacro
Class simultaneously generates hook variable;Hook variable is used for the function address of management simulation function;Macro generation and target are generated by function
The corresponding analog function of function and Hook Function;Objective function is identical as the parameter type of analog function and number of parameters;Hook
Function is used to jump to calling analog function by jump instruction in invocation target function by hook Variable Control.
In one embodiment, simulation class defmacro includes the first simulation class defmacro and the second simulation class defmacro;The
One simulation class defmacro is generated according to the common feature of each non-template class, for generating simulation class corresponding to non-template class;The
Two simulation class defmacros are generated according to the common feature of each template class, for generating simulation class corresponding to template class;Second mould
Quasi- class defmacro carries the template parameter quantity of template class.
In one embodiment, collector 1101 is also used to pass through generic function when objective function is generic function
Generate the corresponding analog function of macro generation generic function and Hook Function;Generic function generates the macro function name for carrying generic function
With the type function of generic function;When objective function is static function, macro generation static function pair is generated by static function
The analog function and Hook Function answered;Static function generates the function class of the macro function name for carrying static function and static function
Type.
In one embodiment, objective function includes stencil function.Generation module 1105 is also used to according to stencil function
Number of parameters classifies to stencil function;Determine the quantity for the class categories that classification obtains;Corresponding each class categories difference
Generate simulation class.
In one embodiment, objective function further includes non-template function.Generation module 1105 is also used to generate and non-mould
The corresponding simulation class of plate function.
In one embodiment, collector 1101 is also used to the by class where alias definition macro generation objective function
One alias;The macro class name for carrying objective function place class of alias definition;First alias is used to quote when invocation target function;Pass through
Simulation class defines the second alias of macro generation simulation class;Simulate the class name that class defmacro carries simulation class;Second alias is for adjusting
It is quoted when with analog function.
In one embodiment, class where objective function is nested class.Generation module 1105 is also used to generate nesting respectively
The simulation class of class where class and nested class;Wherein, class name entrained by the class name defmacro of the first alias of nested class is generated,
The class name of class is nested with the class name of nested class where nested class obtains.
In one embodiment, objective function is overall situation function.Generation module 1105 is also used to the head according to objective function
The header file of file generated simulation class;The header file for simulating class is used for Embedded test use-case.Collector 1101 is also used to pass through
Class defmacro is simulated, simulation class is generated and generates hook variable;Hook variable is used for the function address of management simulation function;Pass through
Static function generates macro, generation analog function corresponding with objective function and Hook Function;The ginseng of objective function and analog function
Several classes of types are identical with number of parameters;Hook Function, for passing through hook Variable Control in invocation target function by jump instruction
Jump to calling analog function.
In one embodiment, generation module 1105 is also used to macro fixed in the initial position addition of the simulation class of overall situation function
Justice;Macrodefinition is used to the alias definition of overall situation function be sky;Cancel macrodefinition in the end position of the simulation class of overall situation function.
Figure 13 shows the internal structure chart of computer equipment in one embodiment.As shown in figure 13, the computer equipment
It include processor, memory and the network interface connected by system bus including the computer equipment.Wherein, memory includes
Non-volatile memory medium and built-in storage.The non-volatile memory medium of the computer equipment is stored with operating system, may be used also
It is stored with computer program, when which is executed by processor, processor may make to realize test method.The interior storage
Computer program can also be stored in device, when which is executed by processor, processor may make to execute test method.
It will be understood by those skilled in the art that structure shown in Figure 13, the only frame of part-structure relevant to application scheme
Figure, does not constitute the restriction for the computer equipment being applied thereon to application scheme, specific computer equipment can wrap
It includes than more or fewer components as shown in the figure, perhaps combines certain components or with different component layouts.
In one embodiment, test device provided by the present application can be implemented as a kind of form of computer program, meter
Calculation machine program can be run in computer equipment as shown in fig. 13 that.It can be stored in the memory of computer equipment and form the test
Each program module of device, for example, collector 1101, jump module 1102 shown in Figure 11, execution module 1103 and place
Manage module 1104.It is each that the computer program that each program module is constituted makes processor execute the application described in this specification
Step in the test method of a embodiment.
For example, computer equipment shown in Figure 13 can pass through the collector 1101 in test device as shown in figure 11
Compile test case corresponding to tested code;Tested code includes the target letter for calling when compiler test use-case
Number.Through jump module 1102 when objective function is called, by executing jump instruction corresponding with objective function, jump to
Analog function corresponding with objective function;Objective function is identical as analog function function.Simulation is executed by execution module 1103
Function obtains the return value of analog function.The test result of tested code is determined according to return value by processing module 1104.
In one embodiment, a kind of computer equipment, including memory and processor are provided, memory is stored with meter
Calculation machine program, when computer program is executed by processor, so that the step of processor executes above-mentioned test method.Test side herein
The step of method, can be the step in the test method of above-mentioned each embodiment.
In one embodiment, a kind of computer readable storage medium is provided, computer program, computer journey are stored with
When sequence is executed by processor, so that the step of processor executes above-mentioned test method.The step of test method can be herein
State the step in the test method of each embodiment.
Those of ordinary skill in the art will appreciate that realizing all or part of the process in above-described embodiment method, being can be with
Relevant hardware is instructed to complete by computer program, the program can be stored in a non-volatile computer and can be read
In storage medium, the program is when being executed, it may include such as the process of the embodiment of above-mentioned each method.Wherein, provided herein
Each embodiment used in any reference to memory, storage, database or other media, may each comprise non-volatile
And/or volatile memory.Nonvolatile memory may include that read-only memory (ROM), programming ROM (PROM), electricity can be compiled
Journey ROM (EPROM), electrically erasable ROM (EEPROM) or flash memory.Volatile memory may include random access memory
(RAM) or external cache.By way of illustration and not limitation, RAM is available in many forms, such as static state RAM
(SRAM), dynamic ram (DRAM), synchronous dram (SDRAM), double data rate sdram (DDRSDRAM), enhanced SDRAM
(ESDRAM), synchronization link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) directly RAM (RDRAM), straight
Connect memory bus dynamic ram (DRDRAM) and memory bus dynamic ram (RDRAM) etc..
Each technical characteristic of above embodiments can be combined arbitrarily, for simplicity of description, not to above-described embodiment
In each technical characteristic it is all possible combination be all described, as long as however, the combination of these technical characteristics be not present lance
Shield all should be considered as described in this specification.
The several embodiments of the application above described embodiment only expresses, the description thereof is more specific and detailed, but simultaneously
The limitation to the application the scope of the patents therefore cannot be interpreted as.It should be pointed out that for those of ordinary skill in the art
For, without departing from the concept of this application, various modifications and improvements can be made, these belong to the guarantor of the application
Protect range.Therefore, the scope of protection shall be subject to the appended claims for the application patent.
Claims (15)
1. a kind of test method, comprising:
Compile test case corresponding to tested code;The tune when tested code includes for compiling the test case
Objective function;
When the objective function is called, by executing jump instruction corresponding with the objective function, jump to it is described
The corresponding analog function of objective function;The objective function is identical as the analog function function;
The analog function is executed, the return value of the analog function is obtained;
The test result of the tested code is determined according to the return value.
2. the method according to claim 1, wherein the method also includes:
By the expectation input value and corresponding return value of testing the macro setting analog function;
The expectation input value and corresponding return value are transferred to simulation administrative unit storage;
The analog function is executed, the return value of the analog function is obtained, comprising:
The input value received is transferred to simulation administrative unit by the analog function;
It is determining with the consistent expectation input value of the input value and the determining expectation is defeated by the simulation administrative unit
Enter the return value for being worth corresponding return value as the analog function.
3. according to the method described in claim 2, it is characterized in that, the expectation by testing the macro setting objective function
Input value and corresponding return value, comprising:
Macro, generation Hook Function, setting function and analog function corresponding with the objective function are generated by function;
It is macro by testing, call the expectation input value and corresponding return value of analog function described in the setting function setup;
The method also includes:
By Hook Function described in the test macro-call, jump instruction corresponding with the objective function is set.
4. the method according to claim 1, wherein the objective function is the member function of class;The method
Further include:
The header file of simulation class is generated according to the header file of class where the objective function;The header file of the simulation class is for embedding
Enter the test case;
By simulating class defmacro, the simulation class of class where generating the objective function simultaneously generates hook variable;The hook becomes
Amount is used for the function address of management simulation function;
Macro generation analog function corresponding with the objective function and Hook Function are generated by function;The objective function and institute
The parameter type for stating analog function is identical with number of parameters;The Hook Function by the hook Variable Control for being called
It is jumped to when the objective function by jump instruction and calls the analog function.
5. according to the method described in claim 4, it is characterized in that, the simulation class defmacro includes the first simulation class defmacro
With the second simulation class defmacro;The first simulation class defmacro is generated according to the common feature of each non-template class, for generating
Simulation class corresponding to non-template class;The second simulation class defmacro is generated according to the common feature of each template class, for giving birth to
At simulation class corresponding to template class;The second simulation class defmacro carries the template parameter quantity of template class.
6. according to the method described in claim 4, it is characterized in that, described generate macro, generation and the target letter by function
The corresponding analog function of number and Hook Function, comprising:
When the objective function is generic function, the corresponding simulation letter of generic function described in macro generation is generated by generic function
Several and Hook Function;The generic function generates the function class of the macro function name for carrying the generic function and the generic function
Type;
When the objective function is static function, the corresponding simulation letter of static function described in macro generation is generated by static function
Several and Hook Function;The static function generates the function class of the macro function name for carrying the static function and the static function
Type.
7. according to the method described in claim 4, it is characterized in that, the objective function includes stencil function;The template letter
The generation step of the simulation class of class includes: where number
Classify according to the number of parameters of the stencil function to the stencil function;
Determine the quantity for the class categories that classification obtains;
Corresponding each class categories generate simulation class respectively.
8. according to the method described in claim 7, the objective function further includes non-template function;Class where the stencil function
Simulation class generation step further include:
Generate simulation class corresponding with the non-template function.
9. the method according to any one of claim 4-7, which is characterized in that the method also includes:
Pass through the first alias of class where objective function described in alias definition macro generation;The alias definition is macro to carry the target
The class name of class where function;First alias is used to quote when invocation target function;
The second alias that class is simulated described in macro generation is defined by the simulation class;The simulation class defmacro carries the simulation
The class name of class;Second alias is for reference when calling analog function.
10. according to the method described in claim 9, it is characterized in that, class where the objective function is nested class;The nesting
The generation step of the simulation class of class includes:
The simulation class of class where generating the nested class and the nested class respectively;
Wherein, class name entrained by the class name defmacro of the first alias of the nested class is generated, where the nested class
The class name of class is nested with the class name of the nested class to be obtained.
11. the method according to claim 1, wherein the objective function is overall situation function;The method is also wrapped
It includes:
The header file of simulation class is generated according to the header file of the objective function;The header file of the simulation class is described for being embedded in
Test case;
By simulating class defmacro, generating the simulation class and generating hook variable;The hook variable is used for management simulation letter
Several function addresses;
Macro, generation analog function corresponding with the objective function and Hook Function are generated by static function;The target letter
Number is identical as the parameter type of the analog function and number of parameters;The Hook Function, for passing through the hook variable control
System is jumped to by jump instruction when calling the objective function and calls the analog function.
12. according to the method described in claim 9, it is characterized in that, the method also includes:
Macrodefinition is added in the initial position of the simulation class of the overall situation function;The macrodefinition is used for the overall situation function
Alias definition is empty default alias;
Cancel the macrodefinition in the end position of the simulation class of the overall situation function.
13. a kind of test device, comprising:
Collector, for compiling test case corresponding to tested code;The tested code includes for compiling
The objective function called when stating test case;
Jump module is used for when the objective function is called, by executing jump instruction corresponding with the objective function,
Jump to analog function corresponding with the objective function;The objective function is identical as the analog function function;
Execution module obtains the return value of the analog function for executing the analog function;
Processing module, for determining the test result of the tested code according to the return value.
14. a kind of computer readable storage medium is stored with computer program, when the computer program is executed by processor,
So that the processor is executed such as the step of any one of claims 1 to 12 the method.
15. a kind of computer equipment, including memory and processor, the memory is stored with computer program, the calculating
When machine program is executed by the processor, so that the processor is executed such as any one of claims 1 to 12 the method
Step.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811117059.3A CN109359036A (en) | 2018-09-25 | 2018-09-25 | Test method, device, computer readable storage medium and computer equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811117059.3A CN109359036A (en) | 2018-09-25 | 2018-09-25 | Test method, device, computer readable storage medium and computer equipment |
Publications (1)
Publication Number | Publication Date |
---|---|
CN109359036A true CN109359036A (en) | 2019-02-19 |
Family
ID=65351512
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201811117059.3A Pending CN109359036A (en) | 2018-09-25 | 2018-09-25 | Test method, device, computer readable storage medium and computer equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN109359036A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110414090A (en) * | 2019-07-10 | 2019-11-05 | 一汽解放汽车有限公司 | A kind of diesel vehicle preprocessor designs and develops Multipurpose Optimal Method |
CN111552478A (en) * | 2020-04-30 | 2020-08-18 | 上海商汤智能科技有限公司 | Apparatus, method and storage medium for generating CUDA program |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106055481A (en) * | 2016-06-02 | 2016-10-26 | 腾讯科技(深圳)有限公司 | Computer program test method and device |
CN106294106A (en) * | 2015-05-27 | 2017-01-04 | 航天信息股份有限公司 | The method of testing of Web application system and device |
CN106776313A (en) * | 2016-12-13 | 2017-05-31 | 广州唯品会信息科技有限公司 | A kind of method of analog service, device and centralized management platform |
CN106933732A (en) * | 2015-12-30 | 2017-07-07 | 航天信息股份有限公司 | Method for testing software and system |
WO2017130087A1 (en) * | 2016-01-25 | 2017-08-03 | Typemock Ltd. | Methods and systems for isolating software components |
CN107423225A (en) * | 2017-08-10 | 2017-12-01 | 中国民航信息网络股份有限公司 | Mock method and device is carried out to C++ unit testings |
-
2018
- 2018-09-25 CN CN201811117059.3A patent/CN109359036A/en active Pending
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106294106A (en) * | 2015-05-27 | 2017-01-04 | 航天信息股份有限公司 | The method of testing of Web application system and device |
CN106933732A (en) * | 2015-12-30 | 2017-07-07 | 航天信息股份有限公司 | Method for testing software and system |
WO2017130087A1 (en) * | 2016-01-25 | 2017-08-03 | Typemock Ltd. | Methods and systems for isolating software components |
CN106055481A (en) * | 2016-06-02 | 2016-10-26 | 腾讯科技(深圳)有限公司 | Computer program test method and device |
CN106776313A (en) * | 2016-12-13 | 2017-05-31 | 广州唯品会信息科技有限公司 | A kind of method of analog service, device and centralized management platform |
CN107423225A (en) * | 2017-08-10 | 2017-12-01 | 中国民航信息网络股份有限公司 | Mock method and device is carried out to C++ unit testings |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110414090A (en) * | 2019-07-10 | 2019-11-05 | 一汽解放汽车有限公司 | A kind of diesel vehicle preprocessor designs and develops Multipurpose Optimal Method |
CN110414090B (en) * | 2019-07-10 | 2023-04-14 | 一汽解放汽车有限公司 | Multi-objective optimization method for design and development of diesel vehicle post-processor |
CN111552478A (en) * | 2020-04-30 | 2020-08-18 | 上海商汤智能科技有限公司 | Apparatus, method and storage medium for generating CUDA program |
CN111552478B (en) * | 2020-04-30 | 2024-03-22 | 上海商汤智能科技有限公司 | Apparatus, method and storage medium for generating CUDA program |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
Zhao | Data-flow-based unit testing of aspect-oriented programs | |
US20050256665A1 (en) | System and method for model based system testing of interactive applications | |
EP1089172A2 (en) | Compiler and method for compiling specification language into implementation language | |
Gilles et al. | Expressing and enforcing user-defined constraints of AADL models | |
US5974255A (en) | Method for state-based oriented testing | |
US10514898B2 (en) | Method and system to develop, deploy, test, and manage platform-independent software | |
JP7315786B2 (en) | Smart contract client program generation method, system, device, and medium | |
US9727446B2 (en) | Modifiers that customize presentation of tested values to constraints | |
JP2015146179A (en) | Generation for test double | |
CN109359036A (en) | Test method, device, computer readable storage medium and computer equipment | |
CN114327476A (en) | Chip design file generation method and device and chip design method and device | |
Ghorbani et al. | Detection and repair of architectural inconsistencies in java | |
Engels et al. | Model-based verification and validation of properties | |
Cottenier et al. | Modeling aspect-oriented compositions | |
Selim et al. | Automated verification of model transformations in the automotive industry | |
CN110347588B (en) | Software verification method, device, computer equipment and storage medium | |
Zhang et al. | Automated unit testing intelligent agents in PDT | |
Di Natale et al. | A Model-based approach for the synthesis of software to firmware adapters for use with automatically generated components | |
Boucher et al. | Transforming workflow models into automated end-to-end acceptance test cases | |
Lai et al. | Defining and verifying behaviour of domain specific language with fUML | |
Ahmed et al. | Symbolic execution based verification of compliance with the ISO 26262 functional safety standard | |
Greci et al. | A framework for contract-policy matching based on symbolic simulations for securing mobile device application | |
Potuzak et al. | Interface-based semi-automated testing of software components | |
Ratiu et al. | Increasing usability of spin-based C code verification using a harness definition language: Leveraging model-driven code checking to practitioners | |
Bachelet et al. | Designing expression templates with concepts |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
RJ01 | Rejection of invention patent application after publication | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20190219 |