Good question, I often think about it and had this problem the other day. What I did is how the basics of our collection work using the vocabulary behind the scenes. For instance:
public class MyCollection { private IDictionary<string, int> backingStore; public MyCollection(IDictionary<string, int> backingStore) { _backingStore = backingStore; } }
Then we check the implementation of the add. Since we had a dictionary by reference, we could argue that after adding the elements, our business logic was correct.
For example, the pseudo code for the addon was something like this:
public void Add(Item item) {
Then one could write a test:
var subject = new MyCollection(backingStore); subject.Add(new Item()) Assert.That(backingStore.Contains(itemThatWeAdded)
Then we continued to supplant other methods, such as search and delete.
Your question is what you should do with regard to hacking addition, in turn, interrupting the search. This is a trick scenario 22. Personally, I would rather cut out a back-up store and use it as an implementation detail. So that’s what we did. We reorganized the tests for using the system under test, and not for the backup storage for claims. The great thing is that the backup storage is public initially, it allows you to test small parts of the code, rather than performing both adding and searching at a time.
The test to be added then looked like this after we reorganized the collection so as not to expose the backup storage.
var subject = new MyCollection(); var item = new Item() subject.Add(item) Assert.That(subject.Has(item), Is.True);
In this case, I think that everything is in order. If you cannot add items successfully, then you are sure that the devil cannot get anything because you did not add them. As long as your tests are called well, any developer who sees some tests, such as " CanOnlyAddUniqueItemsToCollection
", will point future developers in the right direction, in other words, the addition will be broken. Just make sure your tests are well-named and you should give as much help as possible.