将代码行打印到错误日志中

时间:2017-06-19 11:53:32

标签: c#

我正在编写一些单元测试,我想在我的错误日志中打印出一行代码。

我不确定你是否可以这样做

我的演示测试看起来像这样,你可以从中看到我正在传递的内容,但是“找不到元素”的消息是不精确的。

我传递了一条消息,行号和方法,但行号没有多大用处,因为它只获取触发捕获的行号。

public void createTest()
{
    try
    {


    excelSession.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));

    excelSession.FindElementByName("Blank workbook").Click();
    excelSession.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
    excelSession.FindElementByName("Create").Click();

    skipTearDown = true;
    }
    catch (Exception)
    {

        CommonMethods.ExceptionHandler("Couldn't find element", new StackTrace(true).GetFrame(0).GetFileLineNumber(), new StackTrace(true).GetFrame(0).GetMethod(), excelSession);
    }
    TearDown();
}

0 个答案:

没有答案