如何通过整合MSTest的测试期间举办VS IDE? [英] How to host VS IDE during integration test via MSTest?

查看:312
本文介绍了如何通过整合MSTest的测试期间举办VS IDE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个集成测试项目来测试VS扩展。如果我请从Visual Studio IDE中测试,所有测试都运行得很好,每一个方法生成一个新的VS IDE。测试方法上标有以下属性:

I have created an integration test project to test VS Extension. If I run the tests from the Visual Studio IDE, all tests are running just fine and every method spawns a new VS IDE. The test methods are marked with the following attributes:

[HostType("VS IDE")]
[TestMethod]
public void TestWhateverMethod() { ... }

不过,如果我尝试自动化测试,从命令行通过MSTest的(或VSTest)我得到了以下错误消息运行它们,因为这是在VS IDE内部举办了测试:

However if I try to automate the tests, and run them from commandline via MSTest (or VSTest) I got the following error message, for the tests that are hosted inside the VS IDE:

主机类型VS IDE无法加载以下原因:
键VS IDE无法找到。 。确保适当的主机
适配器安装在机器上

The host type 'VS IDE' cannot be loaded for the following reason: The key 'VS IDE' cannot be found. Make sure that the appropriate host adapter is installed on the machine.

因此,我试图在寻找解决方案:< A HREF =https://msdn.microsoft.com/en-us/library/bb166001%28v=vs.90%29.aspx相对=nofollow> MSDN - 如何安装主机适配器。但它只是记录了VS2005和2008年

Therefore I tried to find the solution at: MSDN - How to: Install a Host Adapter. But it is only documented for VS2005 and 2008.

我想问一下,了解有关VS 2013的方向,我在哪里可以找到更多信息?还是我缺少什么?这是从VS IDE外部运行集成测试的正确方法?如何可以编程方式举办一个IDE?

I would like to ask for directions regarding VS 2013, where can I found out more? Or what am I missing? Which is the proper way to run integration tests from outside the VS IDE? How one can host an IDE programmatically?

感谢你在前进!

推荐答案

我意识到如何做到这一点,而不使用HOSTTYPE属性。希望下面的代码片段可以帮忙他人,以及:

I realized how to do it, without using the HostType attribute. Hopefully the following code snippet can help out others as well:

Type visualStudioType = Type.GetTypeFromProgID("VisualStudio.DTE.12.0", true);    
DTE env = Activator.CreateInstance(visualStudioType, true) as DTE;

这将得到VS的类型,与指定的版本,将抛出错误异常。在DTE将成为EnvDTE的界面,即可以使用。

This will get the type of the VS, with the specified version and will throw an exception on error. The DTE will be the interface of the EnvDTE, that one can use.

要得到服务,做到以下几点,例如拿到UI壳牌:

To get services, do the following, e.g. to get the UI Shell:

ServiceProvider serviceProvider = new ServiceProvider(env as 
Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
IVsUIShell uiShell = (IVsUIShell)serviceProvider.GetService(typeof(SVsUIShell));



一要跟踪服务,得到了RCW处理和事后正确释放COM对象的使用。

One should keep track of the services, get the rcw handle and properly release the COM object afterwards the usage.

这篇关于如何通过整合MSTest的测试期间举办VS IDE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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