使用TestDriven.Net时如何查看Debug.WriteLine语句? [英] How do I see Debug.WriteLine statements when using TestDriven.Net?

查看:137
本文介绍了使用TestDriven.Net时如何查看Debug.WriteLine语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用TestDriven.Net不仅可以测试我的代码,还可以调用我的代码中的一个函数,其目的是将代码的内部状态打印到调试窗口。

I'm trying to use TestDriven.Net not only to test my code, but to call a function on my code whose purpose is to print out the internal state of the code to the Debug window.

这是一个非常简单的例子,我正在尝试做..

Here's a very simplified example of what I'm trying to do..

<TestFixture()> _
Public Class UnitTest

    <Test()> _
    Public Sub TestDebug()
        Dim oClass1 As New Class1

        Assert.AreEqual(True, oClass1.IsTrue)

        Debug.WriteLine("About to call .PrintDebug()")
        oClass1.PrintToDebug()

    End Sub

End Class

Public Class Class1

    Private _IsTrue As Boolean = True

    Public ReadOnly Property IsTrue() As Boolean
        Get
            Return _IsTrue
        End Get
    End Property

    Public Sub PrintToDebug()
        Debug.WriteLine("Internal state of Class1: " & _IsTrue)
    End Sub

End Class

我试图测试Class1的公共接口,以某种方式查看 Class1.PrintToDebug() function。

I'm trying to test the Public interface of Class1, and somehow view the output from the Class1.PrintToDebug() function.

我看过 TestDriven.Net quickstart ,其中显示了例子在单元测试中使用 Debug.WriteLine ,但奇怪的是,这对我来说也不起作用 - 即我的测试窗口中唯一的输出是: p>

I've looked through the TestDriven.Net quickstart, which shows examples of using the Debug.WriteLine in a unit test, but strangely this doesn't work for me either - i.e. the only Output in my 'Test' window is:

------ Test started: Assembly: ClassLibrary1.dll ------


1 passed, 0 failed, 0 skipped, took 1.19 seconds.

我试过在其他窗口中查找(Debug and Build),Debug窗口有'程序输出和异常消息选项启用。

I've tried looking in the other windows (Debug and Build), the Debug window has the 'Program Output' and 'Exception Messages' options enabled.

我已经查找选项或偏好,找不到任何!

I've looked for options or preferences and can't find any!

感谢您的帮助!



编辑:我使用的是VB.Net 2.0,TestDriven.Net 2.14.2190和NUnit 2.4.8.0


I'm using VB.Net 2.0, TestDriven.Net 2.14.2190 and NUnit 2.4.8.0

推荐答案

我发现尽管Debug.Writeline()不使用单元测试,Console.WriteLine()。

I found that while Debug.Writeline() doesn't work with unit tests, Console.WriteLine() does.

原因是当您运行测试时,调试器进程不被调用,Debug.WriteLine()将被忽略。但是,如果您使用Test with Debugger,我认为(没有尝试)Debug.WriteLine()将工作。

The reason is that when you run tests, the debugger process isn't invoked, and Debug.WriteLine() is ignored. However, if you use "Test with Debugger", I think (haven't tried) Debug.WriteLine() will work.

这篇关于使用TestDriven.Net时如何查看Debug.WriteLine语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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