none
Unit Testing VSTO 2010 Project RRS feed

  • Question

  • Is there a way to isolated the project layers in a VSTO project? I have not had much luck setting up a testable model. My ViewModel should drive the functionality of the Word Document / Ribbon and Custom Task Pane. Any articles leading to a way to achieve this functionality?
    Tuesday, May 31, 2011 8:41 PM

Answers

  • Unit testing of a VSTO project is not trivial. In general, my approach is to leave as little code as possible in the add-in itself, and to extract the logic into a separate dll, which is instantiated by the add-in when it starts up. That way, you can unit test the external dll with much problem.

    I wrote a blog post a while back on the topic, it would need a bit of updating, but illustrates the idea:

    http://www.clear-lines.com/blog/post/Unit-testing-VSTO-projects.aspx

    Where things get a bit hairy is with the Ribbon and the TaskPane. I have had some success with the TaskPane, by creating a TaskPane with a WPF host in the add-in itself, and then injecting specific Views into it from my dll; again, as all your code is now moved into the dll, you can test it without too much trouble. I still don't have a very good solution for the Ribbon. I initially worked with the Visual Ribbon, which is problematic to work with, but I think something similar might be workable using the xml Ribbon.

    You may also want to look into the VSTO contrib project:

    http://vstocontrib.codeplex.com/ 

    It has been developed with your goal in mind, namely, making VSTO projects testable. I have not used it yet, but I attended a talk by Jake Ginnivan, who developed it, and it looked very promising.

    Hope this helps!

    Mathias

    • Marked as answer by Codeitup Wednesday, June 1, 2011 11:38 AM
    Tuesday, May 31, 2011 11:55 PM

All replies

  • Unit testing of a VSTO project is not trivial. In general, my approach is to leave as little code as possible in the add-in itself, and to extract the logic into a separate dll, which is instantiated by the add-in when it starts up. That way, you can unit test the external dll with much problem.

    I wrote a blog post a while back on the topic, it would need a bit of updating, but illustrates the idea:

    http://www.clear-lines.com/blog/post/Unit-testing-VSTO-projects.aspx

    Where things get a bit hairy is with the Ribbon and the TaskPane. I have had some success with the TaskPane, by creating a TaskPane with a WPF host in the add-in itself, and then injecting specific Views into it from my dll; again, as all your code is now moved into the dll, you can test it without too much trouble. I still don't have a very good solution for the Ribbon. I initially worked with the Visual Ribbon, which is problematic to work with, but I think something similar might be workable using the xml Ribbon.

    You may also want to look into the VSTO contrib project:

    http://vstocontrib.codeplex.com/ 

    It has been developed with your goal in mind, namely, making VSTO projects testable. I have not used it yet, but I attended a talk by Jake Ginnivan, who developed it, and it looked very promising.

    Hope this helps!

    Mathias

    • Marked as answer by Codeitup Wednesday, June 1, 2011 11:38 AM
    Tuesday, May 31, 2011 11:55 PM
  • Very good I knew it wasn't going to be an neasy task! Thansk for all the articles I am going to review all the material and decide the direction I am going to go in...

     

    Thanks again

    Wednesday, June 1, 2011 11:38 AM