unittest "name" {}

ProtectAndHide ProtectAndHide at gmail.com
Thu Feb 16 23:33:51 UTC 2023


On Thursday, 16 February 2023 at 17:26:20 UTC, bachmeier wrote:
>
> My opinion is that naming a unit test is the wrong approach. If 
> the condition for an `enforce` statement fails, it returns an 
> informative message, not a name attached to the `enforce` 
> statement. Along those lines, I would prefer this:
>
> ```
> unittest {
>   onFailure("Comparison of transformations failed");
>   ...
> }
> ```
>
> Naming unit tests would open up other issues. Would you allow 
> recycling of names? There's no reason you couldn't have 
> variable foo and unittest foo, but that would be confusing to 
> someone learning the language. Would you have to use unique 
> unittest names if you import 30 modules written by someone 
> else? This could probably be resolved without great difficulty 
> at the level of language design, but it's all added complexity 
> that you shouldn't deal with when learning a language.

If one wants to identify the purpose of a particular unittest, 
then naming it makes sense.

Searching for some attribute within the unittest itself (e.g 
onFailure("...")) is not the correct approach to solving this 
particular problem.

Imagine your suggested approach as being the approach for a type, 
such as:

class()
{
   classID := "This class is for the purposes of creating a car 
object";
}

No. I prefer to name my class.

I'd prefer to name my unittest also.





More information about the Digitalmars-d mailing list