I have some code with unit tests that pass in a Debug build but fail in a Release build which is correct. However, the same tests pass in both Debug and Release mode when run using JetBrains dotCover.
To give a bit of background, here is the offending test code, just to give you in idea of why it's failing for a Release build - it's basically because of reduced stack information due to code optimization.
using System.Diagnostics;
using NUnit.Framework;
namespace DotCoverTest
{
[TestFixture]
public class TestLogger
{
[Test]
public void GetCurrentClassLoggerReturnsLoggerWithOwningTypeName()
{
Assert.AreEqual(Logger.GetCurrentClassLogger(), GetType().Name);
}
}
public class Logger
{
public static string GetCurrentClassLogger()
{
return new StackFrame(1, false).GetMethod().DeclaringType.Name;
}
}
}
EDIT: Any ideas how I can set up my build so that I get the same test results with or without a coverage tool ?
NOTE: This question was initially posted believing that it was a problem with TeamCity but it is not.