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开发者_Python百科, 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?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();
}
精彩评论