Skip to content

frederic-prusse/XUnitPriorityOrderer

Repository files navigation

XUnitPriorityOrderer

Order test cases and collections using xunit (ITestCaseOrderer, ITestCollectionOrderer)

Based in the guideline of tomdupont with some minor changes to get the collection order in project's assemblies that import the nuget

How to use

Add/Download the package XUnitPriorityOrderer from nuget.org

dotnet add package XUnitPriorityOrderer --version 1.0.3

set a base test class adding the required parameters (TestCollectionOrderer and TestCaseOrderer) following the sample:

using Xunit;
using XUnitPriorityOrderer;

// set to be sequential execution
[assembly: CollectionBehavior(DisableTestParallelization = true)]
// addset the custom test's collection orderer
[assembly: TestCollectionOrderer(CollectionPriorityOrderer.TypeName, CollectionPriorityOrderer.AssembyName)]

namespace MyTestsNameSpace
{
    // set the custom test's case orderer
    [TestCaseOrderer(CasePriorityOrderer.TypeName, CasePriorityOrderer.AssembyName)]
    public class MyBaseTestClass { }
}

And set the order of your tests, following the sample

using Xunit;
using XUnitPriorityOrderer;

namespace MyTestsNameSpace
{
    // Set collection order
    [Order(5)]
    public class MyTestClass : MyBaseTestClass
    {
        // Set case order
        [Fact, Order(2)]
        public void Test2() {}

        // Set case order
        [Fact, Order(1)]
        public void Test1() {}
    }
}