When testing in any language, how does everybody phrase their assertion messages?
I see three obvious ways:
# assume failure
assert (4-2) == 2, "Subtracting 2 from 4 doesn't equal 2"
# describe success
assert (4-2) == 2, "Subtracting 2 from 4 should equal 2"
# be vauge with failure
assert (4-2) == 2, "Subtracting 2 from 4 is broken"
This is obviously a simple example, but you get the idea. What is the standard practice? What do you do? Why?
From a test readability perspective, assertion messages are code comments. Instead of relying on them, refactor tests to be self-documenting. In terms of ease of diagnostics, a better alternative to assertion messages is: Making tests verify a single unit of behavior.
An assertion failure occurs when the database server cannot continue normal processing and must shut down. You can correct some of the problems that cause assertion failures, such as disk issues. For other problems that cause assertion failures, you must contact IBM® Software Support.
An assertion is a true-false statement, a boolean expression, about the values of the variables in a program. In the sequence to the left below, an assertion has been placed in a comment on the second line. The assertion is true at that point.
I don't know what's the standard practice, but I combine your first two approaches with the addition of the actual result obtained.
"Substracting 2 from 4 should equal 2, but equals " + value
This leaves no room for doubt and eases debugging.
The important thing with an assert is the actual condition being tested. In C you can use the preprocessor "stringization" to output the actual condition being tested. My code just outputs
Assert Failed: (4-2)==2 : Line 123, File foo.c
If you're lucky, you can get a stack dump as well...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With