When implementing something that implements IDictionary, what should I unit test?
It seems to be overkill to test the entire interface, but then what do I know? I have only been unit testing for a few days...
When implementing something that implements IDictionary, what should I unit test?
It seems to be overkill to test the entire interface, but then what do I know? I have only been unit testing for a few days...
You should test everything you implement. If you have code that is called through the public interface, there should be a unit test that supports that. If you write the code, it is worth testing.
The exception might be simple properties ( Property {get; set;} )
Test all your interface points, but beware the temptation to test the framework.
Every public member of your IDictionary should be tested. You should also set up some tests to ensure that your IDictionary behaves the same as some other concrete implementation of an IDictionary. In fact, you could structure most of your tests like that:
void Test_IDictionary_Add(IDictionary a, IDictionary b)
{
string key = "Key1", badKey = 87;
int value = 9, badValue = "Horse";
a.Add(key, value);
b.Add(key, value);
Assert.That(a.Count, Is.EqualTo(b.Count));
Assert.That(a.Contains(key), Is.EqualTo(b.Contains(key)));
Assert.That(a.Contains(key), Is.EqualTo(a.ContainsKey(key)));
Assert.That(a.ContainsKey(key), Is.EqualTo(b.ContainsKey(key)));
Assert.That(a.ContainsValue(value), Is.EqualTo(b.ContainsValue(value)));
Assert.That(a.Contains(badKey), Is.EqualTo(b.Contains(badKey)));
Assert.That(a.ContainsValue(badValue), Is.EqualTo(b.ContainsValue(badValue)));
// ... and so on and so forth
}
[Test]
void MyDictionary_Add()
{
Test_IDictionary_Add(new MyDictionary(), new Hashtable());
}