tags:

views:

91

answers:

1

I generated unit tests on a generic class in VS 2008 and it used the type GenericParameterHelper in all of the places that a generic type was used. Is this a placeholder that should be replaced or does it have some use? What are the uses if any?

Here's one of the tests it generated as an example:

/// <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>();
}
+1  A: 

Let's say you have a class:

public class Foo<T>
{
    public bool DoSomething()
    {
        return false;
    }

    public T DoSomethingElse()
    {
    // ...
}

Now you want to test DoSomething. First you have to instantiate Foo. You can't do:

var foo = new Foo<T>();

You have to use a real type. But T isn't used in the method, so it's noise in the test. So you can do:

var foo = new Foo<GenericParameterHelper>();

...which stands, more or less, for "any old type."

Craig Stuntz
Should've called it `AnyType` then, or something. Much shorter :P
Svish
So they're basically a placeholder? Good to know.
Bryan Anderson
"This class is a placeholder for use with generics. It helps you test generic types by letting you pass non-specific type arguments." http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.genericparameterhelper.aspx
Craig Stuntz
It also adds the Data property so I thought it might be useful for something.
Bryan Anderson