我有以下代码:
[TestFixture]
public class LexicalTests
{
[Test]
public void LexicalTest1()
{
TestContext.CurrentContext.TestDirectory;
}
}CurrentContext在尝试获取TestDirectory或WorkingDirectory属性时引发异常。
我该如何解决这个问题?
附言:在我家里的PC上,测试运行得很好(没有奇怪的例外)。
发布于 2013-04-16 15:41:08
似乎某些提供运行NUnit单元测试功能的应用程序的TestContext类有问题。
下面类中的测试应该通过:
using NUnit.Framework;
namespace UnitTests
{
[TestFixture]
public class UnitTests
{
[Test]
public void CurrentContextTest()
{
Assert.IsNotNull(TestContext.CurrentContext);
Assert.IsNotNull(TestContext.CurrentContext.TestDirectory);
Assert.IsNotNull(TestContext.CurrentContext.WorkDirectory);
}
}
}如果测试没有通过,那么,就像德米特里在上面的评论中写的那样,在ReSharper菜单中更改NUnit版本。在Visual Studio中,转到ReSharper ->选项-> Tools -> NUnit。单击specified NUnit installation单选按钮,并确保指定了包含nunit.core.dll、nunit.core.interfaces.dll和nunit.util.dll的文件夹。如果找不到列出的文件,则会显示错误。

更改NUnit版本后,重新运行测试,测试应该会通过。
https://stackoverflow.com/questions/16014936
复制相似问题