onsi / ginkgo

A Modern Testing Framework for Go
http://onsi.github.io/ginkgo/
MIT License
8.09k stars 643 forks source link

Support for KeyValue atttributes in specs #1335

Closed nonsocode closed 3 months ago

nonsocode commented 6 months ago

Gingko nodes currently support label nodes but these label nodes only accept string values. A great addition would be support for key-value attribute nodes. This could open up more options for reporters E.g, The JUnit reporters could be able to use this to add attributes like owner to the testcase xml node.

onsi commented 6 months ago

Are there other usecases? or is this a request for adding an Owner decorator for junit? my hesitation is it would then be natural to want to filter specs by key:value pairs. or by specs with key Y with value X but not key Z. all to say that it would naturally expand the scope of the filtering language which i’d prefer not to do….

nonsocode commented 6 months ago

Yes the main use case is for the Owner attribute. We have a large codebase owned my multiple different teams. It would be great if the owner attribute is present on specs so it's easy to identify who owns a spec. The owner attribute is natively supported in Azure devops pipelines as seen here

onsi commented 5 months ago

great, thanks @nonsocode . I could imagine that after adding an Owner decorator there will quickly be requests for implementing filtering specs by Owner. One idea that comes to mind is to teach the JUnit reporter to look for special labels and interpret them. So, for example, the first label matching Label(“owner:.*”) could be detected by the reporter and interpreted as the owner for the spec. I think i’d be up for that and documenting it as a feature of the junit reporter. This way the existing filtering mechanisms would still apply. WDYT?

nonsocode commented 5 months ago

Yes I think that's a great alternative. I'm happy with this idea

onsi commented 5 months ago

alright - this is now on master. i'll be cutting a release soon. you can now set Label(owner:X) and X will get set to the Owner attribute of the test case. if you could give it a try and make sure it works for you end-to-end on azure devops that would be great.

nonsocode commented 3 months ago

This works great. Thank you