【发布时间】:2012-02-19 11:43:01
【问题描述】:
我有一些带有单元测试的代码,这些代码在调试版本中通过,但在发布版本中失败,这是正确的。但是,当使用 JetBrains dotCover 运行时,相同的测试在 Debug 和 Release 模式下都会通过。
为了提供一些背景知识,这里是有问题的测试代码,只是为了让您了解它在发布版本中失败的原因 - 这基本上是因为代码优化导致堆栈信息减少。
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;
}
}
}
编辑: 有什么想法可以设置我的构建,以便在使用或不使用覆盖工具的情况下获得相同的测试结果?
注意:最初发布此问题时认为这是 TeamCity 的问题,但事实并非如此。
【问题讨论】:
-
您确定 TeamCity 中的 Release 版本实际上使用的是 Release dll 而不是 Debug 的?
-
查看运行单元测试的构建脚本会很有用
-
感谢小伙子们的回复——我在原帖中添加了更多关于该问题的信息
标签: .net unit-testing nunit continuous-integration teamcity