Visual Studio 单元测试之四---Generic测试
这里的Generic我觉得理解为外部测试更合适。因为在这种测试模式下Visual Studio只是启动一个外部的程序,然后通过返回值(0:Passed,其他值:failed)来判断运行结果。
到目前为止,我还没有想到它的具体用途,可能微软就是为了兼容其他测试工具吧。比如把NUint作为外部程序来调用,让它跑一些测试用例。
创建Generic测试:
Add->Generic Test如下图:在第一个输入框中写入要运行的外部程序路径.
<!--[if gte vml 1]><v:shapetype
id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t"
path="[email protected]@[email protected]@[email protected]@[email protected]@5xe" filled="f" stroked="f">
<v:stroke joinstyle="miter" />
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0" />
<v:f eqn="sum @0 1 0" />
<v:f eqn="sum 0 0 @1" />
<v:f eqn="prod @2 1 2" />
<v:f eqn="prod @3 21600 pixelWidth" />
<v:f eqn="prod @3 21600 pixelHeight" />
<v:f eqn="sum @0 0 1" />
<v:f eqn="prod @6 1 2" />
<v:f eqn="prod @7 21600 pixelWidth" />
<v:f eqn="sum @8 21600 0" />
<v:f eqn="prod @7 21600 pixelHeight" />
<v:f eqn="sum @10 21600 0" />
</v:formulas>
<v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect" />
<o:lock v:ext="edit" aspectratio="t" />
</v:shapetype><v:shape id="Picture_x0020_34" o:spid="_x0000_i1026" type="#_x0000_t75"
alt="41.JPG" style='width:6in;height:201pt;visibility:visible;
mso-wrap-style:square'>
<v:imagedata src="file:///C:\DOCUME~1\victorg\LOCALS~1\Temp\msohtmlclip1\01\clip_image001.jpg" mce_src="file:///C:\DOCUME~1\victorg\LOCALS~1\Temp\msohtmlclip1\01\clip_image001.jpg"
o:title="41" />
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
其他选项,比如命令行参数等,可以根据具体情况增加。
这时在Test List Editor窗口就可以看到刚才新建的Generic测试。
<!--[if gte vml 1]><v:shape
id="Picture_x0020_35" o:spid="_x0000_i1025" type="#_x0000_t75" alt="42.JPG"
style='width:377.25pt;height:106.5pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\DOCUME~1\victorg\LOCALS~1\Temp\msohtmlclip1\01\clip_image003.jpg" mce_src="file:///C:\DOCUME~1\victorg\LOCALS~1\Temp\msohtmlclip1\01\clip_image003.jpg"
o:title="42" />
</v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
大家可以自行运行查看结果。
此至Generic Test已经完成了。我想说的是,Generic Test其实并不难,难的是什么时候用。我设想了一种情况:在一个大项目中,以前一直是用其他测试工具进行测试(如NUnit),而且具有大量的测试用例,现在改用VS的test,不可能把以前的用例全部迁移过来,也就是说存在两个测试工具要一起用的情况。在这种情况下,Generic Test的优势就体现出来了。如上图,我们可以把Generic和其他测试一起运行或把它们组合成顺序测试等。
如需转载,请注明本文原创自灰太狼的博客:http://blog.****.net/tjvictor