强制 MonoDevelop“运行测试”在特定的运行时间下
我们的大量单元测试在 OS X 上的 Mono 下失败,并出现以下错误:
System.TypeLoadException : Could not load type 'System.Func``2' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
在有问题的单元测试中:
[Test]
public void CanAuthenticateValidUser()
{
const string testUsername = "jappleseed";
var repo = new Mock<IUserRepository>();
repo.Setup(x => x.GetByUsername(testUsername)).Returns(GetTestUser());
var authenticator = new Authenticator(repo.Object);
var result = authenticator.Authenticate(testUsername, "test");
Assert.That(result, Is.True);
}
使用 MonoDevelop 2.4 运行 Mono 2.8。
有人有任何建议来解决这个问题吗?
编辑:
应该指出此错误来自 MonoDevelop 中“单元测试”板中内置的“运行测试”命令。
编辑 2:
强制运行时按照 jpobst 建议在控制台中运行。我想问题已经变成了如何让 MonoDevelop 在特定框架下展示运行测试?
shimms:Debug shimms$ mono ~/Development/nunit/bin/net-2.0/nunit-console.exe Convergence.Core.Services.Tests.dll
抛出相同的异常,但是:
shimms :Debug shimms$ mono --runtime=v4.0.30319 ~/Development/nunit/bin/net-2.0/nunit-console.exe Convergence.Core.Services.Tests.dll
所有测试通过
A heap of our unit tests are failing under Mono on OS X with the following error:
System.TypeLoadException : Could not load type 'System.Func``2' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
On of the unit tests in question:
[Test]
public void CanAuthenticateValidUser()
{
const string testUsername = "jappleseed";
var repo = new Mock<IUserRepository>();
repo.Setup(x => x.GetByUsername(testUsername)).Returns(GetTestUser());
var authenticator = new Authenticator(repo.Object);
var result = authenticator.Authenticate(testUsername, "test");
Assert.That(result, Is.True);
}
Running against Mono 2.8, with MonoDevelop 2.4.
Anyone got any suggestions to get around this?
Edit:
Should point out this error is coming from the inbuilt "Run Tests" command in the "Unit Tests" pad in MonoDevelop.
Edit 2:
Forcing the runtime as per jpobst suggestion runs in the console. I guess the question has become how does one get MonoDevelop to exhibit run tests under a specific framework?
shimms:Debug shimms$ mono ~/Development/nunit/bin/net-2.0/nunit-console.exe Convergence.Core.Services.Tests.dll
Throws the same exceptions, however:
shimms:Debug shimms$ mono --runtime=v4.0.30319 ~/Development/nunit/bin/net-2.0/nunit-console.exe Convergence.Core.Services.Tests.dll
All tests pass
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有一个名为“mscorelib”的程序集,它是“mscorlib”。这是一个错字吗?或者参考损坏了?
第二次尝试:
您确定您的测试是针对 4.0 (dmcs) 编译的吗?
您还可以尝试使用以下命令覆盖运行时:
mono --runtime=v4.0.30319 mytests.exe
There isn't an assembly called "mscorelib", it's "mscorlib". Is that a typo? Or a broken reference?
Second try:
Are you sure your tests were compiled against 4.0 (dmcs)?
You can also try overriding the runtime with:
mono --runtime=v4.0.30319 mytests.exe