- 🍅 我是蚂蚁小兵,专注于车载诊断领域,尤其擅长于对CANoe工具的使用
 - 🍅 寻找组织 ,答疑解惑,摸鱼聊天,博客源码,点击加入👉【相亲相爱一家人】
 - 🍅 玩转CANoe,博客目录大全,点击跳转👉
 
📘前言
-  
🍅 在做测试用例开发的时候,我们可能期望在执行测试用例之前,做一些变量初始化,复制,文本处理等前瞻性工作,
 -  
🍅 有些小伙伴可能想通过
on start和on prestart实现,但这是不理智的,在test unitsandtest modules中on start是不可用的,而on prestart初始化变量等是不可靠的。 -  
🍅 所以如果是
XML test modules类型的测试用例,想要完成初始化的一些工作,使用XML调用CAPL Test Function是一个不错的选择 
CANoe中XML编程常用语法
- 📘前言
 - 🌎CAPL Test Function
 - 🌎测试用例1(preparation标签下的无参数调用)
 - 🌎测试用例2(testcase标签下的带参数调用)
 - 🌎测试用例3(completion标签下的带参数调用)
 - 🌎总结
 
🌎CAPL Test Function
下图是Call CAPL Test Function的Help解释:
- 1,
XML test module中的XML文件可以调用CAPL中的Test Function,且只能被XML调用。 - 2,调用capl中的
testfunction用capltestfunction标签,且该标签无法独立使用,需被 或 或 标签包含使用。
3,以最简单的例子<capltestfunction name="test_01" title="call test function : test_01"></capltestfunction> - name的值必须和CAPL中的testfunction 一致。
 - title 的值可以任意填写
4,testfunction 的函数是没有返回值的。
5,capltestfunction是可以传参调用的,支持的参数有:float|int|string|signal|envvar|sysvar 

🌎测试用例1(preparation标签下的无参数调用)
- 1️⃣ 如下图的CAPL界面,创建了一个testfunction test_01()
 

- 2️⃣ 创建的xml文件如下图,通过 
capltestfunction标签调用 capl脚本中创建的test_01()函数 

<testmodule title="XML Test Module" version="1.1">
  <description>XML Test Module</description>
  <preparation>
    <initialize title="Initialize test module" wait="200">
      <!-- <envvar name="">1</envvar> -->
    </initialize>
	<capltestfunction name="test_01" title="call test function : test_01"></capltestfunction>
  </preparation>
  <testgroup title="UDS">			
	<capltestcase name="TC_0001" />
	</testgroup>
  <completion>
    <initialize title="Adding testreport info" wait="500">
      <!-- <envvar name="">0</envvar> -->
    </initialize>
  </completion>
</testmodule>
 
- 2️⃣ 例如,新建一个xml文件,命名为test.xml ,写入如下代码,新建一个XML Test Modele 节点,测试下,观察测试报告的输出
 
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<testmodule title="testmodel_tag" version="1.13"></testmodule>
 
- 3️⃣ 根据输出报告可以看出 title=“testmodel_tag” ,输出的报告名字就是testmodel_tag
 

- 3️⃣ 创建的
Test Module测试节点。然后执行测试,根据结果可以看到XML成功调用了函数test_01


 
🌎测试用例2(testcase标签下的带参数调用)
- 1️⃣ 如下图的CAPL界面,创建了一个
testfunctiontest_02(int s)

 
- 2️⃣通过 
testcase标签调用 capl脚本中创建的test_02()函数 
<testmodule title="XML Test Module" version="1.1">
  <description>XML Test Module</description>
  <preparation>
    <initialize title="Initialize test module" wait="200">
      <!-- <envvar name="">1</envvar> -->
    </initialize>
	<capltestfunction name="test_01" title="preparation标签下的无参数调用"></capltestfunction>
  </preparation>
  <testgroup title="UDS">			
	<capltestcase name="TC_0001" />
	
	<testcase title="TC_0002" ident="TC_0002">	
		  <capltestfunction name="test_02" title="testcase标签下的带参数调用">
				<caplparam name="para1" type="int">0x01</caplparam>
		  </capltestfunction>
		  				 
	</testcase>
	
	</testgroup>
  <completion>
    <initialize title="Adding testreport info" wait="500">
      <!-- <envvar name="">0</envvar> -->
    </initialize>
  </completion>
</testmodule>
 
- 3️⃣ 输出结果,根据结果可以看到
XML成功调用了函数test_02

 
🌎测试用例3(completion标签下的带参数调用)
- 1️⃣ 如下图的CAPL界面,创建了一个
testfunctiontest_03(char s[]) 
/*@!Encoding:936*/
testfunction test_01()
{
  write("***************XML调用了 testfunction test_01***************");
}
testfunction test_02(int s)
{
  write("***************XML调用了 testfunction test_02 ,接收参数:%d***************",s);
}
testfunction test_03(char s[])
{
  write("***************XML调用了 testfunction test_03 ,接收参数:%s***************",s);
}
testcase TC_0001()
{
  
}
 
- 2️⃣通过 
completion标签调用 capl脚本中创建的test_03()函数 
<testmodule title="XML Test Module" version="1.1">
  <description>XML Test Module</description>
  <preparation>
	<capltestfunction name="test_01" title="preparation标签下的无参数调用"></capltestfunction>
  </preparation>
  <testgroup title="UDS">			
	<capltestcase name="TC_0001" />
	
	<testcase title="TC_0002" ident="TC_0002">	
		  <capltestfunction name="test_02" title="testcase标签下的带参数调用">
				<caplparam name="para1" type="int">0x01</caplparam>
		  </capltestfunction>
		  				 
	</testcase>
	
	</testgroup>
  <completion>
	  <capltestfunction name="test_03" title="completion标签下的带参数调用">
			<caplparam name="para1" type="string">hello</caplparam>
	  </capltestfunction>
  </completion>
</testmodule>
 
- 3️⃣ 输出结果,根据结果可以看到
XML成功调用了函数test_03

 
🌎总结


- 🚩要有最朴素的生活,最遥远的梦想,即使明天天寒地冻,路遥马亡!
 
- 🚩如果这篇博客对你有帮助,请 “点赞” “评论”“收藏”一键三连 哦!码字不易,大家的支持就是我坚持下去的动力。
 



















