none
TestContext is null when invoking method using reflection in unit test C# RRS feed

  • Question

  • I am trying to invoke a test method from separate project  using reflection but i get the test context property as null.
    Wednesday, February 6, 2019 12:07 PM

All replies

  • Can you provide a simple example? Make sure to use the code block when posting code..


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, February 6, 2019 12:33 PM
    Moderator
  • I am trying to invoke a test method from separate project  using reflection but i get the test context property as null.

    If you have to do special things in order to run the test, like using Reflection and some context property, then you are not unit testing.

    https://www.artima.com/weblogs/viewpost.jsp?thread=126923

    Unit Testing can be discussed at the UT forum.

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=vsunittest

    Wednesday, February 6, 2019 12:35 PM
  • just create any unit test project and try to invoke the method using reflection from another project


    i get Testcontent Property as null in the test method itself ...

    but if i run same test method from Vs2015 u will get testcontext so need to know how is testcontext set 


    Wednesday, February 6, 2019 2:24 PM
  • A test method is nothing more than a normal method. What makes it a "test" is when it is run by a test framework like NUnit or MSTest. In order to be able to run it as a test you'll have to run the test framework itself. The test context is only one of several things that the test framework sets up. If you're building your own test framework then you'll have to set up the test environment as well. The test context, assertion support, exception handling, concurrency and other things are all the responsibility of the test framework to set up and manage.

    What are you trying to do exactly such that simply running the test framework isn't an option?


    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, February 6, 2019 2:50 PM
    Moderator
  • just create any unit test project and try to invoke the method using reflection from another project


    i get Testcontent Property as null in the test method itself ...

    but if i run same test method from Vs2015 u will get testcontext so need to know how is testcontext set 



    show the code
    Wednesday, February 6, 2019 4:10 PM
  • Hi MarutAwasthi14,

    It will be beneficial to resolve the issue if you share a bit more information, such as a simple complete project. the steps to reproduce the issue, etc.

    Best regards,

    Zhanglong


    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.

    Thursday, February 7, 2019 2:36 AM
    Moderator