Skip to content

Commit 1d8126f

Browse files
authored
Merge pull request #2 from asherber/default-priority
Default priority
2 parents e5a4dc6 + 4ec1820 commit 1d8126f

20 files changed

+365
-214
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,5 @@ paket-files/
258258

259259
# Python Tools for Visual Studio (PTVS)
260260
__pycache__/
261-
*.pyc
261+
*.pyc
262+
**/launchSettings.json

Directory.Build.props

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<PackageReference Include="Nerdbank.GitVersioning">
5+
<Version>3.0.24</Version>
6+
<PrivateAssets>all</PrivateAssets>
7+
</PackageReference>
8+
</ItemGroup>
9+
</Project>

README.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![Icon](https://github.com/asherber/Xunit.Priority/raw/master/media/xunit-priority-64.png)
22

3-
# Xunit.Priority [![NuGet](https://img.shields.io/nuget/v/Xunit.Priority.svg)](https://nuget.org/packages/Xunit.Priority)
3+
# Xunit.Priority [![NuGet](https://img.shields.io/nuget/v/Xunit.Priority.svg)](https://nuget.org/packages/Xunit.Priority) [![Build status](https://ci.appveyor.com/api/projects/status/h9kxm1ocxtcvf4iu/branch/master?svg=true)](https://ci.appveyor.com/project/asherber/xunit-priority/branch/master)
44

55
Provides an `ITestCaseOrderer` that allows you to control the order of execution of Xunit tests within a class.
66

@@ -35,9 +35,22 @@ public void ThirdTestToRunB() { }
3535
public void TestsWithNoPriorityRunLast() { }
3636
```
3737

38-
### Notes
38+
Priorities are evaluated in numeric order (including 0 and negative numbers). If there are multiple tests with the same priority, those tests will be run in alphabetical order.
3939

40-
- Priorities are evaluated in numeric order (including 0 and negative numbers)
41-
- Multiple tests with the same priority will be run in alphabetical order
42-
- Tests with no explicit `Priority` attribute are assigned priority `int.MaxValue` and will be run last
40+
By default, tests with no explicit `Priority` attribute are assigned priority `int.MaxValue` and will be run last. You can change this by setting a `DefaultPriority` attribute on your test class.
41+
42+
```csharp
43+
[DefaultPriority(0)]
44+
public class MyTests
45+
{
46+
[Fact]
47+
public void SomeTest() { }
48+
49+
[Fact]
50+
public void SomeOtherTest() { }
51+
52+
[Fact, Priority(10)]
53+
public void RunMeLast() { }
54+
}
55+
```
4356

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Xunit;
7+
using Xunit.Priority;
8+
using FluentAssertions;
9+
10+
namespace Xunit.Priority.Tests
11+
{
12+
public class BasicPriorityTests: TestsBase
13+
{
14+
#pragma warning disable 169
15+
private static bool[] _counter;
16+
#pragma warning restore 169
17+
18+
19+
[Fact, Priority(10)]
20+
public void Test3A() => VerifyAndFlip(2);
21+
22+
[Fact, Priority(-10)]
23+
public void Test1() => VerifyAndFlip(0);
24+
25+
[Fact]
26+
public void Test5() => VerifyAndFlip(5);
27+
28+
[Fact, Priority(0)]
29+
public void Test2() => VerifyAndFlip(1);
30+
31+
[Fact, Priority(20)]
32+
public void Test4() => VerifyAndFlip(4);
33+
34+
[Fact, Priority(10)]
35+
public void Test3B() => VerifyAndFlip(3);
36+
}
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Xunit;
7+
using Xunit.Priority;
8+
using FluentAssertions;
9+
10+
namespace Xunit.Priority.Tests
11+
{
12+
public class NoPriorityTests: TestsBase
13+
{
14+
#pragma warning disable 169
15+
private static bool[] _counter;
16+
#pragma warning restore 169
17+
18+
19+
[Fact]
20+
public void Test3A() => VerifyAndFlip(2);
21+
22+
[Fact]
23+
public void Test1() => VerifyAndFlip(0);
24+
25+
[Fact]
26+
public void Test5() => VerifyAndFlip(5);
27+
28+
[Fact]
29+
public void Test2() => VerifyAndFlip(1);
30+
31+
[Fact]
32+
public void Test4() => VerifyAndFlip(4);
33+
34+
[Fact]
35+
public void Test3B() => VerifyAndFlip(3);
36+
}
37+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Xunit;
7+
using Xunit.Priority;
8+
using FluentAssertions;
9+
10+
namespace Xunit.Priority.Tests
11+
{
12+
[DefaultPriority(int.MinValue)]
13+
public class OnePriorityMinDefaultTests: TestsBase
14+
{
15+
#pragma warning disable 169
16+
private static bool[] _counter;
17+
#pragma warning restore 169
18+
19+
20+
[Fact]
21+
public void Test3A() => VerifyAndFlip(2);
22+
23+
[Fact]
24+
public void Test1() => VerifyAndFlip(0);
25+
26+
[Fact]
27+
public void Test5() => VerifyAndFlip(4);
28+
29+
[Fact]
30+
public void Test2() => VerifyAndFlip(1);
31+
32+
[Fact]
33+
public void Test4() => VerifyAndFlip(3);
34+
35+
[Fact, Priority(10)]
36+
public void Test3B() => VerifyAndFlip(5);
37+
}
38+
}

Xunit.Priority.Tests/PriorityOrdererTests.cs

Lines changed: 0 additions & 95 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Xunit;
7+
using Xunit.Priority;
8+
using FluentAssertions;
9+
10+
namespace Xunit.Priority.Tests
11+
{
12+
[DefaultPriority(int.MaxValue)]
13+
public class PriorityWithMaxDefaultTests: TestsBase
14+
{
15+
#pragma warning disable 169
16+
private static bool[] _counter;
17+
#pragma warning restore 169
18+
19+
20+
[Fact, Priority(10)]
21+
public void Test3A() => VerifyAndFlip(2);
22+
23+
[Fact, Priority(-10)]
24+
public void Test1() => VerifyAndFlip(0);
25+
26+
[Fact]
27+
public void Test5() => VerifyAndFlip(5);
28+
29+
[Fact, Priority(0)]
30+
public void Test2() => VerifyAndFlip(1);
31+
32+
[Fact, Priority(20)]
33+
public void Test4() => VerifyAndFlip(4);
34+
35+
[Fact, Priority(10)]
36+
public void Test3B() => VerifyAndFlip(3);
37+
}
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Xunit;
7+
using Xunit.Priority;
8+
using FluentAssertions;
9+
10+
namespace Xunit.Priority.Tests
11+
{
12+
[DefaultPriority(0)]
13+
public class PriorityWithZeroDefault: TestsBase
14+
{
15+
#pragma warning disable 169
16+
private static bool[] _counter;
17+
#pragma warning restore 169
18+
19+
20+
[Fact, Priority(50)]
21+
public void Test3A() => VerifyAndFlip(5);
22+
23+
[Fact, Priority(-10)]
24+
public void Test1() => VerifyAndFlip(1);
25+
26+
[Fact]
27+
public void Test5() => VerifyAndFlip(3);
28+
29+
[Fact, Priority(0)]
30+
public void Test2() => VerifyAndFlip(2);
31+
32+
[Fact, Priority(-40)]
33+
public void Test4() => VerifyAndFlip(0);
34+
35+
[Fact, Priority(10)]
36+
public void Test3B() => VerifyAndFlip(4);
37+
}
38+
}

Xunit.Priority.Tests/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)