none
Write the Unit testing for my Extensible(VS Add-in) Projects

    Question

  • Hi,

    Currently I have implemented the Visual Studio Add-in and its works as expected.

    I have to implement the unit testing project for my Extension project. Can any one suggested how can I start this ? 

    Also I have used some project instance objects inside of this utility. So from unit testing how can I generate and pass the project object ? 

    Thanks in advance,


    - Abbas K



    Thursday, December 22, 2016 5:45 PM

All replies

  • Hi Abbas K,

    It’s hard to Unit Test Visual Studio Add-ins. This is mainly because hard dependencies with COM-related interfaces.

    We could unit test any C# code, and the test class should be public. However, there are many internal classes and members of the other assembly in VSIX project, which could not be accessed by unit test. You probably don't get much value Unit Testing the methods in your Plugin.

    But you could use your unit testing approach separately, and here is thread where the marked answer gave the approach:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/294b37ac-3deb-47a1-943b-cb26f147f93e/dte-and-unit-testing?forum=vsx

    I hope it could be helpful.

    Best regards,

    Fletcher


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 23, 2016 11:03 AM
  • Hi 

    I have tried to create project using above your suggest MSDN Form post . But I get below mention errors randomly,

    1).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)). 

    2)."RPC server is unavailable.(Exception from HRESULT:0x800706BA)" 

    Can you please suggest how to resolve above mention issues ? "

    Best Regards,


    - Abbas K

    Thursday, January 5, 2017 9:18 AM
  • When automating DTE, the following approach must be used:

    Fixing 'Application is Busy' and 'Call was Rejected By Callee' Errors 

    https://msdn.microsoft.com/en-us/library/ms228772(VS.80).aspx


    My portal and blog about VSX: http://www.visualstudioextensibility.com
    Twitter: https://twitter.com/VSExtensibility
    MZ-Tools productivity extension for Visual Studio: https://www.mztools.com

    Thursday, January 5, 2017 4:52 PM
  • Thanks for your response.

    I have already used IOleMessageFilter  error handlers.Sometimes IOleMessageFiltererror handlers will be resolve run time exception, But I get exception like System.Runtime.InteropServices.COMException (0x80080005) randomly, When run unit test cases.

    I have get another issue in project create function. When create project DTE instance,one or more Visual Studio instance will be created. Please refer below screen for showing one or more Visual Studio instance in Task Manager.

    Can you please suggest any other solution to resolve above mention issues ? "

    Best Regards,


    - Abbas K

    Friday, January 6, 2017 5:25 AM
  • Hi,

    I don't know about the System.Runtime.InteropServices.COMException (0x80080005).

    Regarding the multiple instances, it could be that:

    - Each test creates its own instance of DTE. In this case, code your tests such as only one DTE instance is created at test suite level and that only one test is executed at the same time.

    - The DTE instance is not closed after a test session, so after multiple test sessions multiple DTE instances remain opened. In this case:

    1) Rather than calling dte.Solution.Open, use:

    dte =....

    solution = dte.Solution;

    solution.Open(...)

    2) Call Marshal.ReleaseComObject for each object:

    dte =....

    solution = dte.Solution;

    solution.Open(...)

    Marshal.ReleaseComObject(solution);

    solution = null;

    dte.Quit();

    Marshal.ReleaseComObject(dte)

    dte = null;

    For more info see:

    https://www.add-in-express.com/creating-addins-blog/2013/11/05/release-excel-com-objects/


    My portal and blog about VSX: <a href="http://www.visualstudioextensibility.com"> http://www.visualstudioextensibility.com</a> <br/> Twitter: <a href="https://twitter.com/VSExtensibility">https://twitter.com/VSExtensibility</a> <br/> MZ-Tools productivity extension for Visual Studio: <a href="https://www.mztools.com"> https://www.mztools.com</a>

    Friday, January 6, 2017 6:27 AM
  • Thanks for your response.

    1)I have run one test session only. But there one or more Visual Studio instance will be created, When create project DTE instance.

    2)I have used "Dte.quit()" line, its get exception like "RPC server unavailable"

    Please suggest any other method for resolve above issues.

    Best Regards,


    - Abbas K

    Monday, January 9, 2017 3:54 AM
  • Hi Abbas K,

    I am trying to involve someone who is familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

    Thanks for your understanding.

    Best regards,

    Fletcher


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, January 20, 2017 6:37 AM
  • Hi Fletcher, 

    Thanks for the response. 


    - Abbas K

    Friday, January 20, 2017 6:41 AM