views:

78

answers:

3

For my project I am using the integrated Visual Studio unit-testing framework but I am having some issues that I never saw before.

One of my classes is causing VSTestHost to crash. So first I though it was because there was a bunch of code causing a stack overflow. What is really strange is that now, even if I create a new project or use older projects that were working before, VSTestHost is crashing immediately (1/2 second after I clicking on the run tests button). In fact I just cannot unit-test anymore... This is really driving me crazy.

I tried many solutions found on the Internet to fix that problem but nothing worked. I had to restore Windows to my last update to get it back working normally. What is sure is that it is one particular test class which cause the unit-test framework to go mad. When I run this test class for the first time everything goes well and all the tests pass, and then every time I try to run a unit-test, VSTestHost is crashing preventing me from unit-testing in any project.

Here I show you the test that is supposedely making the program to crash. My LoadFromExe() method is just using ConfigurationManager.OpenExeConfiguration() method. It makes now some month I a using this AlphaProjectConfiguration whithout any issue.

[TestMethod()]
public void LoadGoodConfigurationFromExeTest()
{  

    using (StreamWriter sw = new StreamWriter(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath))
    {
        sw.Write(Resources.GoodConfiguration);
    }

    AlphaProjectConfiguration actual = new AlphaProjectConfiguration();
    actual.LoadFromExe();

    Assert.IsNotNull(actual);
}

I just put all my efforts in solving this issue and I am really getting rid of it now. It is why I am asking some help from the community now. Thanks.


Edit: This test class contains 3 other tests that almost do the same thing. I tried this on Windows 7 x64 and Windows XP x86 with VSTS 2008 SP1. Crash happens on both systems.

A: 

I can't imagine what is going wrong here. We have also some nasty issues with MSTest. It is quite unstable and slow.

To solve another kind of problem we configured the test host to restart again for each testrun. This could probably also solve your problem.

Goto Tools -> Options -> Test Tools -> Test Execution. Disable "Keep test execution engine running between test runs".

It might be take some more time to start the test tun, because the test host needs to start every time. But it solves some issues.

Hope this helps.

Stefan Steinegger
I tried it and for the moment it seems to work properly. But I cannot confirm your answer for the moment because the way the crash happened was a bit unpredictable. I know this could crash at any moment now! Crossing fingers.Thanks.
Ucodia
Unfortunately the crash happened again... I do not know if it is related to an incorrect use of ConfigurationManager or of StreamWriter (even with a using statement) or simply related to unstability of the unit-testing framework.I am going to restore Windows again. I forgot to mention that I tested this on VSTS 2008 SP1 under Windows XP x86 and Windows 7 x64. The crash happens on both systems.
Ucodia
A: 

If something is going wrong when the test runs, it might be that some resources are getting locked by the mstest process causing the problems.

I might suggest adding some troubleshooting code to ensure that all the file resources are properly closed if unexpected exceptions occur. Throw some exception handling around the StreamWriter methods in the LoadGoodConfigurationFromExeTest method and also the AlphaProjectConfiguration code.

Set some breakpoints or throw some logging in there to see where things are failing (if they are).

Additional suggestions would be to comment out entirely the use of the AlphaProjectConfiguration class and see if things still crash. Sounds like you're saying it will only crash when using that class. If so, time to drill down into the imolementation.

I'm probably not helping you much but those are the first steps I'd be taking not really knowing how much you've already done.

Atoms
"Additional suggestions would be to comment out entirely the use of the AlphaProjectConfiguration class and see if things still crash" That is where I am lost, because even after commenting it out, it still crashes, even on other project that were working properly before and that were completely independent. It is like if it was corrupting the integrity of the framework itself (I had no choice but restoring Windows to a previous state to get it work again). I am gonna take a look to see if Resources are the key of my problem.
Ucodia
A: 

I had a similar problem luckily there's a hotfix that solved the issue on my machine. If you're intersted in the details of this issue, I've wrote about it in my blog.

Dror Helper
I would like to try it but the bug mysteriously disapeared. I cannot even make it happen again... I did not changed my code. I promiss that I will test this hotfix if the same problem happens and I will post feedbacks. Thanks.
Ucodia