Testing with arrays, the useful way

We’ve all seen this sometime when a test fails:

Failed assertion, no message given.

Now, I like using arrays in tests because they allow me to test a lot of cases with less code. A simple (and dummy) test could be:

However, when running this test, we will get the quite useless message above: Failed assertion, no message given. Right, we know the test failed, but we don’t know which case made it fail.

We can easily know with an often misused attribute of assert: message. As the docs say, we can pass a message together with an assertion, and it will be used in case of failure.

Now, when running this test, we know that the number 2 makes the test fail. It is so simple, but how often we forget!