What object types are best for writing unit tests for generic collections? Obviously if I’m using them in a specific way in my application, it’s best to test with those types. But if I’m not, and simply creating a utility library, which types should I use?
I’m trying to avoid any pitfalls with specific object types. For example, when testing a generic dictionary structure, I know that the GetHashCode and Equals methods are very important in ensuring a valid test. I’m worried that if I simply use dummy object instances (var a = new object();), that I run into problems with these methods not being robust enough.
I’m considering using GUID instances for all of my unit testing, because of their necessarily unique constraints. However, being structs, I cannot test for equivalent references should I need to.
Lastly, are there any other gotchas to watch out for when using a specific object implementation (like object or GUID) in place of generic types for unit test purposes?
If you want to be thorough, you should test with several types:
intEquals+GetHashCodeIEqualityComparer<T>doubleorfloatfor their strangeNaNsemantics.Not every test needs to be done for all of them. But I’d add at least one test for each of them.