简体   繁体   English

如何单元测试Visual Studio AddIn与VS DOM交互

[英]How to Unit Test Visual Studio AddIn interacting with VS DOM

I have developed a Visual Studio Add-In which interacts with the Visual Studio DOM and amends the loaded solution. 我开发了一个Visual Studio加载项,它与Visual Studio DOM交互并修改加载的解决方案。
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? 虽然我已经努力分离与DOM交互的代码并且可以通过单元测试对其他业务逻辑进行单元测试,但是有没有办法对VS DOM交互功能和添加自定义菜单项的外接程序初始化代码进行单元测试。 Visaual工作室?

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. 这可能会在某种程度上回答这个...我有一个代码示例来创建一个DTE VS实例,我希望我可以在我的单元测试中使用它注入我的类,它与VS交互,然后希望分析DTE对象以确认测试成功标准。 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();
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM