I have a method which has a lot of conditions in it:
public bool IsLegalSomething(Order order)
{
var item0 = order.Items.SingleOrDefault(x => x.ItemCode == "ItemCode0");
var item1 = order.Items.SingleOrDefault(x => x.ItemCode == "ItemCode1");
...
var itemN = order.Items.SingleOrDefault(x => x.ItemCode == "ItemCodeN");
return ((item0.Status == Status.Open) && (item1.Status == Status.Closed)
&& ...
&& (itemN.Status == Status.Canceled));
}
I want to unit test this function, but there are so many conditions that the number of unit tests is crazy if you consider every combination. There are 16 conditions in that return statement, and since each condition is true/false that is 2^16 different combinations I would need to check on. Do I really need to create 2^16 different unit tests here to ensure that every condition is utilized? Mind you, this is a simple example. Some of my functions have complex conditions due to legal requirements:
return (condition0 && condition1 && (condition2 || condition3)
&& (condition4 || (condition5 && condition6)) ...)
By the math of some of my functions, the number of different combinations that the conditions can produce is millions! I looked into Data-Driven Unit Tests (DDUT), as well as Parameterized Unit Tests (PUT), but that just makes it so that the unit test is a "fill in the blanks" style. I still have to supply all of the various combinations and the expected result! For example:
// Parameterized Unit Test
[TestCase(..., Result = true)] // Combination 0
[TestCase(..., Result = true)] // Combination 1
[TestCase(..., Result = false)] // Combination 2
public bool GivenInput_IsLegalSomething_ReturnsValidResult(...) { }
If I use MSTest to pull in a datasource (csv for example), I still have the same problem. I have way too many combinations that give different results. Is there an alternative I just am unaware of?