Code is behaving differently in Release vs Debug Mode

后端 未结 6 1468
一向
一向 2020-12-19 03:52

We have some unit tests that fail when run in Release mode vs debug mode. If I attach a debugger in release mode the tests pass. There is way too much code to publish here s

6条回答
  •  天命终不由人
    2020-12-19 03:55

    Questions you should ask yourself -

    1. Is my code threaded? Timing differences will affect output
    2. Is someone calling Debug.Assert() with an expression that side effects?
    3. What objects implement IDisposable() and do some do so in such a way that changes state?
    4. Are you P/Invoking into unmanaged code?

    Number 3 is a very likely bad-boy in this case. Garbage collection may be very different in debug and release and you may find that when an object is garbage collected is affecting the outcome of a later unit test.

    And FYI, if you're using NUnit and TestDriven.NET - the two run tests in different orders.

提交回复
热议问题