Testcase中Debug 提示

当TestCase运行时需要进行调试,但是case的代码非常多,并不想或则没发打开所有项目进行调试,只需要调试某个Case即可.

添加下面代码到case的初始化中,设置ISDEBUG变量=true,在运行case时,会提示进行进行调试,附加相关进程,点击确定即可进行调试.

 

当然也可以应用到其他的应用程序中,不一定为Testcase.

 

  public static bool IsDebugging
        {
            get
            {
                string s = Environment.GetEnvironmentVariable("ISDEBUG");
                bool result = false;
                if (bool.TryParse(s, out result))
                {
                    return result;
                }
                return false;
            }
        }

        public static void DebugPrompt(string msg)
        {
            if (IsDebugging)
            {
                int procId = System.Diagnostics.Process.GetCurrentProcess().Id;
                MessageBox.Show(
                   string.Format("ISDEBUG 已设置,测试现处在 '{0}'\n需要附加的进程ID为: {1}", msg, procId),
                   "Debugging: " + procId,
                   MessageBoxButtons.OK,
                   MessageBoxIcon.Exclamation,
                   MessageBoxDefaultButton.Button1,
                   MessageBoxOptions.RightAlign);
            }
        }

posted @ 2010-04-14 09:54  Zhongjian Zhang  阅读(1098)  评论(1编辑  收藏  举报