Reputation: 15475
I have a simple task to display a fruit object based on certain conditions. For example, if I need to show a banana I need to make sure the other fruits don't display.
For simplicity's sake, let's say they are 4 possible fruits. Do I need to test all the possible combinations?
Test1 if banana not strawberry
Test2 if banana not apple
Etc.
Upvotes: 1
Views: 72
Reputation: 549
This depends on things such as if your code is even capable of displaying more than one fruit at once (by accident or otherwise). The extremely safe choice would be "Yes, test everything!"
Upvotes: 0
Reputation: 13409
Depends on few things. But one way would be just to make sure you only have banana when you expect a banana. I'm sure there are differences between types, so you can assert on that (eg. assert names of all objects are "banana" only).
Upvotes: 1
Reputation: 81724
You need to test as many combinations as there are code paths, for sure. If there's no strawberry-specific or apple-specific code, then you don't need to test both banana v. strawberry and banana v. apple. But if there's different code for a given fruit, you need to test it, as well as one of the others; and if there's different code based on the number of fruits, then you need to test 0, 1, 2, N-1, N, and N+1, whatever the largest value of N is. In general, you need to test enough to convince yourself additional tests wouldn't help.
Upvotes: 2