NUnit Test Run Order

前端 未结 16 1346
名媛妹妹
名媛妹妹 2020-12-02 11:44

By default nunit tests run alphabetically. Does anyone know of any way to set the execution order? Does an attribute exist for this?

16条回答
  •  天命终不由人
    2020-12-02 12:28

    I'm suprised the NUnit community hasn't come up with anything, so I went to create something like this myself.

    I'm currently developing an open-source library that allows you to order your tests with NUnit. You can order test fixtures and ordering "ordered test specifications" alike.

    The library offers the following features:

    • Build complex test ordering hierarchies
    • Skip subsequent tests if an test in order fails
    • Order your test methods by dependency instead of integer order
    • Supports usage side-by-side with unordered tests. Unordered tests are executed first.

    The library is actually inspired in how MSTest does test ordering with .orderedtest files. Please look at an example below.

    [OrderedTestFixture]
    public sealed class MyOrderedTestFixture : TestOrderingSpecification {
        protected override void DefineTestOrdering() {
            TestFixture();
    
            OrderedTestSpecification();
    
            TestFixture();
            TestFixture();
        }
    
        protected override bool ContinueOnError => false; // Or true, if you want to continue even if a child test fails
    }
    

提交回复
热议问题