I have developed a Visual Studio Add-In which interacts with the Visual Studio DOM and amends the loaded solution.
While I have endevoured to seperate the code which interacts with the DOM and can unit test the other business logic via unit tests, is there a way to unit test the VS DOM interaction functionality and the Add-In initialisation code which adds custom menu items to Visaual Studio?
Asked
Active
Viewed 734 times
3
-
1This is a problem I've been grappeling with too. So far the best I've been able to do is to mock interfaces and perform the tests based on my expectation of what VS should do. – Kell Mar 29 '11 at 09:19
1 Answers
1
This may go some way to answer this... I've got a code sample to create a DTE VS instance which i'm hoping I can then use in my unit test to inject into my class, which interacts with VS, and then hopefully analyse the DTE object to confirm the tests success criteria. I havent got round to trying it within a test but it looks promising.
DTE2 dte = null;
try
{
Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE.10.0");
object inst = System.Activator.CreateInstance(type, true);
dte = (EnvDTE80.DTE2)inst;
dte.Solution.Open(@"C:\Demo.sln");
// Inject into class under test
// Perform the test
// Analyse the DTE to test for success.
}
finally
{
if (dte != null)
{
dte.Quit();
}

gouldos
- 1,015
- 1
- 16
- 30
-
1This also gives some help with timing issues which might arise http://msdn.microsoft.com/en-us/library/ms228772(VS.80).aspx – gouldos Apr 01 '11 at 16:26
-
1What about Carlos J.Quintero's answer in http://social.msdn.microsoft.com/Forums/eu/vsx/thread/294b37ac-3deb-47a1-943b-cb26f147f93e? – Kiquenet Jan 21 '13 at 08:06
-
Maybe errors like System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with CLSID {656D8328-93F5-41A7-A48C-B42858161F25} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)). – Kiquenet Jan 21 '13 at 10:16
-