不能在 visual studio 代码中使用 DEBUG 标志进行测试

can't use DEBUG flag in visual studio code for tests

我在 visual studio 代码中设置了单元测试,我需要读取测试数据文件,将其加载到 HtmlDocument (HtmlAgilityPack) 并测试解析器 class。在 class 的顶部我有

public class MegaParserTests{

private HtmlDocument _hd;
private MegaParser _parserUT;

public ParserTests() {
    _parserUI = new MegaParser();
    _hd = new HtmlDocument()

#if DEBUG
    filePath = "data/theDoc.html";
#else
    filePath = @"../../../data/theDoc.html";
#endif

    var docStr = File.ReadAllText(filePath);
    _hd.LoadHtml(doc);
}
}

我使用了 #if DEBUG,因为文件路径似乎会根据我是 "debug test" 还是从命令行执行 "dotnet test" 而改变。但是,当我进行 dotnet 测试时,遇到了最上面的“#if DEBUG”条件,我得到了错误的文件路径。为什么当我 运行 dotnet 测试 运行 时认为我处于调试模式.. 我该如何改变它?

实际上 dotnet test command 默认使用 Release 构建配置...尝试使用 -configuration 标志强制发布构建配置:

dotnet test -c Release

-c|--configuration

Configuration under which to build. The default value is Release.