With a large, but finite number of test cases Data-Driven Testing is the answer.
... testing done using a table of conditions directly as test inputs and verifiable outputs as well as the process where test environment settings and control are not hard-coded. In the simplest form the tester supplies the inputs from a row in the table and expects the outputs which occur in the same row. The table typically contains values which correspond to boundary or partition input spaces.
You need 1 explicit test where all conditions are true saying "it works".
By using a data driven test, you can test all of the "false" values by parameterizing each boolean field as an input to the test.
How you do this depends on the tech stack and unit testing framework, but it could be reduced down to a test method and a for-loop that iterates over the expected inputs (example in C#, MS Test framework):
[TestClass]
public class ShipTests
{
[TestMethod]
public void ItWorks()
{
var ship = new SpaceShip(true, true, true, true, true);
Assert.IsTrue(ship.isShipAvailable());
}
[TestMethod]
public void ItDoesntWork()
{
var inputs = new bool[][]
{
{ false, true, true, true, true },
{ false, false, true, true, true },
// ...
{ false, false, false, false, false },
};
foreach (var row in inputs)
{
var ship = new SpaceShip(row[0], row[1], row[2], row[3], row[4]);
Assert.IsFalse(ship.isShipAvailable());
}
}
}
Robert Harvey commented on the question:
That said, if you really want tests for this, I think one test with all flags true and one test with one of the flags false really ought to suffice.
It doesn't suffice, because any one flag being false causes the ship to be unavailable. You don't want to test that the warp drive is not available, and say all tests pass if a defect causes the flux capacitor to be unexpectedly offline.
The flux capacitor is important, you know. VERY important. It must be online no matter what -- even more than Facebook!
Otherwise, there's 5 flags here; a fully comprehensive test would require 32 test permutations.
Yes, there are a large number of test cases, but the work required to maintain those tests is minimal if using a data driven test. And if this is all in-memory data manipulation, test execution time is negligible. I think I spent more time writing this answer than all the developers on the team will spend running these tests over the course of the project's lifetime.
isAvailable
when you could simply string together all those&&
clauses? (put each on its own line, starting with&&
)