简体   繁体   English

Visual Studio 2008 Extension可以快速测试功能吗? C#

[英]Visual Studio 2008 Extension to test a function quickly? C#

I have a function buried deep inside an assembly, eventually this function will get called by my program, but I really don't want to have to debug it all the way to get to this function. 我有一个深藏在程序集内部的函数,最终这个函数将被我的程序调用,但我真的不想一直调试它来获得这个函数。

Is it not possible to get a module / addon for visual studio 2008, where I can just select the function I want to run, provide the parameters, and it will automatically either return the value or best case to actually fire up the debugger, so that breakpoints are met? 是不是可以获得visual studio 2008的模块/插件,我可以在其中选择我想要运行的功能,提供参数,它会自动返回值或最佳情况以实际启动调试器,所以那个断点得到满足?

Thanks... 谢谢...

Please say if the question is not clear enough? 如果问题不够明确,请说一下?

Sometimes the object test bench is a bit clumsy; 有时对象测试台有点笨拙; you can also use the much simpler Immediate Window: Debug -> Windows -> Immediate. 你也可以使用更简单的立即窗口:Debug - > Windows - > Immediate。

Then you can type: 然后你可以输入:

MyNamespace.MyClass.MyStaticMethod() [enter]

If there's a breakpoint in the method, the debugger will start and break at that position. 如果方法中有断点,则调试器将在该位置启动和中断。

If you need to call an instance method: 如果需要调用实例方法:

new MyNamespace.MyClass().InstanceMethod() [enter]

You can also create variables and assign them return values--then call methods on those variables. 您还可以创建变量并为它们分配返回值 - 然后在这些变量上调用方法。

The immediate window can also be used during a debug session. 也可以在调试会话期间使用即时窗口。 When a thread is in the break state, you can execute methods using information (such as variables in scope) from the current debug context. 当线程处于中断状态时,您可以使用当前调试上下文中的信息(例如作用域中的变量)来执行方法。 Very useful! 很有用!

The only downside is that every identifier entered in the immediate window has to be fully-qualified with its namespace, so you end up typing quite a bit. 唯一的缺点是在立即窗口中输入的每个标识符都必须使用其命名空间完全限定,因此您最终会输入相当多的内容。

You might want to try the Object Test Bench . 您可能想尝试对象测试台

From MSDN: 来自MSDN:

Object Test Bench (OTB) is designed for simple object-level testing. 对象测试台(OTB)专为简单的对象级测试而设计。 Use OTB to create instances of your project's objects, invoke methods, and evaluate the results. 使用OTB创建项目对象的实例,调用方法并评估结果。 This way, you shorten the task of coding, debugging and re-coding. 这样,您就可以缩短编码,调试和重新编码的任务。 Visual C#, Visual Basic and Visual J# support testing methods in OTB. Visual C#,Visual Basic和Visual J#支持OTB中的测试方法。

In the View menu: 在“视图”菜单中:
替代文字

I think you're looking for the Object Test Bench . 我想你正在寻找对象测试台 This feature was designed precisely for testing classes and methods on the fly, as you write the code. 在编写代码时,此功能专门用于动态测试类和方法。

MSDN states that it desirable to use for the following tasks: MSDN声明它最适合用于以下任务:

  • Teaching object-oriented programming concepts without going into language syntax. 在不进入语言语法的情况下教授面向对象的编程概念。
  • Providing a lightweight testing tool designed for academic and hobbyist programmers to use on small and simple projects. 提供轻量级测试工具,专为学术和业余爱好者程序员设计,用于小型和简单的项目。
  • Shortening the write-debug-rewrite loop. 缩短write-debug-rewrite循环。
  • Testing simple classes and their methods. 测试简单的类及其方法。
  • Discovering the behavior of a library API quickly. 快速发现库API的行为。

You can access it through View > Other Windows > Object Test Bench . 您可以通过View > Other Windows > Object Test Bench访问它。

使用NUnit创建单元测试,并使用TestDriven.NET在Visual Studio中进行集成

Run an Nunit test with a test runner 使用测试运行器运行Nunit测试

This assumes of course you can mock/stub out any dependencies on this code. 当然,您可以假设您可以模拟/删除此代码的任何依赖项。 Could you provide the code in question? 你能提供有问题的代码吗?

如果您只有VS2008 Express,它不包含测试功能,您可以使用NUnit并为您的方法编写单元测试,并使用测试运行器 ,如Testdriven.NET

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM