简体   繁体   English

C#单元测试如何进入function调试代码?

[英]How to step into function to debug code in C# unit test?

I am trying to add a C# unit test (.net 4.5) to an existing solution that creates an instance of a class and calls a public method, and it will execute the code but not let me step into it.我正在尝试将 C# 单元测试 (.net 4.5) 添加到创建 class 实例并调用公共方法的现有解决方案中,它将执行代码但不允许我介入。 The code is in another project in the solution and I've written unit tests before that let me step into code.代码在解决方案的另一个项目中,在此之前我已经编写了单元测试让我进入代码。 The assembly from the main project (that houses the code I want to step into) is in my GAC, but I added it to the unit test project as a project reference, not assembly reference.主项目中的程序集(包含我要进入的代码)在我的 GAC 中,但我将它添加到单元测试项目中作为项目参考,而不是程序集参考。

Code in the test method:测试方法中的代码:

[TestMethod]
public void CalculateChartlines_HasValidCL()
{
    //populating lvi, startDate, endDate
    ChartLines pchart = new ChartLines();
      
    CenterlineDateRange cdr = new CenterlineDateRange(0, true, startDate, endDate, 12);           

    var valuesOut = pchart.CalculateChartLines(ChartType.P_Chart, lvi, cdr); //steps over
    ...
}

ChartLines class in another project in the same solution (I added this project as a reference): ChartLines class 在同一解决方案的另一个项目中(我添加了这个项目作为参考):

public class ChartLines : ILNCharts
{
    public ChartLines()
    { 
    
    }
    public List<ValuesOut> CalculateChartLines(ChartType chartType, List<ValuesIn> lvi, CenterlineDateRange cldr)
    {
        return GetCalculateChartLines(chartType, lvi, cldr);
    }
    ...
}

public interface ILNCharts
{
    List<ValuesOut> CalculateChartLines(ChartType chartType, List<ValuesIn> lvi, CenterlineDateRange cldr);
    <other methods>
}

maybe you need to add the dll from the project after building it in debug mode and then add the reference to your test project, i do that in my projects.也许您需要在调试模式下构建项目后从项目中添加 dll,然后将引用添加到您的测试项目,我在我的项目中这样做。

Maybe this would help too: debug a project with references in visual studio也许这也会有所帮助: debug a project with references in visual studio

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM