如何对与 VS DOM 交互的 Visual Studio 插件进行单元测试

How to Unit Test Visual Studio AddIn interacting with VS DOM(如何对与 VS DOM 交互的 Visual Studio 插件进行单元测试)
本文介绍了如何对与 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 插件进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
Weird behaviour when I open a reportviewer in WPF(在WPF中打开报表查看器时出现奇怪的行为)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)