c# - 在 .NET-core 中找不到 TestContext 类
问题描述
我正在将代码从 .NET-Framework 移动并重构为 C# 中的 .NET-Core。当我对应该对列表进行排序的方法运行简单测试时,我收到此错误:
“System.MissingMethodException:找不到方法:'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()'。
解决方案
推荐阅读
- xamarin - How to hide navigation Toolbar icon in xamarin?
- attributes - 如何更改 NSAttributedStringKey.link Swift4 的颜色
- sql - How to group hierarchical relationships together in SQL Server
- system-verilog - 是否有任何工具或 EDA 可以轻松使用 systemverilog?
- pandas - 从 pandas 的行中追加列
- javascript - 地图内的地图数组对象 - ReactJS
- c++ - 功能不停止
- rest - 如何在 spring-integration 中获取 ResponseEntity 主体
- asp.net-mvc - MVC SqlDateTime 溢出。必须在 1753 年 1 月 1 日上午 12:00:00 到 9999 年 12 月 31 日晚上 11:59:59 之间
- php - ajax问题,只显示标题而不显示记录