为C#编写Coverage工具 [英] Writing a Coverage Tool for C#

查看:98
本文介绍了为C#编写Coverage工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自Rational的纯粹覆盖是我能够找到C#的唯一覆盖工具,而且我真的不想支付Rational收费

表示像覆盖工具一样简单的东西。所以,我想尝试自己编写
,但是我很难入门。我看待

的方式,我需要做以下几点?


1)创建一个调试器对象或类似的东西,这将允许我

单步执行我的代码。


2)启动一个程序来运行我的单元测试,并使用调试器

来确定哪些行代码执行。


我已经查看了MSDN

文档中的Debug和Debugger类,但它们似乎都没有提供我的功能我

需要。任何人都可以告诉我如何像调试器一样单步执行代码

这样做我可以确定执行哪行代码?任何有关

的帮助都会朝着正确的方向前进,这将非常感谢

赞赏。

Pure coverage from Rational is the only coverage tool I''ve been able
to find for C#, and I don''t really want to pay what Rational charges
for something as simple as a coverage tool. So, I''d like to try to
write my own, but I''m having trouble getting started. The way I see
it, I need to do the following?

1) Create a debugger object or something similar that will allow me
to step through my code.

2) Start a process to run through my unit tests, and use the debugger
to determine which lines of code execute.

I''ve looked into the Debug and Debugger classes in the MSDN
documentation, but neither of them seem to offer the functionality I
need. Can anyone tell me how to step through code like the debugger
does so I can determine which lines of code are executed? Any help to
get moving in the right direction on this would be greatly
appreciated.

推荐答案

Refleftion

" tjm" < TJ *** @ rocketmail.com>在消息中写道

新闻:a5 ************************** @ posting.google.c om ...
Refleftion
"tjm" <tj***@rocketmail.com> wrote in message
news:a5**************************@posting.google.c om...
来自Rational的纯粹覆盖是我能够找到C#的唯一覆盖工具,而且我真的不想支付Rational收费的
像覆盖工具一样简单的东西。所以,我想尝试自己编写,但我很难开始。我看到它的方式,我需要做以下事情。

1)创建一个调试器对象或类似的东西,让我可以逐步完成我的代码。 2)启动一个程序来运行我的单元测试,并使用调试器
来确定执行哪些代码行。

我已经查看了调试和MSDN
文档中的调试器类,但它们似乎都没有提供我需要的功能。任何人都可以告诉我如何像调试器一样单步执行代码
这样我可以确定执行哪行代码?任何帮助
在这方面朝着正确的方向前进的任何帮助都将非常感激。
Pure coverage from Rational is the only coverage tool I''ve been able
to find for C#, and I don''t really want to pay what Rational charges
for something as simple as a coverage tool. So, I''d like to try to
write my own, but I''m having trouble getting started. The way I see
it, I need to do the following.

1) Create a debugger object or something similar that will allow me
to step through my code.

2) Start a process to run through my unit tests, and use the debugger
to determine which lines of code execute.

I''ve looked into the Debug and Debugger classes in the MSDN
documentation, but neither of them seem to offer the functionality I
need. Can anyone tell me how to step through code like the debugger
does so I can determine which lines of code are executed? Any help to
get moving in the right direction on this would be greatly
appreciated.





tjm < TJ *** @ rocketmail.com>在消息中写道

新闻:a5 ************************** @ posting.google.c om ...

"tjm" <tj***@rocketmail.com> wrote in message
news:a5**************************@posting.google.c om...
来自Rational的纯粹覆盖是我能够找到C#的唯一覆盖工具,而且我真的不想支付Rational收费的
像覆盖工具一样简单的东西。所以,我想尝试自己编写,但我很难开始。我看到它的方式,我需要做以下几点。

1)创建一个调试器对象或类似的东西,让我可以逐步完成我的代码。


我能说的最好,这在.NET中是不可能的。 cordbg.exe出现

从imagehlp.dll导入其大部分功能,你将不得不研究如何编写调试器一般。

框架中几乎肯定没有直接可用的类来执行此操作,可以将函数导入(或用MC ++编写)到

实现目标,我不知道。当我有更多的时间我会看到什么

否则我可以找到,如果你发布任何进一步的

信息,我会很感激。

2)启动一个程序来运行我的单元测试,并使用调试器
来确定执行哪些代码行。

我看了进入MSDN
文档中的Debug和Debugger类,但它们似乎都没有提供我需要的功能。任何人都可以告诉我如何像调试器一样单步执行代码
这样我可以确定执行哪行代码?任何帮助
在这方面朝着正确的方向前进的任何帮助都将非常感激。
Pure coverage from Rational is the only coverage tool I''ve been able
to find for C#, and I don''t really want to pay what Rational charges
for something as simple as a coverage tool. So, I''d like to try to
write my own, but I''m having trouble getting started. The way I see
it, I need to do the following.

1) Create a debugger object or something similar that will allow me
to step through my code.
Best as I can tell, this isn''t possible directly in .NET. cordbg.exe appears
to import from imagehlp.dll for most of its features, you will have to
research how to write debuggers in general.
There is almost certainly no directly available class in the framework to
do this, it may be possible to import the functions(or write in MC++) to
achieve that goal, I don''t know. When I have a bit more time I''ll see what
else I can find out and I''d appreciate it if you post any further
information you find here.

2) Start a process to run through my unit tests, and use the debugger
to determine which lines of code execute.

I''ve looked into the Debug and Debugger classes in the MSDN
documentation, but neither of them seem to offer the functionality I
need. Can anyone tell me how to step through code like the debugger
does so I can determine which lines of code are executed? Any help to
get moving in the right direction on this would be greatly
appreciated.



嗨tjm,


" tjm" < TJ *** @ rocketmail.com>在消息中写道

新闻:a5 ************************** @ posting.google.c om ...
Hi tjm,

"tjm" <tj***@rocketmail.com> wrote in message
news:a5**************************@posting.google.c om...
来自Rational的纯粹覆盖是我能够找到C#的唯一覆盖工具,而且我真的不想支付Rational收费的
简单的覆盖工具。
Pure coverage from Rational is the only coverage tool I''ve been able
to find for C#, and I don''t really want to pay what Rational charges
for something as simple as a coverage tool.



< snip>


一种可能的方法是挂钩 C#编译器和

插入" logging"在输出

汇编中调用每个方法的顶部和底部。这里描述了这种技术(但是出于不同的目的):

http://codeproject.com/dotnet/model_...nts_in_net.asp

正如你所看到的,这显然是非平凡的,这可以解释为什么

理性收费如此之多。


问候,

Dan


<snip>

One possible way to do this would be to "hook" the C# compiler and
insert "logging" calls at the top and bottom of each method in the output
assembly. Such a technique is described here (but for a different purpose):

http://codeproject.com/dotnet/model_...nts_in_net.asp

As you''ll see, it''s decidedly non-trivial, which could explain why
Rational charges so much.

Regards,
Dan


这篇关于为C#编写Coverage工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆