使用 Test Explorer 來對單元測試進行調試和分析Debug and analyze unit tests with Test Explorer

您可以使用 [測試總管] 來啟動測試的偵錯工作階段。You can use Test Explorer to start a debugging session for your tests. 使用 Visual Studio 偵錯工具逐步執行程式碼可讓您順暢地在單元測試和受測專案之間來回進行。Stepping through your code with the Visual Studio debugger seamlessly takes you back and forth between the unit tests and the project under test. 啟動偵錯:To start debugging:

  1. 在 Visual Studio 編輯器中,於您要偵錯的一個或多個測試方法中設定中斷點。In the Visual Studio editor, set a breakpoint in one or more test methods that you want to debug.

    注意

    由於測試方法可以依照任何順序執行,請在您要偵錯的所有測試方法中設定中斷點。Because test methods can run in any order, set breakpoints in all the test methods that you want to debug.

  1. 在 [測試瀏覽器] 中,選取 (s 的測試方法) 然後選擇右鍵功能表上的 [偵測 選取的測試 ]。In Test Explorer, select the test method(s) and then choose Debug Selected Tests on the right-click menu.
  1. 在 [測試瀏覽器] 中,選取 (s 的測試方法) 然後在右鍵功能表上選擇 [ Debug ]。In Test Explorer, select the test method(s) and then choose Debug on the right-click menu.

    測試執行詳細資料

如需偵錯工具的詳細資訊,請參閱在 Visual Studio 中偵錯For more information, about the debugger, see Debug in Visual Studio.

診斷測試方法效能問題Diagnose test method performance issues

若要診斷測試方法為何花費太多時間,請在 [測試總管] 中選取該方法,然後在右鍵功能表上選擇 [設定檔已選取測試]****。To diagnose why a test method is taking too much time, select the method in Test Explorer and then choose Profile Selected Test on the right-click menu. 請參閱 檢測分析報表See Instrumentation profiling report.

若要診斷測試方法為何花費太多時間,請在 [測試總管] 中選取該方法,然後選擇右鍵功能表上的 [設定檔]****。To diagnose why a test method is taking too much time, select the method in Test Explorer and then choose Profile on the right-click menu. 請參閱 檢測分析報表See Instrumentation profiling report.

注意

.NET Core 目前不支援這項功能。This feature is not currently supported for .NET Core.

另請參閱See also