2017-01-09 11 views
0

我在visual studio代碼中有一個單元測試設置,我需要讀取一個測試數據文件,將它加載到HtmlDocument(HtmlAgilityPack)並測試一個Parser類。在類的頂部我不能在Visual Studio代碼中使用DEBUG標誌進行測試

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); 
} 
} 

我已經使用了#如果DEBUG作爲文件路徑似乎取決於我「調試測試」,還是在命令行中執行「dotnet的測試」,以改變。但是,當我做一個dotnet測試時,頂部「#if DEBUG」條件被擊中,我得到錯誤的文件路徑。爲什麼當我運行dotnet測試運行時認爲我處於調試模式..我怎樣才能改變這一點?

回答

1

實際上dotnet testcommand默認使用Release生成配置...嘗試使用-configuration標誌來強制發佈版本的配置:

dotnet test -c Release 

-c | --configuration

配置在其下建立。默認值是Release。

相關問題