views:

481

answers:

2

My project generates few values(equal partitioning method) for each data types by getting the Minimum and Maximum values. i am doing this generating values for functional testing ,i am actually passing this values to nunit partner ,max amd min are applicable to int ,float ,double etc ..these values are test data .

Initially i generated for basic data types like int, float, double, string etc.

Now i need to support data types like DataSet, HashTable and other Collections.

public DataSet MySampleMethod(int param1, string param2, Hashtable ht) for testing this fuctions i can pass values for int and string but how will i pass test data for ht or how is test data generated for hash table

A: 

You should not use random data at all for unit testing. A test may pass or fail randomly depending on the data chosen, and when you try to find out why it failed you may have a very hard time debugging the code because you can't repeat the failure in a predictable way.

Guffa
As long as you seed the randomizer, there is nothing unpredictable about most RNG, and thus can be a reasonable approach for getting uniform (in the probability sense) coverage without having to test each number in the Int32 range, for example. I use this in serialization tests, for example.
Marc Gravell
If you seed the random generator then you don't get random values. :)
Guffa
my questing is what kind of data you need to generate in order to test a function which has hash table has data type
Arunachalam
@Guffa - no, but you can generate a wide spread of uniformly distributed values, to provide a smoke-test without having to test every possible value.
Marc Gravell
+2  A: 

First - I always seed my random values for unit tests, so that hey are repeatable - however, something like (using Dictionary<,> instead of HashTable, but equivalent):

        Random rand = new Random(123456); // note seed
        Dictionary<int, double> lookup = new Dictionary<int, double>();
        for (int i = 0; i < 5000; i++)
        {
            lookup[rand.Next(100000)] = rand.NextDouble();
        }
Marc Gravell