Visual Studio Team System 对Unmanaged code 的Code Coverage支持

要利用VS进行Code Coverage,你必须安装VSTS版本,找到VSTS安装目录Microsoft Visual Studio 8/Team Tools/Performance Tools,将这个目录加到你的环境变量PATH里。

第一步,进行Code Coverage,首先要instrument你的native binary文件。

vsintr -coverage target.exe

运行之后,该命令将会在目标binary文件中加入一些instrumentation代码用来收集运行信息。

第二步,然后启动coverage monitor来收集信息,并将输出结果到一个文件。

start vsperfmon -coverage -output:mytestrun.coverage

接下来,你可以运行你的程序代码或测试代码,并且运行结束后,你得告诉monitor你运行或测试结束,运行命令:

vsperfcmd -shutdown

这个命令将会等到目标进程结束,这时将有一个.coverage文件产生,如果用VS打开这个文件,你将会看到一个code coverage result窗口,里面有你刚才运行的结果。

现在我们简单结合Unit Test一个例子说明,在这里使用CxxTest测试框架,有关CxxTest测试框架,可以访问http://cxxtest.sourceforge.net/

以下为UnitTest的Makefile文件:

TESTS = ./*.

PERL
=
perl 

#
 Where the CxxTest distribution is unpacked 

CXXTESTDIR 
= 
cxxtestinstallpath 

#
 Check CXXTESTDIR 

!
if !exist($(CXXTESTDIR)cxxtestgen.pl)
 

!error Please fix CXXTESTDIR 

!endif 

!include 
<win32.mak>
 

#
 cxxtestgen needs Perl or Python 

!
if defined(PERL)
 

CXXTESTGEN 
= $(PERL) $(CXXTESTDIR)/cxxtestgen.
pl 

!elseif defined
(PYTHON)
 

CXXTESTGEN 
= $(PYTHON) $(CXXTESTDIR)/cxxtestgen.
py 

!
else
 

!error You must define PERL or PYTHON 

!endif 

all: runner
.cpp runner.obj runner.exe binplace run
 

#
 The arguments to pass to cxxtestgen 

#
 - ParenPrinter is the way MSVC likes its compilation errors 

# - --have-eh/--abort-on-fail are nice when
 you have them 

#CXXTESTGEN_FLAGS = --gui=Win32Gui --runner=ParenPrinter --have-eh --abort-on
-fail 

CXXTESTGEN_FLAGS 
= --runner=ParenPrinter --have-eh --abort-on
-fail 

# How to generate the test runner, "runner.cpp"
 

runner
.cpp: $(TESTS)
 

$(CXXTESTGEN) $(CXXTESTGEN_FLAGS) -o $$(TESTS)
 

runner
.obj: runner.
cpp 

$(CC) -EHsc $(cdebug) $(cflags) $(cvars) runner.
cpp 

runner
.exe: runner.
obj 

$(link) $(ldebug) $(conflags) $*.obj target.lib /out:runner.
exe 


binplace: runner
.
exe 

xcopy *.dll . //



# Command
-line arguments to the runner 

RUNNER_FLAGS 
= -title "CxxTest Runner"
 

# How to run the tests, which should be in runner.
exe 

run
: binplace 

set PATH="
C:/Program Files/Microsoft Visual Studio 8/Team Tools/Performance Tools";PATH 

vsinstr.exe -coverage target.dll 

start vsperfmon.exe -coverage -output:runner.coverage 

runner.exe $(RUNNER_FLAGS) 

vsperfcmd.exe -shutdown 

clean: 

del runner.* 

del *.dll

这样我们在每次build时候就能知道自己Unit Test的Code Coverage结果。

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值