コード例 #1
0
ファイル: EqualityExercise.cs プロジェクト: GalaDe/xcsharp
        protected override TestMethod CreateTestMethod(TestMethodData testMethodData)
        {
            if (testMethodData.Options.ThrowExceptionWhenExpectedValueEquals(testMethodData.CanonicalDataCase.Expected))
            {
                return(CreateExceptionTestMethod(testMethodData));
            }

            return(CreateEqualityTestMethod(testMethodData));
        }
コード例 #2
0
        protected override TestMethod CreateTestMethod(TestMethodData testMethodData)
        {
            if (testMethodData.CanonicalDataCase.Expected is bool b)
            {
                testMethodData.Options.ExceptionType = typeof(ArgumentOutOfRangeException);
                return(CreateExceptionTestMethod(testMethodData));
            }

            return(CreateEqualityTestMethod(testMethodData));
        }
コード例 #3
0
        /// <summary>
        /// 收集Test的数据
        /// </summary>
        static public void CollectTestClassData(TestType testType)
        {
            testMethodDataMap = new Dictionary <Type, List <TestMethodData> >();
            List <Type> types = new List <Type>();

            //判断不同的模式
            if (testType == TestType.MonoOrCLR)
            {
                var assembly = typeof(BDLauncher).Assembly;
                types = assembly.GetTypes().ToList();
            }
            else if (testType == TestType.ILRuntime)
            {
                types = ILRuntimeHelper.GetHotfixTypes();
            }

            var attribute = typeof(UnitTestBaseAttribute);
            //测试用例类
            List <Type> testClassList = new List <Type>();

            foreach (var type in types)
            {
                var attrs = type.GetCustomAttributes(attribute, false);
                if (attrs.Length > 0)
                {
                    testClassList.Add(type);
                }
            }

            //搜集Test信息
            foreach (var type in testClassList)
            {
                var methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                // var attrs = type.GetCustomAttributes(attribute,false);
                // var attr = attrs[0] as HotfixTest;
                var testMethodDataList = new List <TestMethodData>();
                testMethodDataMap[type] = testMethodDataList;
                //获取uit test并排序
                foreach (var method in methods)
                {
                    var mattrs = method.GetCustomAttributes(attribute, false);
                    var mattr  = mattrs[0] as UnitTestBaseAttribute;

                    //数据
                    var newMethodData = new TestMethodData()
                    {
                        MethodInfo = method, TestData = mattr,
                    };

                    //添加整合排序
                    bool isAdd = false;
                    for (int i = 0; i < testMethodDataList.Count; i++)
                    {
                        var tdata = testMethodDataList[i];

                        if (newMethodData.TestData.Order < tdata.TestData.Order)
                        {
                            testMethodDataList.Insert(i, newMethodData);
                            isAdd = true;
                            break;
                        }
                    }

                    if (!isAdd)
                    {
                        testMethodDataList.Add(newMethodData);
                    }
                }
            }
        }
コード例 #4
0
 protected virtual TestMethod CreateExceptionTestMethod(TestMethodData testMethodData)
 => ExceptionTestMethodGenerator.Create(testMethodData);
コード例 #5
0
 protected virtual TestMethod CreateEqualityTestMethod(TestMethodData testMethodData)
 => EqualityTestMethodGenerator.Create(testMethodData);
コード例 #6
0
 protected virtual TestMethod CreateBooleanTestMethod(TestMethodData testMethodData)
 => BooleanTestMethodGenerator.Create(testMethodData);
コード例 #7
0
 protected abstract TestMethod CreateTestMethod(TestMethodData testMethodData);
コード例 #8
0
ファイル: BooleanExercise.cs プロジェクト: Thorocaine/xcsharp
 protected override TestMethod CreateTestMethod(TestMethodData testMethodData)
 => CreateBooleanTestMethod(testMethodData);
コード例 #9
0
ファイル: TestRunner.cs プロジェクト: mrcece/BDFramework.Core
        static void TestForMono()
        {
            testMethodMap = new Dictionary <Type, List <TestMethodData> >();
            //
            var assembly  = typeof(BDLauncherBridge).Assembly;
            var attribute = typeof(HotfixTestAttribute);
            //测试用例类
            List <Type> testClassList = new List <Type>();

            foreach (var type in assembly.GetTypes())
            {
                var attrs = type.GetCustomAttributes(attribute, false);
                if (attrs.Length > 0)
                {
                    testClassList.Add(type);
                }
            }

            //搜集Test信息
            foreach (var type in testClassList)
            {
                var methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                // var attrs = type.GetCustomAttributes(attribute,false);
                // var attr = attrs[0] as HotfixTest;
                var testMethodDataList = new List <TestMethodData>();
                testMethodMap[type] = testMethodDataList;
                //获取uit test并排序
                foreach (var method in methods)
                {
                    var mattrs = method.GetCustomAttributes(attribute, false);
                    var mattr  = mattrs[0] as HotfixTestAttribute;

                    //数据
                    var newMethodData = new TestMethodData()
                    {
                        MethodInfo = method, TestAttributeAttribute = mattr,
                    };


                    //添加整合排序
                    bool isAdd = false;
                    for (int i = 0; i < testMethodDataList.Count; i++)
                    {
                        var tdata = testMethodDataList[i];

                        if (newMethodData.TestAttributeAttribute.Order < tdata.TestAttributeAttribute.Order)
                        {
                            testMethodDataList.Insert(i, newMethodData);
                            isAdd = true;
                            break;
                        }
                    }

                    if (!isAdd)
                    {
                        testMethodDataList.Add(newMethodData);
                    }
                }
            }

            foreach (var item in testMethodMap)
            {
                Debug.LogFormat("<color=yellow>---->执行:{0} </color>", item.Key.FullName);

                foreach (var methodData in item.Value)
                {
                    try
                    {
                        methodData.MethodInfo.Invoke(null, null);
                        Debug.LogFormat("<color=green>执行:{0}: 成功!</color>", methodData.MethodInfo.Name);
                    }
                    catch (Exception e)
                    {
                        Debug.LogErrorFormat("<color=red>执行{0}: {1}</color>", methodData.MethodInfo.Name, e.InnerException.Message);
                        Debug.Log(e.StackTrace);
                    }
                }
            }
        }
コード例 #10
0
 protected override TestMethod CreateTestMethod(TestMethodData testMethodData)
 => CreateEqualityTestMethod(testMethodData);