How to gen stubs:
Usually, all external functions/methods which are used in SUT(software under test) will be automatically generated to stubs by Cantata.
If not, you can manually do:
1. In the tab "Call Interface Control" of Test Script Manager > click Add... > Choose the functions/methods and make sure their control status is "Stub" > Finish
Remember save the Test Script Manager before switch to test script.
OR
2. You can define directly the stubs in test script as template below:
With:
REGISTER_CALL("function_ident") : Registers the execution of the function identified by function_ident.
IF_INSTANCE("instance"){} : separate to many behaviors as our expectation.
LOG_SCRIPT_ERROR("Call instance not defined.") : log script error if your controlling stub is wrong.
How to test stubs:
In test case, put "Call SUT" into the EXPECTED_CALLS() / EXPECT_CALL() / EXPECT_CALL_DEFAULT() ... END_CALLS() block.
With:
EXPECTED_CALLS(const char* sequence):
Specifies the expected call sequence ("function_ident#instance").
Example:
EXPECT_CALL(const char* function, const char* call_number, const char* instance):
Specifies the instance to use when the given function is called the given number of times.
Example:
EXPECT_CALL_DEFAULT(const char* function, const char* instance):
This directive is purely a convenience directive. It has no built-in functionality of its own and maps directly to EXPECT_CALL(function, "others", instance);
Notes:
- The REGISTER_CALL() must be called in EXPECTED_CALLS()/EXPECT_CALL()/EXPECT_CALL_DEFAULT() ... END_CALLS() block, if not the "Script Error: reg_callfunc() called outside call sequence check block" shall be logged.
- The EXPECTED_CALLS()/EXPECT_CALL()/EXPECT_CALL_DEFAULT() ... END_CALLS() block must be implemented in START_TEST()...END_TEST() block.
- The EXPECTED_CALLS() must be NOT implemented in EXPECT_CALL()/EXPECT_CALL_DEFAULT() ... END_CALLS() block and otherwise.
- The number of calling stub will be depended on the number of "call SUT" in EXPECTED_CALLS()/EXPECT_CALL()/EXPECT_CALL_DEFAULT() ... END_CALLS() block.
- If you separate to many EXPECTED_CALLS()/EXPECT_CALL()/EXPECT_CALL_DEFAULT() ... END_CALLS() blocks in one test case, it is OK for testing and generating ctr file (this way makes to easier check stub and read result in ctr file). BUT when export the report, you can be facing with the issue about ctg file and the report shall have only one the code coverage part. (unknown)
- Check EXPECT_CALL_DEFAULT() but related stubs are not called, the result is still pass.
- The functions which only have declaration in SUT and have been not used by SUT will be automatically defined by Dependency Resolver. If it is called by test case, the script error shall be logged.
- ...