如何对与 VS DOM 交互的 Visual Studio 插件进行单元测试 [英] How to Unit Test Visual Studio AddIn interacting with VS DOM

查看:26
本文介绍了如何对与 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 插件进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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