jeudi 30 juillet 2015

Writing a test assertion message

I figure there are two ways you can write an assertion message in a unit test.

You can either state what the assertion is doing.

assertEquals("Validating that the sum of 2 and 2 is equal to 4.", sum(2, 2), 4);

Or you can state what failed.

assertEquals("The sum of 2 and 2 is expected to be 4.", sum(2, 2), 4);

These are fairly simple examples but hopefully they convey the difference in language. In my opinion the first example just restates what should be obvious based on the test case whereas stating what failed may be able to give some context as to why that assertion is used?

Are either of these correct or incorrect? Is there a standard or a preferred way for writing assertion messages? Does it even matter?

Aucun commentaire:

Enregistrer un commentaire