locked
parallelTestCount causes TestContext to be null sometimes RRS feed

  • General discussion

  • We are running our unit test in parallel using parallelTestCount. Occasionally a test would fail with NullReferenceException accessing TestContext. Is this a known bug?

    Friday, February 10, 2012 10:38 PM

All replies

  • Hi Alex,

    Thank you for posting in the MSDN forum.

    Do you mean that you get the error “System.NullReferenceException: Object reference not set to an instance of an object.”?

    If it is not, please share the whole error message.

    If it is, firstly we can only use this parallel execution feature if the following conditions are true:

    • You run your tests on a computer that is using Microsoft Visual Studio 2010. The
      tests can be run locally or remotely using a test controller.
    • You only run unit tests. (The test cannot be an extension of a unit test type, for
      example coded UI tests.)
    • Your unit tests are thread-safe to prevent issues when the tests run in parallel.
    • You cannot collect any data and diagnostics with your test settings because this
      will slow down the test execution time and the data would be based on multiple
      tests running at the same time.
    • You must not run your unit tests as hosted tests. For example, you cannot use an ASP.NET host adapter.

    For detailed information, see How to: Run Unit Tests Faster Using a Computer with Multiple CPUs or Cores.

    In addition, I did some research, and I found some reasons which
    can generate this issue, like 
    Private accessors here or we don't have a connection string in our configuration here
    and so on.
    We usually ask for the trace log file when there is not enough
    information for the problem, see Unit Test Adapter threw exception: System.NullReferenceException. Hope it helps.

    If there's any concern, please feel free to let us know.

    Best Regards,



    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    Monday, February 13, 2012 5:50 AM
  • Yes, we are getting "System.NullReferenceException: Object reference not set to an instance of an object." accessing TestContext property of the unit test calss. We do not use private accessors. And it does not happen all the time. So I was wandering if there is a known race condition in MSTest framework when running tests in parallel.
    Tuesday, February 14, 2012 6:31 PM
  • Hi Alex,

    Glad to receive your reply.

    As my last reply, there are many reasons which can generate the same error, so it is hard to get a known solution about this issue. We would check it one step by one step.

    As the last link provided by me, you can try to enable tracing for test execution issues. I think you will get more useful information.

    You can try to run it with another computer, make sure that it is not related to the VS.

    If no help, please also attach your Visual Studio project, you can upload it to the sky driver, and then share the download link in your post. We will download and check it on our side.

    If there's any concern, please feel free to let me know.

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, February 15, 2012 5:37 AM
  • Hi Alex,

    I am writing to check the status of the issue on your side. What about this problem now? Would you mind letting us know the result of the suggestion? If no help, please let us know the latest news about this issue.

    Thank you for your understanding!


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    Monday, February 20, 2012 3:36 AM
  • It has not happened for a while.
    Monday, February 20, 2012 5:51 PM
  • Hi Alex,

    Glad to receive your reply.

    If you think that a certain reply is helpful, you can make it as the answer, based on your description

    It has not happened for a while.

    So I will close this thread. If it has any issue again, welcome back!

    Have a nice day,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, February 21, 2012 2:25 AM
  • The issue is back. And I a said in my original post I am suspecting a race in Visual Studio Unit Test framework. Is anyone else running unit tests on TFS 2010 build servers using parallelTestCount?
    Thursday, April 19, 2012 4:35 AM
  • Hi Alex,

    Glad to receive your reply.

    The issue is back. And I a said in my original post I am suspecting a race in Visual Studio Unit Test framework. Is anyone else running unit tests on TFS 2010 build servers using parallelTestCount?

    Based on your description, it is related to the TFS 2010 build, since I’m not a TFS 2010 build expert. So if possible, you could post a new thread Team Foundation Server - Build Automation for dedicated support.

    In addition, you could post the link of this thread in your new thread, and I think it will be useful for the TFS 2010 build expert to troubleshoot this issue. Since this issue is related to the TFS 2010 build, we are changing the issue type to General Discussion. Thanks for your understanding. 

    Sincerely,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, April 19, 2012 5:28 AM