Use different conditions to test methods

Tagged As:

Let’s say that you have a function that takes an HTML <ul> structure and check items.

For simplicity, our method would check if each item in the list has a link pointing to type of resource (A).

So here can write a test that takes a list with items containing resource A links. Here we expect the function to return true.

But this does not guarantee that the function is working as there is another outcome from the function which false.  So we have to test this by using a list having no item pointing to resource A.

Then we have to think about the situation where we find both type of links that contains non-resource A and resource A links and expect the function to return false.

The importance of this that you test different scenarios. This increases the code reliability and your understanding of the code.