Daily Archives: July 25, 2007

The Mystery of the Disappearing Tests in Microsoft Test



I have finally solved the mystery.   A couple of days ago I wrote a four tests in a test class.  All seemed well.  Here there are:


Then “it” happened.  All of a sudden, one or more of the tests in the “Test View” would vanish without explanation.  I would rename one of them and it would return, only to vanish later.

I renamed the test methods, googled the problem, deleted code, duplicated code, when generally crazy without any luck. 

Do you believe that the position of certain declarations in your class makes any difference?  I didn’t believe so.  Until now.  In the past I liberally scattered private declarations and member variables throughout my class where I felt necessary, unshackled by the VB6esque standard of declaring everything at the top.    As it turns out, the old standard wouldn’t have saved me either…

The Problem

It turns out the “poison” which prevents Microsoft Test from finding tests is a delegate declaration.  Declare any delegate in your code and all test methods declared after that delegate will be invisible to test view.

Here’s a VB.Net example:

Private Delegate Sub ThisStopsTheFollowingBeingDetected()
    <TestMethod()> Public Sub TheInvisibleTestMethod()

    End Sub

The Solution

The only way of solving the problem is to move your delegate declarations to  the bottom of your class file:

    <TestMethod()> Public Sub TheInvisibleTestMethod()

    End Sub

    Private Delegate Sub ThisIsDelcaredAtTheBottom()

End Class

 Strange but true. 

This problem with detected in Visual Studio 2005 Team Edition for Developers.

The issue is tracked at https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=288973