Friendlier attributes to help categorise your tests.
This is a fork of the Xunit.Categories project. The excellent work of Brendan Connolly - @bredanconnolly.
The project was not getting updated. I reached out to Brendan and did not get a response. So in order to keep the project alive I forked it.
| Branch | Status |
|---|---|
master |
|
develop |
Currently, we support both xUnit v2 and v3. As such, we have two packages:
| Package | NuGet |
|---|---|
| Xunit.OpenCategories | |
| Xunit.OpenCategories.V3 |
The xUnit built in option Traits can get a little messy. Its just 2 strings representing a key and value, unless you are familiar with xUnit and the Trait attribute it looks a little magical.
Also, both key and value must be specified on the command line. This means if you decorate your test with
[Trait("Category","Bug")] you cannot run only tests from a specific bug without adding another trait ([Trait("Bug","8675309"])
| Attribute | Description |
|---|---|
Author |
The person who wrote the test |
Bug |
The bug number associated with the test |
Category |
The category of the test |
Component |
The component of the test |
Components |
The list of components of the test |
DatabaseTest |
A database test |
Description |
The description of the test |
Documentation |
A test case that exist primarily to document how something should work |
Expensive |
A test that is expensive to run |
Exploratory |
For tests that have a exploratory purpose like trying out an unknown API. Not necessarily relating to your own code. |
Feature |
Tests relating to a specific feature |
IntegrationTest |
Integrations tests |
KnownBug |
For failing tests relating to known bugs that should not fail a build |
LocalTest |
For tests that should only be executed locally and excluded from automated pipeline runs |
Services |
A list of services under test |
SnapshotTest |
A snapshot test |
Specification |
A specification test |
SystemTest |
A system test |
TestCase |
A test case |
UnitTest |
A unit test |
UserStory |
A user story |
WorkItem |
A related work item |
Open an issue or pull request to add more.
[Fact]
[Bug]
public void TestBug()
{
throw new NotImplementedException("I'm a bug");
}
[Fact]
[Bug("777")]
public void TestBugWithId()
{
throw new NotImplementedException("I've got your number");
}Using this attribute you get descriptive information and flexibility when running tests. You can run all tests marked as Bugs
xunit.console.exe ... -trait "Category=Bug"
-or via dotnet test
dotnet test --filter "Category=Bug"
or get more granular
xunit.console.exe ... -trait "Bug=777"
-or via dotnet test
dotnet test --filter "Bug=777"