12

In order not to pollute my projects with unit tests, I like to create a separate project for my unit tests; I add a reference to the project under test in the unit tests project. However, this isn't working that well with my VSTO excel add-in projects: when I create a separate unit test project and go to Add Reference > Projects, there is no project to pick.
What I have done so far is Add Reference > Browse, and pick the add-in dll from the debug folder. I have also run into issues from time to time with this, with the reference suddenly not working, requiring to remove/re-add the dll reference.
Can anybody explain why a VSTO project doesn't show up as a regular project? And is there a better way to go about it than what I am doing presently?

Mathias
  • 15,191
  • 9
  • 60
  • 92
  • This doesn't directly answer your question, but here is an interesting blog entry about testing Excel VSTO add-ins: http://www.clear-lines.com/blog/post/Unit-testing-VSTO-projects.aspx – Jay Sep 05 '11 at 07:25
  • 2
    @Jay: I would be tempted to say this is an excellent post, but that may be a bit inappropriate, because I wrote it :) – Mathias Sep 08 '11 at 03:15
  • I prefer using xUnit, which is working well for me with my VSTO Outlook AddIn project. My AddIn project showed-up without any problems under the "Projects" section of the Reference Manager window. My question/answer on setting up xUnit to work with my VSTO Outlook AddIn is [here](https://stackoverflow.com/q/75739113/20036274). – wopr_xl Mar 15 '23 at 11:04

5 Answers5

4

I can offer an answer to the last part of your question about avoiding the issue.

One way to get around this is to separate the code that doesn't explicitly reference VSTO libraries into another project, and then test that - I understand that this will likely involve an effort to actually have code that doesn't reference VSTO.

But this way, the code you are testing is code that can be tested without referencing VSTO and the VSTO-specific code would probably be tested via integration tests (manually or via an API like White - where White doesn't need to reference VSTO because it merely runs executable code that uses VSTO)

While this may mean some significant redesign - you may need to create wrapper-classes, for example - and it may not be feasible for you right now, I believe that this is generally seen as a good practice (it's a kind of separation of concerns) because it would make it easier to manage code and often helps isolate certain bugs from VSTO complications.

PandaWood
  • 8,086
  • 9
  • 49
  • 54
3

I just had the same problem when trying to add a VSTO addin project reference to a WIX setup project. My solution was to manually add the project reference by editing the target project file in notepad. Just find an existing ProjectReference xml tag in the project file, copy it, and replace the file path details, name, etc.

More of a workaround than a solution, but I hope it helps. Not sure what is different about the VSTO addin projects that prevents them from being shown in the add references dialog.

dan9298
  • 195
  • 1
  • 11
0

When I had this issue, it was because the add-in project and unit test project were configured to different versions of .NET. Once the versions were the same, it was available.

andrewtatham
  • 1,093
  • 9
  • 10
0

I wasn't able to see add a reference to my VSTO Addin until I ticked 'Register for COM interop' on the Build tab in properties.

Matt Fitzmaurice
  • 1,319
  • 4
  • 19
  • 40
0

What brought me here is trying to Unit test the Presenter of my MVP based VSTO plugin. The best answer I have seen so far is this: http://blogs.msdn.com/b/pstubbs/archive/2006/09/15/756488.aspx

Basically you run your VSTO plugin remotely and then you can separately run your test suite against it. This avoids trying to mock the unmockable: an Office application.

It allows you to test the Presenter layer directly in the environment (running as a plugin to an actual Office app) that it needs to be tested in.

Dirk Bester
  • 1,791
  • 19
  • 21