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

Working in a DevOps team is the best thing that happened to me. 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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.