NewLife/NewLife.UnitTest

增加DefaultOrderer,默认排序(按方法在类内出现的顺序)
大石头 authored at 2022-03-19 21:00:35
4f8f80f
Tree
1 Parent(s) 9823346
Summary: 5 changed files with 61 additions and 9 deletions.
Added +20 -0
Renamed +3 -3
NewLife.UnitTest/TestOrderer.cs → NewLife.UnitTest/PriorityOrderer.cs
Modified +10 -5
Added +27 -0
Modified +1 -1
Added +20 -0
diff --git a/NewLife.UnitTest/DefaultOrderer.cs b/NewLife.UnitTest/DefaultOrderer.cs
new file mode 100644
index 0000000..11ac905
--- /dev/null
+++ b/NewLife.UnitTest/DefaultOrderer.cs
@@ -0,0 +1,20 @@
+using System.Collections.Generic;
+using Xunit.Abstractions;
+using Xunit.Sdk;
+
+namespace NewLife.UnitTest
+{
+    /// <summary>默认顺序</summary>
+    /// <remarks>
+    /// 默认排序(按方法在类内出现的顺序):
+    /// [TestCaseOrderer("NewLife.UnitTest.DefaultOrderer", "NewLife.UnitTest")]
+    /// </remarks>
+    public class DefaultOrderer : ITestCaseOrderer
+    {
+        /// <summary>对测试用例进行排序</summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="testCases"></param>
+        /// <returns></returns>
+        public IEnumerable<T> OrderTestCases<T>(IEnumerable<T> testCases) where T : ITestCase => testCases;
+    }
+}
\ No newline at end of file
Renamed +3 -3
NewLife.UnitTest/TestOrderer.cs → NewLife.UnitTest/PriorityOrderer.cs
diff --git a/NewLife.UnitTest/TestOrderer.cs b/NewLife.UnitTest/PriorityOrderer.cs
similarity index 93%
rename from NewLife.UnitTest/TestOrderer.cs
rename to NewLife.UnitTest/PriorityOrderer.cs
index 2d0b853..a4c23d2 100644
--- a/NewLife.UnitTest/TestOrderer.cs
+++ b/NewLife.UnitTest/PriorityOrderer.cs
@@ -9,9 +9,9 @@ namespace NewLife.UnitTest
     /// <summary>优先级顺序</summary>
     /// <remarks>
     /// 提供测试用例排序支持:
-    /// [TestCaseOrderer("NewLife.UnitTest.TestOrderer", "NewLife.UnitTest")]
+    /// [TestCaseOrderer("NewLife.UnitTest.PriorityOrderer", "NewLife.UnitTest")]
     /// </remarks>
-    public class TestOrderer : ITestCaseOrderer
+    public class PriorityOrderer : ITestCaseOrderer
     {
         /// <summary>对测试用例进行排序</summary>
         /// <typeparam name="T"></typeparam>
@@ -27,7 +27,7 @@ namespace NewLife.UnitTest
                 var atts = testCase.TestMethod.Method.GetCustomAttributes(assemblyName).ToList();
                 foreach (var att in atts)
                 {
-                    var n = att.GetNamedArgument<Int32>(nameof(TestOrderAttribute.Order));
+                    var n = att.GetNamedArgument<Int32>(nameof(TestOrderAttribute.Priority));
                     if (n != 0) priority = n;
                 }
 
Modified +10 -5
diff --git a/NewLife.UnitTest/TestOrderAttribute.cs b/NewLife.UnitTest/TestOrderAttribute.cs
index 4ee0b98..bae8fe8 100644
--- a/NewLife.UnitTest/TestOrderAttribute.cs
+++ b/NewLife.UnitTest/TestOrderAttribute.cs
@@ -4,17 +4,22 @@ namespace NewLife.UnitTest
 {
     /// <summary>测试顺序。升序</summary>
     /// <remarks>
-    /// 提供测试用例排序支持:
-    /// [TestCaseOrderer("NewLife.UnitTest.TestOrderer", "NewLife.UnitTest")]
+    /// 测试用例排序
+    /// 
+    /// 方法特性优先级:
+    /// [TestCaseOrderer("NewLife.UnitTest.PriorityOrderer", "NewLife.UnitTest")]
+    /// 
+    /// 默认排序(按方法在类内出现的顺序):
+    /// [TestCaseOrderer("NewLife.UnitTest.DefaultOrderer", "NewLife.UnitTest")]
     /// </remarks>
     [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
     public class TestOrderAttribute : Attribute
     {
         /// <summary>测试顺序。升序</summary>
-        public Int32 Order { get; private set; }
+        public Int32 Priority { get; private set; }
 
         /// <summary>测试顺序。升序</summary>
-        /// <param name="order"></param>
-        public TestOrderAttribute(Int32 order) => Order = order;
+        /// <param name="priority"></param>
+        public TestOrderAttribute(Int32 priority) => Priority = priority;
     }
 }
\ No newline at end of file
Added +27 -0
diff --git a/XUnitTest.Core/MethodOrderTests.cs b/XUnitTest.Core/MethodOrderTests.cs
new file mode 100644
index 0000000..5553f1d
--- /dev/null
+++ b/XUnitTest.Core/MethodOrderTests.cs
@@ -0,0 +1,27 @@
+using System.Threading;
+using NewLife.UnitTest;
+using Xunit;
+
+namespace XUnitTest
+{
+    [TestCaseOrderer("NewLife.UnitTest.DefaultOrderer", "NewLife.UnitTest")]
+    public class MethodOrderTests
+    {
+        [TestOrder(1)]
+        [Fact]
+        public void Test3() => Thread.Sleep(1000);
+
+        [TestOrder(2)]
+        [Fact]
+        public void Test2() => Thread.Sleep(1000);
+
+        [Fact]
+        public void Test1() => Thread.Sleep(1000);
+
+        [Fact]
+        public void Test4() => Thread.Sleep(1000);
+        
+        [Fact]
+        public void Test5() => Thread.Sleep(1000);
+    }
+}
\ No newline at end of file
Modified +1 -1
diff --git a/XUnitTest.Core/OrderTests.cs b/XUnitTest.Core/OrderTests.cs
index 8fad203..069cf63 100644
--- a/XUnitTest.Core/OrderTests.cs
+++ b/XUnitTest.Core/OrderTests.cs
@@ -4,7 +4,7 @@ using Xunit;
 
 namespace XUnitTest
 {
-    [TestCaseOrderer("NewLife.UnitTest.TestOrderer", "NewLife.UnitTest")]
+    [TestCaseOrderer("NewLife.UnitTest.PriorityOrderer", "NewLife.UnitTest")]
     public class OrderTests
     {
         [TestOrder(1)]