Does generic NET suite of ICollection/IEnumerable/IList testing unit tests exist?
I'm looking for a set of generic unit tests that will cover the bases for implementors of one (or more) of the .NET collection interfaces. I'm sure it's been done many times before, and there's no point in rolling it again, right? I don't开发者_StackOverflow社区 care if it's NUnit, MSTest, C#, VB etc. I can adapt.
Microsoft Pex has great support for that. It has standard tests for framework built-in interfaces in it which check the semantic contract. This is what you want. If you invest 3h of learning Pex you will not regret it.
This is TDD at its best. Write the test first and Pex will adapt to your implementation until the very last bug has been found. An empty implementation is perfectly testable with pex. It will just find an error very quickly, that is all.
You can factor out all your common testing logic for a particular interface. Pex even supports generic tests which means you can write a test for an arbitrary instance of IComparer and say: run this test with the following types.
精彩评论