The Mystery of the Disappearing Tests in Microsoft Test

Standard

image

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:

image

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s