Unit testing of a running VSTO plugin
-
Monday, October 03, 2011 8:25 AM
How to unit test a VSTO plugin? (Word 2010, .NET4, Visual Studio 2010 in my case).
There are plenty of examples that refactor to maybe MVP or something and then unit test the Presenter because the underlying code is simple and testable in isolation. This is not the case for my project.
I need to test code that is manipulating the document. Mocking up the entire Word (or other Office) application is just not possible. The plugin needs to be running in its native environment for the bulk of the testing.
I have seen two possible solutions:
1) Use the deprecated "remoting" classes to run the tests "remotely". http://blogs.msdn.com/b/pstubbs/archive/2006/09/15/756488.aspx but translated to WCF for 2010 I guess.
2) Somehow use VSTO Contrib http://vstocontrib.codeplex.com/. I have not looked at it in detail but it uses a different security model and has to hack click once for deployment among other things and is still a work in progress.
So are these the answers to the question? Or can I magically get a testing solution that works by upgrading to Visual Studio Premium or something?
- Moved by Mike Dos ZhangMicrosoft Contingent Staff Tuesday, October 04, 2011 6:00 AM unit test problem (From:Windows Forms General)
- Moved by Jack Zhai - MSFTMicrosoft Contingent Staff, Moderator Tuesday, October 04, 2011 7:33 AM (From:Visual Studio Team System - Testing)
All Replies
-
Tuesday, October 04, 2011 6:03 AM
I think this "test" forum is suitable than the Windows Form forum for your this aspect question.
So I moved it here for more expert help.
Best wishes,
Mike [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

-
Tuesday, October 04, 2011 7:37 AM
Hi,
A similar blog, see Unit testing VSTO projects. May just have a try as the links provided by you to check whether it helps.
Best Regards,
Fan
When you help others, it's help yourself! -
Wednesday, October 05, 2011 6:37 AM
Thanks for the link Captain Fan,
I have looked at that already as part of my search. However to quote that article summary itself:
Finally, unit tests are only one aspect of testing; essentially, the test I presented operates on the following premise: “if Excel behaves the way I believe it does, then my class is working properly”. In no way does it guarantee that when everything is wired together, Excel and the Add-In will work happily together – and I don’t know how to approach this, for the reason I mentioned earlier: the add-in is started by Excel, and I am not clear how to go about replicating this in an automated test.
So the author is in the same boat I am in. He knows how to test simple and uninteresting things. He even knows how to test things he "thinks" also mean the plugin will behave at runtime. He rightfully notes that that last category is likely wasted effort. In my opinion it is completely wasted.
So the question remains: what is an effective way to to test that the plugin produces the results needed _at runtime_ in the actual Office application environment? No amount of mocking or simplistic scenarios substitutes for this question.
-
Tuesday, July 03, 2012 2:18 AM
Your VSTO add-in can expose a COM API. Then, you can invoke that API from a COM client, including MSTest classes and/or VB in Office.
It is not straight-forward or obvious. But, it is possible.
http://msdn.microsoft.com/en-us/library/bb608614.aspx
http://blogs.msdn.com/b/andreww/archive/2008/10/13/exposing-events-from-managed-add-in-objects.aspx -
Wednesday, August 22, 2012 9:20 AM
Hi,
have you found any solution yet?
We have the same problem. We also have an office plugin and are trying to get it under test.
Unit testing with Mocks is one thing, but it gets complicated if you are trying to mock the complex classes like MailItem or Document. We also looked at tools like typemock but in the end I don't think that this will help.
With gui tests you can cover the behavior of the addin with office but we still have to do these tests before each release manually because we haven't found any gui testing framework yet which is capable of testing office.
Viele Grüße Mark

