在MSTest中为所有单元测试启用跟踪源. [英] Enabling trace sources in MSTest for ALL unit tests.

查看:45
本文介绍了在MSTest中为所有单元测试启用跟踪源.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TraceSource   ;目的 用于输出跟踪信息.

I have a DLL that's a bit on the complicated side that I'm writing tests against. Most of the classes under test have their own TraceSource object that are used to output tracing information.

namespace MyDll
{
    public class Class1
    {
        static TraceSource tracing = new TraceSource(nameof(Class1));
        //Instance members and functions...
    }

    public class Class2
    {
        static TraceSource tracing = new TraceSource(nameof(Class2));
        //Instance members and functions...
    }

    public class Class3
    {
        static TraceSource tracing = new TraceSource(nameof(Class3));
        //Instance members and functions...
    }
}

MyDll   project 是 App.config 文件 添加了常见的 ConsoleTraceListener  至 TraceSource , 像这样:

Inside of the MyDll project is an App.config file that adds a common ConsoleTraceListener to all of the TraceSource, like so:

<configuration>
  <system.diagnostics>
    <sources>
      <source name="Class1"
        switchName="sourceSwitch"
        switchType="System.Diagnostics.SourceSwitch">
        <listeners>
          <add name="console"/>
        </listeners>
      </source>
      <source name="Class2"
        switchName="sourceSwitch"
        switchType="System.Diagnostics.SourceSwitch">
        <listeners>
          <add name="console"/>
        </listeners>
      </source>
      <source name="Class3"
        switchName="sourceSwitch"
        switchType="System.Diagnostics.SourceSwitch">
        <listeners>
          <add name="console"/>
        </listeners>
      </source>
    </sources>
    <switches>
      <add name="sourceSwitch" value="Verbose"/>
    </switches>
    <sharedListeners>
      <add name="console"
            type="System.Diagnostics.ConsoleTraceListener">
        <filter type="System.Diagnostics.EventTypeFilter"
          initializeData="Verbose"/>
      </add>
    </sharedListeners>
  </system.diagnostics>
</configuration>

App.config is configured to always copy to the output directory. I'm not sure if that's relevant.

问题出在这里:如果我运行1个测试,则会从测试中获得输出中的所有跟踪信息.但是,如果我运行所有测试,则只有第一个测试将具有被测代码的跟踪.所有其他测试都没有任何输出.

Here's the problem: If I run 1 test, I get all of the tracing information in the Output from the test. However, if I run all of the tests, only the first test will have the tracing from the code under test. All of the other tests do not have any output.

我怎样才能让MSTest从所有

How can I get MSTest to output all tracing information from all TraceSource for all tests?

推荐答案

您应该发布到UT论坛.

You should post to the UT forum.

https://social.msdn.microsoft.com/Forums/vstudio/en-us/home?forum=vsunittest

https://social.msdn.microsoft.com/Forums/vstudio/en-us/home?forum=vsunittest


这篇关于在MSTest中为所有单元测试启用跟踪源.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆