Sep 26 2011

Visual Studio 2010 my tests doesn’t pass if I run them, but pass if I debug!

Category: — Duke @ 18:45

today I had a bizarre experience using nhibernate.

I’m writing an audit trail system on the top of nhibernate, that have to satisfy certain regulatory requisites.

Of course I’ve a lot of test that proves that my work is proceeding in the right direction. But this morning I’ve added few line of code to introduce a new feature that at the end requires a “references” clause in the nhibernate mapping.

Suddenly some of the test went broken.

I’ve tought that I’ve wrote something wrong in my code so I’ve run the test in debug mode… and guess what? all the test pass…

I’ve then tought that there was some particular situation (maybe some file locked or god-knows-what-like situation that have caused the transient… or what I’ve supposed to be a transient) and then everything was returned normal.

so I’ve wrote other few lines of code and run the test again and BANG! red again…

this time I’ve started investigating more, I’ve lost the whole morning

the symptoms were the followings.

1) if I RUN the test form the test list windows of visual studio, some of the test (and always the same tests) systematically fails.

2) if I DEBUG the failing tests from within the test result window or the test list window the exact same test pass

3) from the moment when the test PASS in DEBUG, I could RUN the test again from the test result windows, and they KEEP passing

4) if for any reason I RUN again the same exact test from the test list window they start failing again.

 

the error message when they fail was something like “the property method get_Xyz could not be found”

and in fact that was the property I was working on.

 

at the end I’ve discovered the cause.

the Code coverage instrumentation was activated on the assembly I was editing.

for a reason that nobody will ever know, visual studio have cached somewhere (probably over the rainbow) something about how to instrument the assembly I was working on.

no mater how I’ve tried to delete the BIN and OBJ and TestResults of all the involved projects… they keep presenting the same behavior.

Guess what? this visual studio magical cache went for another unknown reason out of date.

and the result (I’ve figured out) was that out of date code was keep injected in my code causing all the sort of the bad things… but only if I RUN the test.

Luckily the DEBUG of the test doesn’t inject (outdated) the instrumentation code.

 

Once understood that the code coverege was the cause it was easy to solve.

just shut the code coverege down, recompiled everything, runned the code => green, debugged the code=> green!

after this I’ve turned on the code coverage again and tested the tests another time: green again! YAY!

 

So, if your test starts to become reds without any reason, give a look at the code coverage Sorriso

Tags:

1.
Kimberley Kimberley says:

I was able to find good information from your blog posts.

Stop by my blog post - online marketing experts ( Kimberley - http://mycashtown.com/ )

2.
Zeichen weiblicher Unfruchtbarkeit Zeichen weiblicher Unfruchtbarkeit says:

It's really a cool and helpful piece of information. I'm glad that you shared this helpful info with us. Please stay us informed like this. Thank you for sharing.

Have a look at my web page:  Zeichen weiblicher Unfruchtbarkeit - http://newmyshopblog.com/kaufen_clomid_de_1/

3.
http://newmyshopblog.com/ http://newmyshopblog.com/ says:

Excellent post. I was checking continuously this weblog and I am inspired! Extremely helpful info particularly the final part Smile I take care of such information a lot. I was seeking this certain info for a long time. Thanks and good luck.

my weblog Gewichtsverlust Hilfe ( http://newmyshopblog.com/ - http://newmyshopblog.com/kaufen_orlistat_de_1/ )

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading