[英]Why I can't see the debug output when I run a test in Visual Studio 2012?
I am very new in C# and Visual Studio (I came from Java) and I have the following doubts about how debug work in Visual Studio. 我是C#和Visual Studio(来自Java)的新手,我对调试在Visual Studio中的工作方式有以下疑问。
So I have this unit test: 所以我有这个单元测试:
[TestMethod]
public void GetVulnerability()
{
DataModel.VulnerabilityManager manager = new DataModel.VulnerabilityManager("DefaultConnection");
try
{
manager.openConnection();
List<DataModel.Vulnerability.VulnSmall> risultato;
DataModel.Vulnerability.SearchVuln model = new DataModel.Vulnerability.SearchVuln();
model.PageSize = 20;
/*model.Filter.CVE = "CVE-2013-2902(Candidate)";*/
int numeroRecordsTotali;
risultato = manager.getList(model, out numeroRecordsTotali);
foreach (DataModel.Vulnerability.VulnSmall v in risultato ){
Debug.WriteLine("MY CVE: " + v.CVE + "**");
}
}
finally
{
manager.closeConnection();
}
So, into the foreach I print the test output by the line 因此,在foreach中,我通过一行打印测试输出
Debug.WriteLine("MY CVE: " + v.CVE + "**")
The thing that I can't understand is that when I go to execute the test clicking on Run selected test voice I can't see the test output that have to be written by my previous line but I can see it if I click on the Debug selected test voice. 我无法理解的是,当我去执行测试时,单击“ 运行选定的测试声音”时,看不到必须由上一行编写的测试输出,但是如果单击调试选定的测试语音。
Why? 为什么? What can I do to show the desidered output (and not only if the test is passed) in Visual Studio debug?
我该怎么做才能在Visual Studio调试中显示期望的输出(不仅是通过测试,还需要显示)?
I think this has to do with the fact that Debug.WriteLine() is tagged with [ConditionalAttribute("DEBUG")]
. 我认为这与Debug.WriteLine()被标记为
[ConditionalAttribute("DEBUG")]
的事实有关。
For all intents and purposes, you may think of it being equivalent to this: 出于所有意图和目的,您可能会认为它等同于以下内容:
public void WriteLine(string message)
{
#if DEBUG
Console.WriteLine(message);
#endif
}
Now you probably already guessed it, but your tests don't run in debug mode. 现在您可能已经猜到了,但是您的测试不在调试模式下运行。
Solution 解
Use the Trace
class instead of the Debug
class. 使用
Trace
类而不是Debug
类。
foreach ( DataModel.Vulnerability.VulnSmall v in risultato )
{
Trace.WriteLine("MY CVE: " + v.CVE + "**");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.