Skip to content
Sean McAdams edited this page Mar 23, 2016 · 5 revisions

#XUnit Custom Traits

The XUnit trait attribute is fantastic, it makes for an easy way to group and run (through the command line) tests. However unlike many unit tests, UI automation tests often require many tags, and having one line for each is kind of a pain.

Because of this the CustomTrait attribute is included in the Aliases.Executors.XUnit package.

This trait allows for semi-colon (;) delimited traits to be added to tests via an attribute.

I don't want semi-colons, i like commas, seriously, i love commas.

If you don't like my version just copy it and make your own.

Making custom traits for XUnit is not a very well documented feature (at the time of me writing this). But there are two parts to it:

  1. An ITraitDiscoverer, This does the majority of the work and actually parses the trait values.
  2. An ITraitAttribute, This is how XUnit finds your trait and uses it.

And that's it, you are on your way to making custom trait attributes. You could even populate the values from a database if you really wanted to.

Clone this wiki locally