【发布时间】:2019-07-02 18:26:48
【问题描述】:
我正在使用 C# 将代码从 .NET-Framework 移动和重构到 .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()'。
【问题讨论】:
-
我最近遇到了这个问题。解决方案是在调用测试运行器时正确配置测试适配器的路径。喜欢:..\packages\MSTest.TestAdapter.1.4.0
标签: c# unit-testing .net-core