Stepping through and debugging code in Unit tests

前端 未结 8 2000
离开以前
离开以前 2020-12-09 01:34

I have not been able to debug or step through unit test.

Here is my sample test code...

using System;
using System.Text;
using System.Collections.Gen         


        
相关标签:
8条回答
  • 2020-12-09 01:49

    If you were running nunit, that was so easy:

    1. Run nunit and open your desired assembly in it.
    2. Open visual studio -> Debug -> Attach to Process...
    3. Select process of nunit
    4. Put break point in each line you want.
    5. Go back to nunit and run tests
    6. You will see that execution stops at break points
    0 讨论(0)
  • 2020-12-09 01:55

    Yes you can, thank you :)

    To actually break on them you need to run your unit tests in Debug mode though.

    0 讨论(0)
  • 2020-12-09 01:57

    It's far simpler in VS 2013, in Test Explorer select tests you wish to debug, right-click and choose debug selected tests.

    0 讨论(0)
  • 2020-12-09 01:57

    One option is to install TestDriven.net which makes it easier to run unit tests on any of the major unit testing .net frameworks (nunit, xunit, VS tools, etc). Once installed you can right click on a function and choose Test With --> debugger.

    0 讨论(0)
  • 2020-12-09 02:00

    When using Microsoft.VisualStudio.TestTools.UnitTesting, go to 'Test' in the main menu of VS 2010, click submenu 'Debug' -> 'tests in current context'.

    Right-clicking on the test-code and selecting 'run tests' will never start the debugger, not even when mode = debug.

    0 讨论(0)
  • 2020-12-09 02:02

    Maybe simply debugging tests and setting breakpoints works in some kinds of Unit tests but it doesn't if you debug e.g. Web service.

    To debug a Web Service (break inside a Unit test) you have to insert this code:

    System.Diagnostics.Debugger.Break();
    

    This will show a popup saying the application stopped working and you can choose to debug it.

    More here: http://msdn.microsoft.com/en-us/library/ms243172.aspx#DebuggingOnCassini

    0 讨论(0)
提交回复
热议问题