我在 VS 2008 的一个泛型类上生成了单元测试,它使用了 GenericParameterHelper 类型。在所有使用泛型类型的地方。这是一个应该被替换的占位符还是有一些用处?如果有的话有什么用途?
这是它生成的测试之一作为示例:
/// <summary>
///A test for Count
///</summary>
public void CountTestHelper<TKey, TValue>()
{
ObservableDictionary<TKey, TValue> target = new ObservableDictionary<TKey, TValue>(); // TODO: Initialize to an appropriate value
int actual;
actual = target.Count;
Assert.Inconclusive("Verify the correctness of this test method.");
}
[TestMethod()]
public void CountTest()
{
CountTestHelper<GenericParameterHelper, GenericParameterHelper>();
}
最佳答案
假设你有一个类:
public class Foo<T>
{
public bool DoSomething()
{
return false;
}
public T DoSomethingElse()
{
// ...
}
现在你想测试 DoSomething。首先你必须实例化 Foo。你不能这样做:
var foo = new Foo<T>();
您必须使用真实类型。但是该方法中没有使用T,因此它是测试中的噪声。所以你可以这样做:
var foo = new Foo<GenericParameterHelper>();
...它或多或少代表“任何旧类型”。
关于.net - 什么是 GenericParameterHelper,它是如何使用的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1639968/