单元测试 VSTO 项目 [英] Unit Testing VSTO projects
问题描述
在我遵循的大多数单元测试教程中,它让我创建第二个单元测试项目,然后将测试项目中的解决方案/项目引用添加到另一个项目.
In most unit test tutorials I follow it has me create a second unit test project and then add a solution/project reference from the test project to the other project.
我有一个 VSTO 插件,当我添加参考时,我没有看到解决方案 > 项目下列出的任何内容.
I have a VSTO addin, and when I go to add the reference I don't see anything listed under Solution > Project.
这是为什么?我还能如何添加对插件项目的引用来测试它?
Why is this? How else can I add a reference to the addin project to test it?
推荐答案
如果这是您第一次进行单元测试,那么 VSTO 可能是一个陡峭的学习曲线.正如@Sam Holder 所建议的那样,您可能希望将一些逻辑放入单独的程序集中,以鼓励您将逻辑与与办公基础设施的交互分开.
If this is your first time at unit testing, then VSTO might be a steep learning curve. As suggested by @Sam Holder, you might want to put some of your logic into a separate assembly to encourage you to separate your logic from your interactions with the office infrastructure.
也就是说,虽然您无法使用添加对项目的引用的常规方法来添加项目,但您可以使用 Browse 添加对该项目的输出的引用
选项:
That said, whilst you can't add the project using the normal approach of adding a reference to the project, you can add a reference to the output from that project using the Browse
option:
- 右键单击测试项目并选择添加引用".
- 在出现的框中,点击底部的浏览"按钮.
- 导航到 VSTO 项目的 bin\debug 文件夹并选择项目 dll.
- 点击确定.
显然,您必须构建插件才能使上述内容正常工作.
Obviously, you will have had to have built the addin for the above to work.
如果您开始尝试创建依赖于办公基础设施的对象,您将面临一些其他挑战.因此,您可能至少需要在测试项目中添加对 Microsoft.Office.Tools
、Microsoft.Office.Tools.Common
的引用.
You're going to face some other challenges if you start trying to create objects that rely on the office infrastructure. So, at a minimum you might need to add references to Microsoft.Office.Tools
, Microsoft.Office.Tools.Common
into your test project.
这篇关于单元测试 VSTO 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!