Crashing unit tests in Visual Studio

Image courtesy of Stuart Miles / FreeDigitalPhotos.net
Today I got my unit tests to crash in Visual Studio. Right after some refactoring the tests stopped working and the output window contained the following message:

The active Test Run was aborted because the execution process exited unexpectedly. To investigate further, enable local crash dumps either at the machine level or for process vstest.executionengine.x86.exe. Go to more details: http://go.microsoft.com/fwlink/?linkid=232477

Looking closer at my refactoring action I soon noted that the constructors looked odd. Below a simplified replication of the crashing code. Can you fix the code below?

[TestMethod]
public void IsWorking_DefaultConstructor_True() {
    var testObject = new ClassUnderTest();
    var result = testObject.IsWorking();
    Assert.IsTrue(result);
}

public class ClassUnderTest {
    private object SomeObject;
    // existing constructor without parameters
    public ClassUnderTest() : this(Environment.OSVersion) { 
        SomeObject = Environment.OSVersion; 
    }
    // new constructor added
    public ClassUnderTest(object someObject) : this() { 
        SomeObject = someObject; 
    }
    // validate SomeObject is set
    public virtual bool IsWorking() {
        return SomeObject != null;
    }
}

* Image courtesy of Stuart Miles / FreeDigitalPhotos.net

About erictummers

My work as a recruited developer changes almost every month. I like challenges and sharing the solutions with others. On my blog I’ll mostly post about my work, but expect an occasional home project, productivity tip and tooling review.
This entry was posted in Development and tagged , , . Bookmark the permalink.

3 Responses to Crashing unit tests in Visual Studio

  1. Mike Manard says:

    Your constructors reference one another. Wouldn’t you be finding yourself in an infinite constructor loop?

    • erictummers says:

      That was the problem causing the Text Runner to crash. The new constructor should have looked like this
      public ClassUnderTest(object someObject) : this() {
      SomeObject = someObject;
      }

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