What makes a good error message for testunit or other nunit style frameworks?

In Ruby test / unit and other similar nunit style frames, what makes a good error message?

If the error message simply describes how the expected value does not match the expected value?

assert_match("hey", "hey this is a test", "The word does not exist in the string") 

Should he describe what you expected?

 assert_match("hey", "hey this is a test", "I expected hey to be in the string") 

Should he describe why you want the behavior to happen?

 assert_match("hey", "hey this is a test", "Program should provide a greeting") 

Should he describe why you thought the test might fail?

 assert_match("konnichiwa", "konnichiwa this is a test", "Program failed to use supplied i18n configuration") 

If test information also exists in the name of the test method and in the name of the test case?

This is based on Ruby's "test / unit", how do I display posts in statements

+4
source share
1 answer

The error message should add context to the error message. So all that saves you, you need to deploy in the test code to find out what failed.

So, if the [method name, expected, actual] set is adequate for the above purpose, you can skip the error message. If you need more information, add an additional error message.

eg. Expected true but was false , doesn't tell me anything.

You can use the error message so that Return value should contain only multiples of 10. Expected true but was false

You can try using more descriptive matches first. So the errors read by Expected all items to be divisible by 10 but was [10,20,35,40] , really.

Personally, I prefer coincidences ... using failure messages as a last resort. (because, like comments, it breaks up. You need the discipline to update the error message if you change the check.)

+2
source

Source: https://habr.com/ru/post/1385809/


All Articles