Problems with Unit Tests, Debugger oddly resolves them RRS feed

  • Question

  • I have upwards of 600 unit tests in my current project. Within the last few days many tests that were once working started failing.  The exceptions are not all the same but tend to be related to unity.

    However, if I debug the unit tests, they all suddenly pass without throwing any exceptions.

    If I then run the same exact tests WITHOUT a debugger, they work.

    What could cause this behavior?

    • Moved by eryang Monday, July 26, 2010 2:39 AM Move to VSTS Tesing forum for better support. (From:Visual Studio Debugger)
    Wednesday, July 21, 2010 8:16 PM

All replies

  • Hi,

    May I know what unit test tool you're using? what exception makes those unit test cases fail?

    Since all unit test cases are run one by one, if the first case didn't clean up its data properly, the second case may receive duty data and failed. If you run the second case separately, it works because the data is clean.

    You may insert some code snppets to your unit test cases to print out some critial values, don't attach debugger, run those cases and monitor the changing of printed values, hope it can helps.

    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, July 22, 2010 2:27 AM
  • Eric, we are using mstest in vs2010.

    Ironically our data-driven tests are all passing.  The tests that are failing are non-data-driven tests.  Here are a few of the exceptions that I see.

    System.Configuration.ConfigurationErrorsException: The value of the property 'type' cannot be parsed. The error is: Could not load type 'XXXXXX' from assembly 'xxxxxxx'.

    Test method XXXX threw exception: 
    Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "XXXXXXX", name = "". Exception message is: The current build operation (build key Build Key[YYYYYYYY, null]) failed: The current type, YYYYYYYY, is an interface and cannot be constructed. Are you missing a type mapping? (Strategy type BuildPlanStrategy, index 3) ---> Microsoft.Practices.ObjectBuilder2.BuildFailedException: The current build operation (build key Build KeyYYYYYYYY, null]) failed: The current type, YYYYYYYYYY, is an interface and cannot be constructed. Are you missing a type mapping? (Strategy type BuildPlanStrategy, index 3) ---> System.InvalidOperationException: The current type, YYYYYYYYYYY, is an interface and cannot be constructed. Are you missing a type mapping?

    Test method XXXXXXX threw exception: 
    System.MissingMethodException: Method not found: 'System.Collections.Generic.List`1<!0> SomeClass`2.SomeType(System.Guid, System.Collections.Generic.List`1<!0>, SomeType ByRef, System.Collections.Generic.List`1<!1> ByRef)'.

    Again, if I attach the debugger, these all go away.
    Thursday, July 22, 2010 12:57 PM
  • I have the exact same issue.  MS test, debug the test instead of running them eliminates the error.


    Tuesday, September 28, 2010 3:47 PM
  • Thought I would bump this.  Still no answer on it.

    Friday, December 10, 2010 7:18 PM
  • *bump again*

    Facing the same error

    Thursday, February 10, 2011 11:41 AM
  • Well at least your problem goes away after the debugger has been attached ... mine seemingly just doesn't want to be observed so i'm naming it the heisenburg test ...


    For config related issues (I see some may be having these):

    I have seen other threads talking about using /runconfig to solve mstest issues, apparently running a unit test in VS gives you some context which the IDE passes to your unit tests, mstest.exe however is not able to do that so you need to use the command argument to specify a test config file to use.

    www.ccoder.co.uk - eh ... What's that in plain C# again ?

    Tuesday, April 10, 2012 3:45 PM