How to Unit Test Visual Studio AddIn interacting with VS DOM(如何对与 VS DOM 交互的 Visual Studio 插件进行单元测试)
问题描述
我开发了一个 Visual Studio 插件,它与 Visual Studio DOM 交互并修改加载的解决方案.
虽然我已经努力分离与 DOM 交互的代码并可以通过单元测试对其他业务逻辑进行单元测试,但有没有办法对 VS DOM 交互功能和添加自定义菜单项的加载项初始化代码进行单元测试视觉工作室?
I have developed a Visual Studio Add-In which interacts with the Visual Studio DOM and amends the loaded solution.
While I have endevoured to seperate the code which interacts with the DOM and can unit test the other business logic via unit tests, is there a way to unit test the VS DOM interaction functionality and the Add-In initialisation code which adds custom menu items to Visaual Studio?
推荐答案
这可能有助于回答这个问题...我有一个代码示例来创建一个 DTE VS 实例,我希望我可以使用它在我的单元测试中注入我的类,它与 VS 交互,然后希望分析 DTE 对象以确认测试成功标准.我还没来得及在测试中尝试它,但它看起来很有希望.
This may go some way to answer this... I've got a code sample to create a DTE VS instance which i'm hoping I can then use in my unit test to inject into my class, which interacts with VS, and then hopefully analyse the DTE object to confirm the tests success criteria. I havent got round to trying it within a test but it looks promising.
DTE2 dte = null;
try
{
Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE.10.0");
object inst = System.Activator.CreateInstance(type, true);
dte = (EnvDTE80.DTE2)inst;
dte.Solution.Open(@"C:Demo.sln");
// Inject into class under test
// Perform the test
// Analyse the DTE to test for success.
}
finally
{
if (dte != null)
{
dte.Quit();
}
这篇关于如何对与 VS DOM 交互的 Visual Studio 插件进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何对与 VS DOM 交互的 Visual Studio 插件进行单元测试


- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- 使用 rss + c# 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01