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 插件进行单元测试


基础教程推荐
- 如何激活MC67中的红灯 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01