我正在使用Nancy
的版本1.2和Nancy.Testing
通过NuGet
编写测试。我的测试用NUnit
2.6.4编写,看起来像这样:
[Test]
public async Task ShouldReturnSuccessfullyAuthenticatedUser()
{
// arrange
var request = CreateRequest();
var userDocument = CreateUserDocumentFrom(request);
await userRepository.AddAsync(userDocument);
// act
var response = browser.Post(Paths.Login, with => with.JsonBody(request));
// assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
}
我有这个例外:
System.TypeInitializationException : The type initializer for 'Nancy.Bootstrapper.AppDomainAssemblyTypeScanner' threw an exception.
----> System.IO.DirectoryNotFoundException : Could not find a part of the path 'E:\myProject\bin\Debug\bin\Debug'.
我认为将Nancy.Testing
与NUnit
一起使用会出现问题,因为xUnit
中的等效测试运行得很好。
答案 0 :(得分:2)
看起来NUnit
正在尝试自动将bin\Debug
添加到bin路径。我解决它的方法是明确指定使用哪种bin路径。这是.nunit
项目文件:
<NUnitProject>
<Settings activeconfig="Debug" />
<Config name="Debug" binpathtype="Manual">
<assembly path="bin/Debug/MyUnitTests1.dll" />
<assembly path="bin/Debug/MyUnitTests2.dll" />
</Config>
<Config name="Release" binpathtype="Manual">
<assembly path="bin/Release/MyUnitTests1.dll" />
<assembly path="bin/Release/MyUnitTests2.dll" />
</Config>
</NUnitProject>
XML属性NUnitProject\Config\binpathtype
之前的值为Auto
。当我将其更改为Manual
时,异常消失,我的测试成功运行。