Skip to main content

Tags and test information

Tags​

Use [BDTestTag] from BDTest on a scenario method or a story class. Apply it several times for several tags.

Illustrative fragment
[BDTestTag("checkout")]
public class CheckoutTests : TUnitBDTestBase<CheckoutContext>
{
[Test]
[BDTestTag("smoke")]
[BDTestTag("payments")]
public async Task SuccessfulCheckout()
{
await Given(() => Basket.HasItems())
.When(() => Checkout.Pay())
.Then(() => Orders.OrderIsPlaced());
}
}
  • Class tags apply to every scenario in the class, including tags inherited from base classes.
  • Method tags combine with class tags. Duplicates are removed, ignoring case.
  • Tag names are trimmed and cannot be empty.

Tags are available on BuildableTest.Tags and immutable ScenarioResult.Tags snapshots and are written to JSON output, including for tests that did not run.

On the report server's Scenarios page, pick a tag to filter scenarios before grouping and paging. Tag matching ignores case and combines with the status filter. Choose All tags to clear the filter.

Scenario tags are separate from the run-level BDTestRunDescriptor.Tag, which labels a whole test run. See Sending results.

Using tags in rules​

Tags are on the Scenario, so a run skip rule can use them:

Illustrative fragment
options.SkipTestRules.Add(scenario =>
scenario.Tags.Contains("slow") && Environment.GetEnvironmentVariable("RUN_SLOW_TESTS") != "true");

Test information​

[TestInformation] attaches extra text to a scenario in the report, for example a bug reference or a link to a requirement. You can apply it several times.

Illustrative fragment
[Test]
[TestInformation("Regression test for bug #12345")]
public async Task Test1()
{
...
}

Custom information attributes​

Subclass TestInformationAttribute to build reusable attributes:

Illustrative fragment
public class BugInformationAttribute : TestInformationAttribute
{
public BugInformationAttribute(string bugNumber)
: base($"Bug #{bugNumber} - https://bugs.example.com/{bugNumber}")
{
}
}

[Test]
[BugInformation("12345")]
public async Task Test1()
{
...
}

Static HTML reports show each entry's text under the generic Information label. Executed BDTest.Contracts.ScenarioResult.CustomTestInformation and pending BDTest.Contracts.ScenarioDefinitionSummary.CustomTestInformation expose read-only collections of information strings, also used by schema-versioned JSON reports.

Result snapshots and pending summaries do not retain custom attribute instances, additional members, type names or Print() behavior. Include any identifying label in the attribute's Information text, as the BugInformationAttribute example does. Builders retain their attribute instances; report consumers read strings. Historical reports retain their legacy model. See Immutable results migration and Scenario definitions migration.

Method tags and test information are read from the exact method supplied by the adapter lifecycle, not from helpers on the call stack. Class tags are combined with method tags. Standalone builders need an explicit method identity to use method attributes.

Each scenario receives newly constructed test information attributes. Mutable arrays or collections in a custom attribute belong to that scenario; changing them does not change another scenario or the cached method metadata.