【发布时间】:2014-05-14 17:32:54
【问题描述】:
我开始编写单元测试(MS Test,Resharper 作为测试运行器)。当我设置 LogicalThreadContext(见下文)时,我的测试用例会“中止”。有人知道为什么吗?这与单元测试在不同的线程上有关吗?我该如何解决这个问题?
[TestClass]
public class ContextInfoTest
{
private ILog _log;
[TestInitialize]
public void TestInitialize()
{
// logging configured in assembly.info
_log = LogManager.GetLogger(this.GetType());
}
[TestMethod]
public void FigureOutWhyAborting()
{
string input = "blah";
LogicalThreadContext.Properties["mypropertyname"] = input;
string output = LogicalThreadContext.Properties["mypropertyname"] as string;
Assert.AreEqual(input, output);
}
[TestMethod]
public void ThisWorks()
{
string input = "blah";
CallContext.LogicalSetData("mypropertyname", input);
string output = CallContext.LogicalGetData("mypropertyname") as string;
Assert.AreEqual(input, output);
}
奇怪的是,如果我要调试并单步执行代码,Assert.AreEqual 确实会被调用并通过,所以在那行代码之后发生了一些事情......这就是为什么我认为它可能有一些东西与测试线程等有关。
谢谢!
更新: 所以我在 MSTest 中运行了这个测试,得到了这个异常(Resharper 没有显示)
单元测试适配器抛出异常: 成员 'log4net.Util.PropertiesDictionary,log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a' 的类型未解析..
我在 VS2013、.Net 4.5 上使用 log4net v1.2.13。
此链接似乎表明这是一个引用程序集问题,但没有解决方案。非常欢迎任何其他想法,GAC'ing log4net 不是一个选项。 https://issues.apache.org/jira/browse/LOG4NET-398
【问题讨论】:
-
对我来说很好(运行和调试测试),但我没有使用 reSharper。也许尝试直接从 VS 而不是通过 ReShaper 运行它们
标签: multithreading unit-testing log4net