Allure.Net.Commons
2.15.0
Prefix Reserved
See the version list below for details.
dotnet add package Allure.Net.Commons --version 2.15.0
NuGet\Install-Package Allure.Net.Commons -Version 2.15.0
<PackageReference Include="Allure.Net.Commons" Version="2.15.0" />
<PackageVersion Include="Allure.Net.Commons" Version="2.15.0" />
<PackageReference Include="Allure.Net.Commons" />
paket add Allure.Net.Commons --version 2.15.0
#r "nuget: Allure.Net.Commons, 2.15.0"
#:package Allure.Net.Commons@2.15.0
#addin nuget:?package=Allure.Net.Commons&version=2.15.0
#tool nuget:?package=Allure.Net.Commons&version=2.15.0
Allure.Net.Commons
Allure.Net.Commons is a library for creating custom Allure adapters for .NET test frameworks.
- Learn more about Allure Report at https://allurereport.org
- 📚 Documentation – discover official documentation for Allure Report
- ❓ Questions and Support – get help from the team and community
- 📢 Official announcements – stay updated with our latest news and updates
- 💬 General Discussion – engage in casual conversations, share insights and ideas with the community
- 🖥️ Live Demo — explore a live example of Allure Report in action
The library can be used by any project that targets a framework compatible with .NET Standard 2.0 (.NET Framework 4.6.1+, .NET Core 2.0+, .NET 5.0+, and more). See the complete list here.
Note for users of Mac with Apple silicon
If you're developing on a Mac machine with Apple silicon, make sure you have Rosetta installed. Follow this article for the instructions: https://support.apple.com/en-us/HT211861
You may also install Rosetta via the CLI:
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
Configuration
The Allure lifecycle is configured via a JSON file with the default name
allureConfig.json. NuGet package installs allureConfig.Template.json, which
you can use as an example. There are two ways to specify config file location:
- Set the ALLURE_CONFIG environment variable to the full path of the file.
- Add
allureConfig.jsonto the project and ensure it's copied to the project output directory next toAllure.Net.Commons.dll:<ItemGroup> <None Update="allureConfig.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> </ItemGroup>
The Allure lifecycle will start with the default configuration settings if no allureConfig.json is provided.
The unparsed configuration can be accessed via
AllureLifeCycle.Instance.JsonConfiguration. Adapters can use it to read
extended configuration properties they need. Check an example
here.
The parsed configuration object can be accessed via
AllureLifeCycle.Instance.Configuration.
An example of the configuration file is provided below:
{
"allure": {
"directory": "allure-results",
"title": "custom run title",
"links":
[
"https://example.org/{link}",
"https://example.org/{issue}",
"https://example.org/{tms}"
],
"failExceptions": [
"MyNamespace.MyAssertionException"
]
}
}
The directory property defaults to "allure-results".
All link pattern placeholders will be replaced with the URL value of the corresponding link type. Given the configuration above, the following transformation will be made:
link(type: "issue", url: "BUG-01") => https://example.org/BUG-01
failExceptions must be an array of strings, each representing the full name of
an exception type. If an unhandled exception occurs whose type matches one of
the provided types, the test/step/fixture is considered failed. Otherwise, it's
considered broken. An exception's type matches a name if:
- Its full name equals the provided name, OR
- One of its base classes matches the name, OR
- It implements an interface that matches the name.
Attribute API
Use the attributes defined in the Allure.Net.Commons.Attributes namespaces:
| Attribute | Effect | Apply to | Notes |
|---|---|---|---|
[AllureAfter] |
Creates a tear down fixture from the method call. | Method. | Uses AspectInjector under the hood. |
[AllureAttachment] |
Creates an attachment from the method's return value. | Method. | Only supports string and byte[] return types. Uses AspectInjector under the hood. |
[AllureBddHierarchy] |
Adds the epic, feature, and story labels to test results at once. |
Method, class, interface. | This is a shorthand for [AllureEpic], AllureFeature, and [AllureStory]. |
[AllureBefore] |
Creates a setup fixture from the method or constructor call. | Method, constructor. | Uses AspectInjector under the hood. |
[AllureDescription] |
Sets a description of test results. | Method, class, interface. | If applied multiple times with Append set, all the strings are joined with \n\n. |
[AllureDescriptionHtml] |
Sets a description of test results in raw HTML. | Method, class, interface. | If applied multiple times with Append set, all the strings are joined (no separator used). |
[AllureEpic] |
Adds the epic label to test results. |
Method, class, interface. | Discards the default BDD hierarchy. |
[AllureFeature] |
Adds the feature label to test results. |
Method, class, interface. | Discards the default BDD hierarchy. |
[AllureId] |
Applies the ALLURE_ID label to test results. |
Method. | - |
[AllureIssue] |
Adds an issue link to test results | Method, class, interface. | If a short ID is used instead of a full URL, a link template must exists in the config. |
[AllureLabel] |
Adds a custom label to test results. | Method, class, interface. | - |
[AllureLink] |
Adds a link to test results. | Method, class, interface. | If a short ID is used instead of a full URL, a link template must exists in the config. |
[AllureMeta] |
Applies a custom set of attributes to test results. | Method, class, interface. | See #406. |
[AllureName] |
Sets a display name of test results. | Method, class, interface. | When applied to a test class, affects the value of the default suite label created from this class. |
[AllureOwner] |
Applies the owner label to test results. |
Method, class, interface. | - |
[AllureParameter] |
Affects how method arguments are converted to Allure parameters. | Parameter. | Allows for ignoring the parameters, see #482. |
[AllureParentSuite] |
Applies the parentSuite label to test results. |
Method, class, interface. | Discards the default suite hierarchy. |
[AllureSeverity] |
Applies the severity label to test results. |
Method, class, interface. | - |
[AllureStep] |
Creates Allure steps from method calls. | Method. | Uses AspectInjector under the hood. |
[AllureStory] |
Applies the story label to test results. |
Method, class, interface. | Discards the default BDD hierarchy. |
[AllureSubSuite] |
Applies the subSuite label to test results. |
Method, class, interface. | Discards the default suite hierarchy. |
[AllureSuite] |
Applies the suite label to test results. |
Method, class, interface. | Discards the default suite hierarchy. |
[AllureSuiteHierarchy] |
Applies the parentSuite, suite, and subSuite labels at once. |
Method, class, interface. | This is a shorthand for [AllureParentSuite], [AllureSuite] and [AllureSubSuite]. |
[AllureTag] |
Applies the tag labels to test results. |
Method, class, interface. | - |
[AllureTmsItem] |
Applies a TMS item link to test results | Method, class, interface. | If a short ID is used instead of a full URL, a link template must exists in the config. |
Most of the attributes are straightforward and can be applied on a method, class, or interface:
- When applied to a method, they affect test results produced by this method.
- When applied to a class, they affect test results produced by all methods of this class and its subclasses.
- When applied to an interface, they affect test results produced by all methods of classes that implement the interface.
AOP attributes
Applying [AllureStep] automatically wraps method calls into Allure step. Call arguments are automatically converted to Allure parameters.
Similarly, [AllureBefore] and [AllureAfter] wrap method calls into fixtures. Apply these to
setup/teardown methods that are invoked by the framework to add fixtures to the report.
Apply [AllureAttachment] to a method that returns string, byte[], System.IO.Stream,
or async versions of these types (e.g., Task<string>) to automatically attach returned values
each time the method is called.
Apply [AllureAttachmentFile] to a method that returns string, FileInfo, or async versions
of these types (e.g., Task<string>) to automatically attach files on each call. The returned
values are treated as file paths.
All four attributes mentioned above requires rely on AspectInjector. If you disable AspectInjector
(e.g., by setting the AspectInjector_Enabled MSBuild property to false), the attributes won't
do anything.
Controlling parameters
There are two contexts where Allure automatically converts method arguments into Allure parameters:
- When creating a test result.
- When creating a step result.
In both contexts, [AllureParameter] can be used to affect the conversion:
- Set
Ignoredto skip the argument. - Use
Nameto explicitly name the parameter. - Use
Modeto mask or hide the value (the original value will still exist in the result files). - Set
Excludedto ignore the parameter when identifying the test that corresponds to the test result (see here).
Example: