当前位置: 首页>>代码示例>>C#>>正文


C# Statistics.AddTime方法代码示例

本文整理汇总了C#中Statistics.AddTime方法的典型用法代码示例。如果您正苦于以下问题:C# Statistics.AddTime方法的具体用法?C# Statistics.AddTime怎么用?C# Statistics.AddTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Statistics的用法示例。


在下文中一共展示了Statistics.AddTime方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: run

        public void run(object targetObject, string targetObjectName)
        {
            logger.log("Testing " + targetObjectName);
            logger.log("----------------------------");
            Statistics statistics = new Statistics();
            Type targetType = targetObject.GetType();
            MethodInfo[] methods = targetType.GetMethods();
            MethodInfo initializer = getMethodOrNull(targetType, "initialize", typeof(string));
            MethodInfo releaser = getMethodOrNull(targetType, "release", typeof(string));
            foreach (MethodInfo method in methods)
            {
                if (method.Name.StartsWith(TEST_METHOD_PREFIX))
                {
                    statistics.TotalCount++;
                    string fullname = "'" + targetObjectName + "->" + method.Name + "'";
                    try
                    {
                        logger.log("Executing test " + fullname);
                        if (null != initializer)
                        {
                            try
                            {
                                initializer.Invoke(targetObject, new object[] { method.Name });
                            }
                            catch (Exception e)
                            {
                                logger.log("WARNING: Initialization before " + fullname + " test executing was failed. Test can't be run. Error message: " + e.Message);
                                statistics.SkippedCount++;
                                logger.log(string.Empty);
                                continue;
                            }
                        }
                        long startTime = DateTime.Now.Ticks;
                        try
                        {
                            targetType.InvokeMember(method.Name, BindingFlags.InvokeMethod, null, targetObject, null);
                        }
                        catch (TargetInvocationException e)
                        {
                            throw e.InnerException;
                        }
                        long spentTime = (DateTime.Now.Ticks - startTime) / 10000;
                        statistics.AddTime(spentTime);
                        statistics.PassedCount++;
                        if (null != releaser)
                        {
                            try
                            {
                                releaser.Invoke(targetObject, new object[] { method.Name });
                            }
                            catch (Exception e1)
                            {
                                logger.log("--- WARNING: Releasing of test data was failed. Error message: " + e1.Message);
                            }
                        }
                        logger.log("Test was passed " + fullname + ". Time: " + spentTime + " ms");
                    }
                    catch (SkippedException se)
                    {
                        if (null != releaser)
                        {
                            try
                            {
                                releaser.Invoke(targetObject, new object[] { method.Name });
                            }
                            catch (Exception e1)
                            {
                                logger.log("--- WARNING: Releasing of test data was failed. Error message: " + e1.Message);
                            }
                        }
                        logger.log("Test was skipped " + fullname + ". Reason: " + se.Message);
                        statistics.SkippedCount++;
                    }
                    catch (Exception e)
                    {
                        if (null != releaser)
                        {
                            try
                            {
                                releaser.Invoke(targetObject, new object[] { method.Name });
                            }
                            catch (Exception e1)
                            {
                                logger.log("--- WARNING: Releasing of test data was failed. Error message: " + e1.Message);
                            }
                        }
                        logger.log("Test was failed " + fullname + ". Message: " + e.Message);
                        statistics.FailedCount++;
                    }
                    logger.log(string.Empty);
                }
            }
            logger.log("----------------------------");
            logger.log("Passed:   " + statistics.PassedCount);
            logger.log("Failed:   " + statistics.FailedCount);
            logger.log("Skipped:  " + statistics.SkippedCount);
            logger.log("Executed: " + statistics.TotalCount);
            logger.log("----------------------------");
            logger.log("Spent time: " + statistics.TotalSpentTime + " ms");
            logger.log();
//.........这里部分代码省略.........
开发者ID:negabaro,项目名称:alfresco,代码行数:101,代码来源:TestRunner.cs


注:本文中的Statistics.AddTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。