Unit Testing VSTO projects

最后都变了- 提交于 2019-12-06 20:49:30

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.

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:

  • Right click on the test project and select "Add Reference".
  • In the Box the appears, click on the "Browse" button at the bottom.
  • Navigate to the bin\debug folder of the VSTO project and select the projects dll.
  • Click on OK.

Obviously, you will have had to have built the addin for the above to work.

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.

I don't know why adding a reference doesn't work, but you might be able to solve it by adding a 3rd project. Place all your logic in this new project. Add a reference to this new project in your tests, and then add a reference to you new project in your VSTO addin project, where you can call the logic.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!