如何进行单元测试的Visual Studio外接程序与VS DOM交互 [英] How to Unit Test Visual Studio AddIn interacting with VS DOM

查看:383
本文介绍了如何进行单元测试的Visual Studio外接程序与VS DOM交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一个Visual Studio插件在其相互作用与Visual Studio DOM和修改加载的解决方案。照片 虽然我endevoured要分开了code的相互作用与DOM,并通过单元测试进行单元测试的其他业务逻辑,是有办法的单元测试VS DOM的交互功能和外接程序初始化code这增加了自定义菜单项Visaual工作室?

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?

推荐答案

这可能会在一定程度上回答这个问题......我有一个code样本来创建一个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();
            }

这篇关于如何进行单元测试的Visual Studio外接程序与VS DOM交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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