How will you unit test a function containing a hash table data type?

My project generates multiple values โ€‹โ€‹(equal split method) for each data type, getting the minimum and maximum values. I generate these values โ€‹โ€‹for functional testing, I actually pass these values โ€‹โ€‹to the partner nunit, max and min are applicable to int, float, double, etc. These values โ€‹โ€‹are test data.

I originally generated them for basic data types such as int, float, double, string, etc.

Now I need to support data types such as DataSet, HashTable and other collections.

public DataSet MySampleMethod(int param1, string param2, Hashtable ht) 

To test this function, I can pass values โ€‹โ€‹for int and string, but how can I pass test data for ht or as test data generated for a hash table?

+4
source share
1 answer

You need to abstract the hash table implementation from the code so that it can be mocked, entered, or chopped during unit testing.

Just create an interface called IHashTable, and then create your specific implementation by implementing the interface. Then make all your classes that use hashtables, now use IHashTable. Then add a parameter to your constructors, which include IHashTable.

Then, when you test unit testing in the layout or stub of the IHashTable interface.

Mocking: http://en.wikipedia.org/wiki/Mock_object

+2
source

All Articles