zoukankan      html  css  js  c++  java
  • C# ASP.Net .Net 单元测试时间

    [TestClass]
        public class FacilityTest
        {public FacilityTest()
            {
            }
    
    
            [TestInitialize]
            public void InitTestData()
            {
                
            }
    
            [TestCleanup]
            public void ClearTestData()
            {
    
            }
    
            /// <summary>
            /// 添加扣分情况
            /// </summary>
            [TestMethod]
            public void UpdateCameraIsOnLine()
            {
    
                DateTime beginTime1 = DateTime.Now;
                for (int i = 0; i < 100000; i++) {
                    AttributeVerification.DesensitizationData1("13888888888");
                }
                DateTime endTime1 = DateTime.Now;
                double diff1 = ExecDateDiff(beginTime1, endTime1);
    
                DateTime beginTime2 = DateTime.Now;
                for (int i = 0; i < 100000; i++)
                {
                    AttributeVerification.DesensitizationData("13888888888");
    } DateTime endTime2 = DateTime.Now; double diff2 = ExecDateDiff(beginTime2, endTime2); Assert.IsTrue(diff1> diff2, "执行失败"); } /// <summary> /// 程序执行时间测试 /// </summary> /// <param name="dateBegin">开始时间</param> /// <param name="dateEnd">结束时间</param> /// <returns>返回(秒)单位,比如: 0.00239秒</returns> public static double ExecDateDiff(DateTime dateBegin, DateTime dateEnd) { TimeSpan ts1 = new TimeSpan(dateBegin.Ticks); TimeSpan ts2 = new TimeSpan(dateEnd.Ticks); TimeSpan ts3 = ts1.Subtract(ts2).Duration(); //你想转的格式 return ts3.TotalMilliseconds; } }

    [TestClass]    public class FacilityTest    {        protected static readonly ILog _logger = LogManager.GetLogger(typeof(SkyNetTest));

            private IWindsorContainer _container;        private ISkyNetMgeSvr _svr;        private IWorkFormCenterSvr _iWorkFormCenterSvr;        private IRightCheck _auther;        private IAuthorize _authorize;        private LoginResult _lgResult;

            public FacilityTest()        {            if (_container == null)            {                _container = ComponentManager.GetInstance();
                    //_container.AddComponent("AppSelfConfigMsg", typeof(IAppSelfConfigMsg), typeof(AppSelfConfigMsg));            }            _authorize = ServiceManager.GetService<IAuthorize>(AccountServiceConst.Component_Authorize, true);            //_auther = (IRightCheck)_container[typeof(IRightCheck)];            //_auther.Active = true;
                _svr = (ISkyNetMgeSvr)_container["SkyNetMgeSvr"];
                //_auther = new AutherUseRightCheck();            //_auther.Login("127.0.0.1", "zprk", "");        }

            [TestInitialize]        public void InitTestData()        {                    }
            [TestCleanup]        public void ClearTestData()        {
            }
            /// <summary>        /// 添加扣分情况        /// </summary>        [TestMethod]        public void UpdateCameraIsOnLine()        {
                DateTime beginTime1 = DateTime.Now;            for (int i = 0; i < 100000; i++) {                AttributeVerification.DesensitizationData1("13880091741");            }            DateTime endTime1 = DateTime.Now;            double diff1 = ExecDateDiff(beginTime1, endTime1);
                DateTime beginTime2 = DateTime.Now;            for (int i = 0; i < 100000; i++)            {                AttributeVerification.DesensitizationData("13880091741");            }            DateTime endTime2 = DateTime.Now;            double diff2 = ExecDateDiff(beginTime2, endTime2);
                Assert.IsTrue(diff1> diff2, "执行失败");        }
            /// <summary>        /// 程序执行时间测试        /// </summary>        /// <param name="dateBegin">开始时间</param>        /// <param name="dateEnd">结束时间</param>        /// <returns>返回(秒)单位,比如: 0.00239秒</returns>        public static double ExecDateDiff(DateTime dateBegin, DateTime dateEnd)        {            TimeSpan ts1 = new TimeSpan(dateBegin.Ticks);            TimeSpan ts2 = new TimeSpan(dateEnd.Ticks);            TimeSpan ts3 = ts1.Subtract(ts2).Duration();            //你想转的格式            return ts3.TotalMilliseconds;        }    }

  • 相关阅读:
    JS函数
    函数与指针
    函数返回指针类型(strchr函数)
    二维数组求平均值(指针的使用)
    二维数组做函数参数传递
    指针与函数
    Ubuntu安装mysql步骤
    带参程序
    函数返回值是指针
    mystrcat
  • 原文地址:https://www.cnblogs.com/xiaoruilin/p/14791147.html
Copyright © 2011-2022 走看看