我正在使用 C# 将代码从 .NET-Framework 移动并重构为 .NET-Core。当我对应该对列表进行排序的方法运行简单测试时,出现以下错误:
"System.MissingMethodException: Method not found: 'System.Collections.IDictionary Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.get_Properties()'."
我已经检查了对其他必要命名空间的引用。网上搜了一下错误,发现.NET Core中还没有提供TestContext类!我可以使用其他方法或替换库吗?谢谢。
[TestMethod]
public void TestMethod()
{
// Arrange
// Grab an arbitrary start time.
Time startTime = Time.Now;
List<TimeValue> values = new List<TimeValue>
{
// Make sure that second timestamp comes before the first
timestamp
new TimeValue(startTime.PlusMinutes(1)),
new TimeValue(startTime)
};
// Ensure that this is sorted in ascending order of time.
List<TimeValue> expectedValues = values.OrderBy(value =>
value.Timestamp).ToList();
CollectionAssert.AreNotEqual(expectedValues, values);
// Act
SortArray myObj = new SortArray(values);
// Assert
CollectionAssert.AreEqual(expectedValues, SortArray.Values);
}
我希望 TestMethod 能够运行,但它没有运行并给出以下错误:
'System.Collections.IDictionary Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.get_Properties()'.
最佳答案
您可以使用的一个可能的替代方案是 xUnit 。它是一个开源工具,您可以将其与 .NET Core 一起使用。
微软提供 tutorial关于如何使用 .NET Core 进行 xUnit。
另一种可能性是“dotnet test”,它是 Microsoft 兼容 .NET Core 的单元测试工具。
关于c# - 在 .NET-core 中找不到 TestContext 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56858246/