代码测试环境:
电脑系统:win11 x64
CANoe版本:CANoe 12.0 SP5
官方解释
关于这两个函数,官方解释如下:
Syntax | TestCaseDescription (char description[]); | |||
---|---|---|---|---|
Function | With this function, a description test for a test case can be written into the report. The function can be called several times in a row, the transmitted texts are then added to one another without additional separation. The function may only be called within a test case and relates then to the respective test case. To obtain line breaks (in form of <br /> tags) in the test report, "\n" may be inserted at any place. | |||
Parameters | Description test for the test case. | |||
Return Values | — | |||
Availability | Since Version | Restricted To | Measurement Setup | Simulation / Test Setup |
5.0 | Test nodes | — | • |
这里说明了TestCaseDescription()这个函数将生成一段描述文字到测试报告中,而且这个函数在一行中可以被多次调用,且不会自动换行,除非你主动加了"\n"这个换行符。
Syntax | TestCaseComment (char aComment[]); | |||
---|---|---|---|---|
TestCaseComment (char aComment[], message aMsg); | ||||
TestCaseComment (char aComment[], mostMessage aMsg); | ||||
TestCaseComment (char aComment[], mostAmsMessage aMsg); | ||||
TestCaseComment (char aComment[], mostRawMessage aMsg); | ||||
TestCaseComment (char aComment[], linFrame aMsg); | ||||
TestCaseComment (char aComment[], char aRawString[]); | ||||
TestCaseComment (char aComment[], gmLanMsg aMsg); | ||||
Function | With this function within a test case a commentary can be taken over into the report. This comment can relate to a message that can also be output in the report. The verdict of the test case is not be influenced. | |||
Parameters | aComment Commentary to be taken over into the report. | |||
aMsg CAN-, GMLAN-, LIN-, MOST-, MOST-AMS- or MOST system message to be taken over into the report. | ||||
aRawString Here you may enter any ASCII characters. They will be added to the comment in the following way: <Hex value of the given character>(<ASCII display of the given charcter>). In ASCII display special characters will be replaced by '.'. | ||||
Return Values | — | |||
Availability | Since Version | Restricted To | Measurement Setup | Simulation / Test Setup |
5.0 | Test nodes | — | • |
这里说明了testCaseComment()这个函数可以给测试用例写注释,并且把注释生成到测试报告中。这个注释还可以和报文关联,将报文信息一起输出到报告中,但不影响测试用例的判断结果。
从以上描述中,我们可以看出,这俩函数都是在测试报告中写一段注释,不同之处是,testCaseComment()这个函数功能似乎更加多一点。其实实际用起来,你会发现二者的区别还是很大的。
生成的位置不同
TestCaseDescription():无论该函数在何处调用,注释内容都只会生成到每个测试用例的顶端
testCaseComment():函数在测试脚本中何处调用,相应的注释生成到测试报告对应的位置。
用例代码
testcase TC_BT_2(char case_num[])
{
char print_temp[100];
TestCaseTitle("TC_0", "这里是TestCaseTitle生成的注释内容");
TestStep("TS_1","testCaseComment");
snprintf(print_temp,elcount(print_temp),"这里是testCaseComment生成的注释内容:%s",case_num);
testCaseComment(print_temp);
TestStep("TS_2","TestCaseDescription");
snprintf(print_temp,elcount(print_temp),"这里是TestCaseDescription生成的注释内容:%s",case_num);
TestCaseDescription(print_temp);
}
报告结果
从报告中可以看到,TestCaseDescription()函数虽然在TS_2下面调用,但其注释内容依然生成在测试报告的顶端。
换行逻辑不同
TestCaseDescription():无论该函数在何处调用,被调用了多少次,只要描述字符串中不包含"\n"换行符,就不会换行
testCaseComment():每调用一次就会生成新的一行注释,"\n"换行符也适用该函数
用例代码
testcase TC_BT_2(char case_num[])
{
char print_temp[100];
TestCaseTitle("TC_0", "这里是TestCaseTitle生成的注释内容");
TestStep("TS_1","testCaseComment");
snprintf(print_temp,elcount(print_temp),"这里是testCaseComment生成的注释内容:%s",case_num);
testCaseComment(print_temp);
testCaseComment(print_temp);
testCaseComment(print_temp);
TestStep("TS_2","TestCaseDescription");
snprintf(print_temp,elcount(print_temp),"这里是TestCaseDescription生成的注释内容:%s",case_num);
TestCaseDescription(print_temp);
TestCaseDescription(print_temp);
TestCaseDescription(print_temp);
TestStep("TS_2","TestCaseDescription testCaseComment交叉使用");
snprintf(print_temp,elcount(print_temp),"!!!!!!开始换行\n换行完成!!!!!!");
testCaseComment(print_temp);
TestCaseDescription(print_temp);
}
报告结果
其实,我特别希望testCaseComment()这个函数也拥有这个不主动换行的功能,这样byte信息拼接生成到报告就方便多了。
注释内容有区别
TestCaseDescription():只支持字符串类注释说明
testCaseComment():除了字符串类注释说明,还可以把报文信息也生成到报告中
用例代码
testcase TC_BT_2(char case_num[])
{
char print_temp[100];
message 0x101 testmsg1;
message 0x102 testmsg2;
TestCaseTitle("TC_0", "这里是TestCaseTitle生成的注释内容");
TestStep("TS_1","testCaseComment");
snprintf(print_temp,elcount(print_temp),"testmsg1注释信息生成如下:");
testCaseComment(print_temp,testmsg1);
testmsg2.dlc = 5;
testmsg2.byte(0) = 0xFF;
snprintf(print_temp,elcount(print_temp),"testmsg2注释信息生成如下:");
testCaseComment(print_temp,testmsg2);
}
报告结果
其实,经过验证,testCaseComment()只支持用例用定义的message的信息显示,不支持直接调用DBC里报文信息。基于这个逻辑,好像不能直接把接收到的报文信息传递到报告中去,当然是可以曲线救国的。
使用场景总结
1、TestCaseDescription()函数是对整个测试用例的描述,虽然可以在脚本的任何位置调用,但生成的描述只会出现在报告的头部。
2、testCaseComment()函数可以对每个测试步骤进行描述,随着调用位置的不同,会在报告的相应位置生成描述文字,同时,该函数支持将报文信息写入到报告相应位置。
以上为个人见解,欢迎讨论指正。