我试图将 .Net Core 控制台应用程序和测试从 2.1 迁移到 3.1,但在我的测试中遇到了问题。我正在使用Moq图书馆,它工作正常。迁移后,我开始A non-collectible assembly may not reference a collectible assembly尝试访问任何模拟对象。我在全新的项目中重现了相同的行为。我无法找到有关此主题的任何相关信息。我已经用MSTest和测试了它Xunit。这是一个Moq库问题还是 .Net Core 3.1 应该对这种情况使用不同的方法?
using Moq;
using Xunit;
namespace NetCore3.Tests
{
public interface IMyInterface{ }
public class UnitTest
{
[Fact]
public void Test()
{
var mock = new Mock<IMyInterface>();
var tmp = mock.Object; // this line throwing exception
}
}
}
Run Code Online (Sandbox Code Playgroud)
例外:
NetCore3.Tests.UnitTest.Test
System.NotSupportedException: A non-collectible assembly may not reference a collectible assembly.
System.NotSupportedException
A …Run Code Online (Sandbox Code Playgroud)