PriorityTestMethodOrderer Class
Definition
- Namespace
- Codebelt.Extensions.Xunit
- Assemblies
- Codebelt.Extensions.Xunit.dll
Orders test methods by PriorityAttribute, followed by ordinal method name.
public sealed class PriorityTestMethodOrderer : ITestMethodOrderer
- Inheritance
-
PriorityTestMethodOrderer
- Implements
-
ITestMethodOrderer
Examples
Apply the orderer to a test class to run its methods by [Priority(n)]. Negative values run before zero; methods without the attribute run last.
using System;
using Codebelt.Extensions.Xunit;
using Xunit;
using Xunit.Sdk;
namespace Example.Tests;
[TestMethodOrderer(typeof(PriorityTestMethodOrderer))]
public class CacheLifecycleTest : Test
{
private static bool _initialized;
public CacheLifecycleTest(ITestOutputHelper output) : base(output) { }
[Fact, Priority(-1)]
public void ShouldInitializeCache()
{
var orderer = new PriorityTestMethodOrderer();
Assert.Empty(orderer.OrderTestMethods<ITestMethod>(Array.Empty<ITestMethod>()));
_initialized = true;
}
[Fact, Priority(0)]
public void ShouldUseInitializedCache()
{
Assert.True(_initialized);
}
}
Availability: .NET 11, .NET 10 and .NET Standard 2.0
Methods
| Name | Description |
|---|---|
| OrderTestMethods<TTestMethod>(IReadOnlyCollection<TTestMethod>) | Orders methods from the lowest numeric priority to the highest, placing methods without a priority last. |