Skip to content

Repo sync for protected CLA branch #7870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/debugger/media/vs-2019/watch-variable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/debugger/media/vs-2022/refresh-watch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/debugger/media/vs-2022/watch-expression.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/debugger/media/vs-2022/watch-variable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/debugger/media/watchvariables.PNG
Binary file not shown.
79 changes: 70 additions & 9 deletions docs/debugger/watch-and-quickwatch-windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Set a watch on variables | Microsoft Docs
description: While you debug, see variables and expressions in Watch and QuickWatch. Watch can display several variables, QuickWatch only one, and only while in break.
ms.custom: SEO-VS-2020
ms.date: 09/10/2021
ms.date: 04/04/2022
ms.topic: how-to
f1_keywords:
- "vs.debug.quickwatch"
Expand Down Expand Up @@ -66,7 +66,17 @@ int main()

1. In the **Watch** window, select an empty row, and type variable `a`. Do the same for `b` and `c`.

![Watch variables](../debugger/media/watchvariables.png "WatchVariables")
::: moniker range="<=vs-2019"

![Screenshot of Watch variables.](../debugger/media/vs-2019/watch-variable.png)

::: moniker-end

::: moniker range=">=vs-2022"

![Screenshot of Watch variables.](../debugger/media/vs-2022/watch-variable.png)

::: moniker-end

1. Continue debugging by selecting **Debug** > **Step Into** or pressing **F11** as needed to advance. The variable values in the **Watch** window change as you iterate through the `for` loop.

Expand All @@ -82,22 +92,43 @@ You can observe any valid expression recognized by the debugger in a **Watch** w

For example, for the code in the preceding section, you can get the average of the three values by entering `(a + b + c) / 3` in the **Watch** window:

![Watch expression](../debugger/media/watchexpression.png "Watch expression")
::: moniker range="<=vs-2019"

![Screenshot of Watch expression.](../debugger/media/vs-2019/watch-expression.png "Watch expression")

::: moniker-end

::: moniker range=">=vs-2022"

![Screenshot of Watch expression.](../debugger/media/vs-2022/watch-expression.png "Watch expression")

::: moniker-end

The rules for evaluating expressions in the **Watch** window are generally the same as the rules for evaluating expressions in the code language. If an expression has a syntax error, expect the same compiler error as in the code editor. For example, a typo in the preceding expression produces this error in the **Watch** window:

![Watch expression error](../debugger/media/watchexpressionerror.png "Watch expression error")
::: moniker range="<=vs-2019"

![Screenshot of Watch expression error.](../debugger/media/vs-2019/watch-expression-error.png "Watch expression error")

::: moniker-end

::: moniker range=">=vs-2022"

![Screenshot of Watch expression error.](../debugger/media/vs-2022/watch-expression-error.png "Watch expression error")

::: moniker-end

A circle with two wavy lines icon may appear in the **Watch** window. This icon means the debugger doesn't evaluate the expression because of a potential cross-thread dependency. Evaluating the code requires other threads in your app to run temporarily, but since you are in break mode, all threads in your app are usually stopped. Allowing other threads to run temporarily can have unexpected effects on the state of your app, and the debugger may ignore events such as breakpoints and exceptions on those threads.

::: moniker range=">= vs-2019"

## Search in the Watch window

You can search for keywords in the Name, Value, and Type columns of the **Watch** window using the search bar above each window. Hit ENTER or select one of the arrows to execute a search. To cancel an ongoing search, select the "x" icon in the search bar.

Use the left and right arrows (Shift+F3 and F3, respectively) to navigate between found matches.

![Search in Watch Window](../debugger/media/ee-search-watch.png "Search in Watch Window")
![Screenshot of Search in Watch Window.](../debugger/media/ee-search-watch.png "Search in Watch Window")

To make your search more or less thorough, use the **Search Deeper** dropdown at the top of the **Watch** window to select how many levels deep you want to search into nested objects.

Expand All @@ -108,7 +139,7 @@ To make your search more or less thorough, use the **Search Deeper** dropdown at

You can quickly inspect objects by their properties in the Watch window with the **Pinnable Properties** tool. To use this tool, hover over a property and select the pin icon that appears or right-click and select the **Pin Member as Favorite** option in the resulting context menu. This bubbles up that property to the top of the object’s property list, and the property name and value is displayed in the **Value** column. To unpin a property, select the pin icon again or select the **Unpin Member as Favorite** option in the context menu.

![Pin properties in the Watch window](../debugger/media/basic-pin-watch.gif "Pin properties in the Watch window")
![Screenshot of Pin properties in the Watch window.](../debugger/media/basic-pin-watch.gif "Pin properties in the Watch window")

You can also toggle property names and filter out non-pinned properties when viewing the object’s property list in the Watch window. You can access both options by selecting the buttons in the toolbar above the watch window.

Expand Down Expand Up @@ -147,7 +178,17 @@ To demonstrate using the refresh icon:

1. Start debugging. The **Watch** window shows something like the following message:

![Refresh Watch](../debugger/media/refreshwatch.png "Refresh Watch")
::: moniker range="<=vs-2019"

![Screenshot of Refresh Watch.](../debugger/media/vs-2019/refresh-watch.png "Refresh Watch")

::: moniker-end

::: moniker range=">=vs-2022"

![Screenshot of Refresh Watch.](../debugger/media/vs-2022/refresh-watch.png "Refresh Watch")

::: moniker-end

1. To refresh the value, select the refresh icon, or press the spacebar. The debugger reevaluates the expression.

Expand Down Expand Up @@ -288,11 +329,31 @@ To observe the `a` variable,

The **QuickWatch** dialog appears. The `a` variable is in the **Expression** box with a **Value** of **1**.

![QuickWatch variable](../debugger/media/quickwatchvariable.png "QuickWatch variable")
::: moniker range="<=vs-2019"

![Screenshot of QuickWatch variable.](../debugger/media/vs-2019/quickwatch-variable.png "QuickWatch variable")

::: moniker-end

::: moniker range=">=vs-2022"

![Screenshot of QuickWatch variable.](../debugger/media/vs-2022/quickwatch-variable.png "QuickWatch variable")

::: moniker-end

1. To evaluate an expression using the variable, type an expression such as `a + b` in the **Expression** box, and select **Reevaluate**.

![QuickWatch expression](../debugger/media/quickwatchexpression.png "QuickWatch expression")
::: moniker range="<=vs-2019"

![Screenshot of QuickWatch expression.](../debugger/media/vs-2019/quickwatch-expression.png "QuickWatch expression")

::: moniker-end

::: moniker range=">=vs-2022"

![Screenshot of QuickWatch expression.](../debugger/media/vs-2022/quickwatch-expression.png "QuickWatch expression")

::: moniker-end

1. To add the variable or expression from **QuickWatch** to the **Watch** window, select **Add Watch**.

Expand Down
134 changes: 122 additions & 12 deletions docs/test/generate-unit-tests-for-your-code-with-intellitest.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Generate unit tests for your code with IntelliTest
description: IntelliTest explores your .NET code to generate test data and a suite of unit tests. Learn how to run IntelliTest to generate smart fuzz tests that cover all your logic branches, see which tests are failing, and fix them.
ms.custom: SEO-VS-2020
ms.date: 10/05/2015
ms.date: 04/04/2022
ms.topic: conceptual
f1_keywords:
- vs.UnitTest.CreateIntelliTest
Expand Down Expand Up @@ -39,27 +39,77 @@ To generate unit tests, your types must be public.

2. Right-click on a method and choose **Run IntelliTest** to generate unit tests for the code in your method.

![Right&#45;click in your method to generate unit tests](../test/media/runpex.png)
::: moniker range="<=vs-2019"

![Screenshot of right click on method to generate unit tests.](../test/media/vs-2019/run-pex.png)

::: moniker-end

::: moniker range=">=vs-2022"

![Screenshot of right click on method to generate unit tests.](../test/media/vs-2022/run-pex.png)

::: moniker-end

IntelliTest runs your code many times with different inputs. Each run is represented in the table showing the input test data and the resulting output or exception.

![Exploration Results window is displayed with tests](../test/media/pexexplorationresults.png)
::: moniker range="<=vs-2019"

![Screenshot of Exploration Results window.](../test/media/vs-2019/pex-exploration-results.png)

::: moniker-end

::: moniker range=">=vs-2022"

![Screenshot of Exploration Results window.](../test/media/vs-2022/pex-exploration-results.png)

::: moniker-end

To generate unit tests for all the public methods in a class, simply right-click in the class rather than a specific method, and then choose **Run IntelliTest**. Use the drop-down list in the **Exploration Results** window to display the unit tests and the input data for each method in the class.

![Select the test results to view from the list](../test/media/selectpextest.png)
::: moniker range="<=vs-2019"

![Screenshot of test results to view from list.](../test/media/vs-2019/select-pex-test.png)

::: moniker-end

::: moniker range=">=vs-2022"

![Screenshot of test results to view from list.](../test/media/vs-2022/select-pex-test.png)

::: moniker-end

For tests that pass, check that the reported results in the result column match your expectations for your code. For tests that fail, fix your code as appropriate. Then rerun IntelliTest to validate the fixes.

## Persist: Save the unit tests as a regression suite

1. Select the data rows that you want to save with the parameterized unit test into a test project.

![Select tests; right&#45;click and choose Save](../test/media/savepextests.png)
::: moniker range="<=vs-2019"

![Screenshot of Save test results.](../test/media/vs-2019/save-pex-tests.png)

::: moniker-end

::: moniker range=">=vs-2022"

![Screenshot of Save test results.](../test/media/vs-2022/save-pex-tests.png)

::: moniker-end

You can view the test project and the parameterized unit test that has been created - the individual unit tests, corresponding to each of the rows, are saved in the *.g.cs* file in the test project, and a parameterized unit test is saved in its corresponding *.cs* file. You can run the unit tests and view the results from Test Explorer just as you would for any unit tests that you created manually.

![Open class file in test method to view unit test](../test/media/testmethodpex.png)
::: moniker range="<=vs-2019"

![Screenshot of saved tests in Solution Explorer.](../test/media/vs-2019/test-method-pex.png)

::: moniker-end

::: moniker range=">=vs-2022"

![Screenshot of saved tests in Solution Explorer.](../test/media/vs-2022/test-method-pex.png)

::: moniker-end

Any necessary references are also added to the test project.

Expand All @@ -71,19 +121,49 @@ For tests that pass, check that the reported results in the result column match

View the warnings to decide what you want to do.

![View warnings](../test/media/pexviewwarning.png)
::: moniker range="<=vs-2019"

![Screenshot of View warnings.](../test/media/vs-2019/pex-view-warning.png)

::: moniker-end

::: moniker range=">=vs-2022"

![Screenshot of View warnings.](../test/media/vs-2022/pex-view-warning.png)

::: moniker-end

2. After you investigate the code and understand what you want to test, you can fix the warning to choose which classes to use to test the interface.

![Right&#45;click the warning and choose Fix](../test/media/pexfixwarning.png)
::: moniker range="<=vs-2019"

![Screenshot of Fix warning.](../test/media/vs-2019/pex-fix-warning.png)

::: moniker-end

::: moniker range=">=vs-2022"

![Screenshot of Fix warning.](../test/media/vs-2022/pex-fix-warning.png)

::: moniker-end

This choice is added into the *PexAssemblyInfo.cs* file.

`[assembly: PexUseType(typeof(Camera))]`

3. Now you can rerun IntelliTest to generate a parameterized unit test and test data just using the class that you fixed.

![Rerun IntelliTest to generate the test data](../test/media/pexwarningsfixed.png)
::: moniker range="<=vs-2019"

![Screenshot of Rerun IntelliTest after fix.](../test/media/vs-2019/pex-warnings-fixed.png)

::: moniker-end

::: moniker range=">=vs-2022"

![Screenshot of Rerun IntelliTest after fix.](../test/media/vs-2022/pex-warnings-fixed.png)

::: moniker-end

## Specify: Use IntelliTest to validate correctness properties that you specify in code

Expand Down Expand Up @@ -129,11 +209,31 @@ If you add an assertion and rerun IntelliTest, it will check that your assertion

**A:** Yes, right-click in the class or method, then choose **Create IntelliTest**.

![Right&#45;click editor, choose Create IntelliTest](../test/media/pexcreateintellitest.png)
::: moniker range="<=vs-2019"

![Screenshot of Create IntelliTest.](../test/media/vs-2019/pex-create-intellitest.png)

::: moniker-end

::: moniker range=">=vs-2022"

![Screenshot of Create IntelliTest.](../test/media/vs-2022/pex-create-intellitest.png)

::: moniker-end

Accept the default format to generate your tests, or change how your project and tests are named. You can create a new test project or save your tests to an existing project.

![Create IntelliTest with MSTest default](../test/media/pexcreateintellitestmstest.png)
::: moniker range="<=vs-2019"

![Screenshot of Create IntelliTest with MSTest default.](../test/media/vs-2019/pex-create-intellitest-mstest.png)

::: moniker-end

::: moniker range=">=vs-2022"

![Screenshot of Create IntelliTest with MSTest default.](../test/media/vs-2022/pex-create-intellitest-mstest.png)

::: moniker-end

<a name="extend-framework"></a>
### Q: Can I use other unit test frameworks with IntelliTest?
Expand All @@ -143,7 +243,17 @@ Test framework extensions are also available in Visual Studio Marketplace, for e

After you restart Visual Studio and reopen your solution, right-click in the class or method, then choose **Create IntelliTest**. Select your installed framework here:

![Select other unit test framework for IntelliTest](../test/media/pexcreateintellitestextensions.png)
::: moniker range="<=vs-2019"

![Screenshot of Select other unit test framework for IntelliTest.](../test/media/vs-2019/pex-create-intellitest-extensions.png)

::: moniker-end

::: moniker range=">=vs-2022"

![Screenshot of Select other unit test framework for IntelliTest.](../test/media/vs-2022/pex-create-intellitest-extensions.png)

::: moniker-end

Then run IntelliTest to generate individual unit tests in their corresponding *.g.cs* files.

Expand Down
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/test/media/vs-2022/pex-fix-warning.png
Binary file added docs/test/media/vs-2022/pex-view-warning.png
Binary file added docs/test/media/vs-2022/pex-warnings-fixed.png
Binary file added docs/test/media/vs-2022/run-pex.png
Binary file added docs/test/media/vs-2022/save-pex-tests.png
Binary file added docs/test/media/vs-2022/select-pex-test.png
Binary file added docs/test/media/vs-2022/test-method-pex.png
Loading