unittest "name" {}

apz28 home at home.com
Thu Feb 16 14:22:01 UTC 2023


On Friday, 10 February 2023 at 21:08:38 UTC, Dennis wrote:
> Names on unittests can be useful for documentation, a better 
> message on failure, or to selectively run a specific test. D 
> has no built-in way to name unittests, but the most popular 
> library test runner 
> ([silly](https://code.dlang.org/packages/silly)) uses the first 
> string UDA as a name:
>
> ```D
> @("Johny")
> unittest {
> 	// This unittest is named Johny
> }
> ```
>
> This isn't too pretty though, and typing parentheses and quotes 
> is annoying (using a QWERTY keyboard with US-layout).
>
> I was thinking it could be improved by either allowing 
> `@"string"` attributes, similar to `@identifier`, or by 
> allowing a string literal after the `unittest` keyword:
>
> ```
> unittest "Johny" {
>     // Has @("Johny") as first UDA
> }
> ```

module sample;

class X { void foo() {} }

Refer below form -> it can be expanded with addition attribute(s) 
in future with consistent structure
unittest(name="good", document="class X")
{}
unittest(name="good", document="class X.foo")
{}

name = name of unittest
document = generate document for class X
            generate document for function class X.foo


for running test
unitttest=name:"good"
unittest=module:"sample"

name = only run unittest with matching name "good"
module = only run unittest(s) for module "sample"





More information about the Digitalmars-d mailing list