From 37d3e04e9c109a23fcd72f069e050f9ff3060042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Fri, 7 Feb 2025 15:18:14 +0100 Subject: [PATCH 1/8] Add more links to MSTest api docs --- ...testing-mstest-writing-tests-assertions.md | 39 +++++++++++++-- ...testing-mstest-writing-tests-attributes.md | 48 +++++++++---------- ...esting-mstest-writing-tests-testcontext.md | 22 ++++----- 3 files changed, 71 insertions(+), 38 deletions(-) diff --git a/docs/core/testing/unit-testing-mstest-writing-tests-assertions.md b/docs/core/testing/unit-testing-mstest-writing-tests-assertions.md index 61665536e1c35..d4b3e6f8087c9 100644 --- a/docs/core/testing/unit-testing-mstest-writing-tests-assertions.md +++ b/docs/core/testing/unit-testing-mstest-writing-tests-assertions.md @@ -12,12 +12,45 @@ Use the `Assert` classes of the class, such as . The class has many methods to choose from, and many of the methods have several overloads. +Use the class to verify that the code under test behaves as expected. Available APIs are: + +- +- +- +- +- +- +- +- +- +- +- +- +- +- ## The `StringAssert` class -Use the class to compare and examine strings. This class contains a variety of useful methods, such as , , and . +Use the class to compare and examine strings. Available APIs are: + +- +- +- +- +- ## The `CollectionAssert` class -Use the class to compare collections of objects, or to verify the state of a collection. +Use the class to compare collections of objects, or to verify the state of a collection. Available APIs are: + +- +- +- +- +- +- +- +- +- +- +- diff --git a/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md b/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md index ff95a240e6225..aa13a3a3a614b 100644 --- a/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md +++ b/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md @@ -29,7 +29,7 @@ Every test class must have the `TestClass` attribute, and every test method must ### `TestClassAttribute` -The [TestClass]() attribute marks a class that contains tests and, optionally, initialize or cleanup methods. +The attribute marks a class that contains tests and, optionally, initialize or cleanup methods. This attribute can be extended to change or extend the default behavior. @@ -44,11 +44,11 @@ public class MyTestClass ### `TestMethodAttribute` -The [TestMethod]() attribute is used inside a `TestClass` to define the actual test method to run. +The attribute is used inside a `TestClass` to define the actual test method to run. The method should be an instance `public` method defined as `void`, `Task`, or `ValueTask` (starting with MSTest v3.3). It can optionally be `async` but should not be `async void`. -The method should have zero parameters, unless it's used with `[DataRow]`, `[DynamicData]` or similar attribute that provides test case data to the test method. +The method should have zero parameters, unless it's used with , or similar attribute that provides test case data to the test method. Consider the following example test class: @@ -74,9 +74,9 @@ Use the following elements to set up data-driven tests. For more information, se ### `DataRowAttribute` -The `DataRowAttribute` allows you to run the same test method with multiple different inputs. It can appear one or multiple times on a test method. It should be combined with `TestMethodAttribute`. +The allows you to run the same test method with multiple different inputs. It can appear one or multiple times on a test method. It should be combined with . -The number and types of arguments must exactly match the test method signature. Consider the following example of a valid test class demonstrating the `DataRow` attribute usage with inline arguments that align to test method parameters: +The number and types of arguments must exactly match the test method signature. Consider the following example of a valid test class demonstrating the usage with inline arguments that align to test method parameters: ```csharp [TestClass] @@ -113,7 +113,7 @@ public class TestClass ``` > [!NOTE] -> You can also use the `params` feature to capture multiple inputs of the `DataRow`. +> You can also use the `params` feature to capture multiple inputs of the . ```csharp [TestClass] @@ -152,7 +152,7 @@ public class TestClass > _Staring with v3:_ > `[DataRow(new string[] { "a" }, new string[] { "b" })]` -You can modify the display name used in Visual Studio and loggers for each instance of `DataRowAttribute` by setting the `DisplayName` property. +You can modify the display name used in Visual Studio and loggers for each instance of by setting the property. ```csharp [TestClass] @@ -164,7 +164,7 @@ public class TestClass } ``` -You can also create your own specialized data row attribute by inheriting the `DataRowAttribute`. +You can also create your own specialized data row attribute by inheriting the . ```csharp [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] @@ -187,9 +187,9 @@ Setup and cleanup that is common to multiple tests can be extracted to a separat ### Assembly level -[AssemblyInitialize]() is called right after your assembly is loaded and [AssemblyCleanup]() is called right before your assembly is unloaded. + is called right after your assembly is loaded and is called right before your assembly is unloaded. -The methods marked with these attributes should be defined as `static void`, `static Task` or `static ValueTask` (starting with MSTest v3.3), in a `TestClass`, and appear only once. The initialize part requires one parameter of type [TestContext](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext) and the cleanup either no parameters, or starting with MSTest 3.8 can have one parameter of type [TestContext](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext). +The methods marked with these attributes should be defined as `static void`, `static Task` or `static ValueTask` (starting with MSTest v3.3), in a , and appear only once. The initialize part requires one parameter of type and the cleanup either no parameters, or starting with MSTest 3.8 can have one parameter of type . ```csharp [TestClass] @@ -225,13 +225,13 @@ public class MyOtherTestClass ### Class level -[ClassInitialize]() is called right before your class is loaded (but after static constructor) and [ClassCleanup]() is called right after your class is unloaded. + is called right before your class is loaded (but after static constructor) and is called right after your class is unloaded. -It's possible to control the inheritance behavior: only for current class using `InheritanceBehavior.None` or for all derived classes using `InheritanceBehavior.BeforeEachDerivedClass`. +It's possible to control the inheritance behavior: only for current class using [InheritanceBehavior.None]() or for all derived classes using [InheritanceBehavior.BeforeEachDerivedClass](). It's also possible to configure whether the class cleanup should be run at the end of the class or at the end of the assembly. -The methods marked with these attributes should be defined as `static void`, `static Task` or `static ValueTask` (starting with MSTest v3.3), in a `TestClass`, and appear only once. The initialize part requires one parameter of type [TestContext](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext) and the cleanup either no parameters, or starting with MSTest 3.8 can have one parameter of type [TestContext](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext). +The methods marked with these attributes should be defined as `static void`, `static Task` or `static ValueTask` (starting with MSTest v3.3), in a `TestClass`, and appear only once. The initialize part requires one parameter of type and the cleanup either no parameters, or starting with MSTest 3.8 can have one parameter of type . ```csharp [TestClass] @@ -267,11 +267,11 @@ public class MyOtherTestClass ### Test level -[TestInitialize]() is called right before your test is started and [TestCleanup]() is called right after your test is finished. + is called right before your test is started and is called right after your test is finished. -The `TestInitialize` is similar to the class constructor but is usually more suitable for long or async initializations. The `TestInitialize` is always called after the constructor and called for each test (including each data row of data-driven tests). +The is similar to the class constructor but is usually more suitable for long or async initializations. The is always called after the constructor and called for each test (including each data row of data-driven tests). -The `TestCleanup` is similar to the class `Dispose` (or `DisposeAsync`) but is usually more suitable for long or async cleanups. The `TestCleanup` is always called just before the `DisposeAsync`/`Dispose` and called for each test (including each data row of data-driven tests). +The is similar to the class `Dispose` (or `DisposeAsync`) but is usually more suitable for long or async cleanups. The is always called just before the `DisposeAsync`/`Dispose` and called for each test (including each data row of data-driven tests). The methods marked with these attributes should be defined as `void`, `Task` or `ValueTask` (starting with MSTest v3.3), in a `TestClass`, be parameterless, and appear one or multiple times. @@ -313,7 +313,7 @@ The following attributes can be used to modify the way tests are executed. ### `TimeoutAttribute` -The [Timeout]() attribute can be used to specify the maximum time in milliseconds that a test method is allowed to run. If the test method runs longer than the specified time, the test will be aborted and marked as failed. +The attribute can be used to specify the maximum time in milliseconds that a test method is allowed to run. If the test method runs longer than the specified time, the test will be aborted and marked as failed. This attribute can be applied to any test method or any fixture method (initialization and cleanup methods). It is also possible to specify the timeout globally for either all test methods or all test fixture methods by using the [timeout properties of the runsettings file](./unit-testing-mstest-configure.md#mstest-element). @@ -322,25 +322,25 @@ This attribute can be applied to any test method or any fixture method (initiali When using the timeout feature, a separate thread/task is created to run the test method. The main thread/task is responsible for monitoring the timeout and unobserving the method thread/task if the timeout is reached. -Starting with MSTest 3.6, it is possible to specify `CooperativeCancellation` property on the attribute (or globally through runsettings) to enable cooperative cancellation. In this mode, the method is responsible for checking the cancellation token and aborting the test if it is signaled as you would do in a typical `async` method. This mode is more performant and allows for more precise control over the cancellation process. This mode can be applied to both async and sync methods. +Starting with MSTest 3.6, it is possible to specify property on the attribute (or globally through runsettings) to enable cooperative cancellation. In this mode, the method is responsible for checking the cancellation token and aborting the test if it is signaled as you would do in a typical `async` method. This mode is more performant and allows for more precise control over the cancellation process. This mode can be applied to both async and sync methods. ### `STATestClassAttribute` -When applied to a test class, the `[STATestClass]` attribute indicates that all test methods (and the `[ClassInitialize]` and `[ClassCleanup]` methods) in the class should be run in a single-threaded apartment (STA). This attribute is useful when the test methods interact with COM objects that require STA. +When applied to a test class, the attribute indicates that all test methods (and the `[ClassInitialize]` and `[ClassCleanup]` methods) in the class should be run in a single-threaded apartment (STA). This attribute is useful when the test methods interact with COM objects that require STA. > [!NOTE] > This is only supported on Windows and in version 3.6 and later. ### `STATestMethodAttribute` -When applied to a test method, the `[STATestMethod]` attribute indicates that the test method should be run in a single-threaded apartment (STA). This attribute is useful when the test method interacts with COM objects that require STA. +When applied to a test method, the attribute indicates that the test method should be run in a single-threaded apartment (STA). This attribute is useful when the test method interacts with COM objects that require STA. > [!NOTE] > This is only supported on Windows and in version 3.6 and later. ### `ParallelizeAttribute` -By default, MSTest runs tests in a sequential order. The [Parallelize]() attribute can be used to run tests in parallel. This is an assembly level attribute. You can specify if the parallelism should be at **class level** (multiple classes can be run in parallel but tests in a given class are run sequentially) or at **method level**. +By default, MSTest runs tests in a sequential order. The attribute can be used to run tests in parallel. This is an assembly level attribute. You can specify if the parallelism should be at **class level** (multiple classes can be run in parallel but tests in a given class are run sequentially) or at **method level**. It's also possible to specify the maximum number of threads to use for parallel execution. A value of `0` (default value) means that the number of threads is equal to the number of logical processors on the machine. @@ -348,10 +348,10 @@ It is also possible to specify the parallelism through the [parallelization prop ### `DoNotParallelizeAttribute` -The [DoNotParallelize]() attribute can be used to prevent parallel execution of tests in a given assembly. This attribute can be applied at the assembly level, class level or method level. +The attribute can be used to prevent parallel execution of tests in a given assembly. This attribute can be applied at the assembly level, class level or method level. > [!NOTE] -> By default, MSTest runs tests in sequential order so you only need to use this attribute if you have applied the `[Parallelize]` attribute at the assembly level. +> By default, MSTest runs tests in sequential order so you only need to use this attribute if you have applied the attribute at the assembly level. ### `RetryAttribute` @@ -372,7 +372,7 @@ It can be used either on test classes (classes marked with `TestClass` attribute Users can have multiple instances of the attribute to specify more than one item. -And here you can see its [constructors](). +And here you can see its [constructors](). **Example** diff --git a/docs/core/testing/unit-testing-mstest-writing-tests-testcontext.md b/docs/core/testing/unit-testing-mstest-writing-tests-testcontext.md index d4d2c818f9ac6..2425807060964 100644 --- a/docs/core/testing/unit-testing-mstest-writing-tests-testcontext.md +++ b/docs/core/testing/unit-testing-mstest-writing-tests-testcontext.md @@ -30,28 +30,28 @@ The `TestContext` class provides properties about the test run along with method ### Test run information -The `TestContext` provides information about the test run, such as: +The provides information about the test run, such as: - – the name of the currently executing test. - - the result of the current test. - - the full name of the test class. - - the directory where the test run is executed. - - the directory where the deployment items are located. -- - the directory where the test results are stored. Typically a subdirectory of the `TestRunDirectory`. -- - the directory where the test results are stored. Typically a subdirectory of the `ResultsDirectory`. -- - the directory where the test results are stored. Typically a subdirectory of the `ResultsDirectory`. +- - the directory where the test results are stored. Typically a subdirectory of the . +- - the directory where the test results are stored. Typically a subdirectory of the . +- - the directory where the test results are stored. Typically a subdirectory of the . -In MSTest 3.7 and later, the `TestContext` class also provides new properties helpful for `TestInitialize` and `TestCleanup` methods: +In MSTest 3.7 and later, the class also provides new properties helpful for `TestInitialize` and `TestCleanup` methods: -- `TestContext.TestData` - the data that will be provided to the parameterized test method or `null` if the test is not parameterized. -- `TestContext.TestDisplayName` - the display name of the test method. -- `TestContext.TestException` - the exception thrown by either the test method or test initialize, or `null` if the test method did not throw an exception. +- - the data that will be provided to the parameterized test method or `null` if the test is not parameterized. +- - the display name of the test method. +- - the exception thrown by either the test method or test initialize, or `null` if the test method did not throw an exception. ### Data-driven tests -In MSTest 3.7 and later, the property `TestData` can be used to access the data for the current test during `TestInitialize` and `TestCleanup` methods. +In MSTest 3.7 and later, the property can be used to access the data for the current test during `TestInitialize` and `TestCleanup` methods. -When targeting .NET framework, the `TestContext` enables you to retrieve and set data for each iteration in a data-driven test, using properties like `DataRow` and `DataConnection` (for [DataSource](xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceAttribute)-based tests). +When targeting .NET framework, the enables you to retrieve and set data for each iteration in a data-driven test, using properties like `DataRow` and `DataConnection` (for [DataSource](xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceAttribute)-based tests). Consider the following CSV file `TestData.csv`: @@ -81,4 +81,4 @@ The or methods to write custom messages directly to the test output. This is especially useful for debugging purposes, as it provides real-time logging information within your test execution context. From 779b1fa8d79bc0cd3c9388f8b1c4f877abef6ced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Fri, 7 Feb 2025 16:48:49 +0100 Subject: [PATCH 2/8] Apply suggestions from code review Co-authored-by: Youssef Victor --- ...testing-mstest-writing-tests-assertions.md | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/docs/core/testing/unit-testing-mstest-writing-tests-assertions.md b/docs/core/testing/unit-testing-mstest-writing-tests-assertions.md index d4b3e6f8087c9..43fe6a566c314 100644 --- a/docs/core/testing/unit-testing-mstest-writing-tests-assertions.md +++ b/docs/core/testing/unit-testing-mstest-writing-tests-assertions.md @@ -14,43 +14,43 @@ Use the `Assert` classes of the class to verify that the code under test behaves as expected. Available APIs are: -- -- -- -- -- -- -- -- -- -- -- +- +- +- +- +- +- +- +- +- +- +- - -- -- +- +- ## The `StringAssert` class Use the class to compare and examine strings. Available APIs are: -- -- -- -- -- +- +- +- +- +- ## The `CollectionAssert` class Use the class to compare collections of objects, or to verify the state of a collection. Available APIs are: -- -- -- -- -- -- -- -- -- -- -- +- +- +- +- +- +- +- +- +- +- +- From 415244ef652f9bb37fc9839777c6efbd21f59993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Fri, 7 Feb 2025 17:05:44 +0100 Subject: [PATCH 3/8] Apply suggestions from code review Co-authored-by: Youssef Victor --- .../unit-testing-mstest-writing-tests-assertions.md | 2 +- .../unit-testing-mstest-writing-tests-attributes.md | 10 +++++----- .../unit-testing-mstest-writing-tests-testcontext.md | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/core/testing/unit-testing-mstest-writing-tests-assertions.md b/docs/core/testing/unit-testing-mstest-writing-tests-assertions.md index 43fe6a566c314..392ef6b2eac31 100644 --- a/docs/core/testing/unit-testing-mstest-writing-tests-assertions.md +++ b/docs/core/testing/unit-testing-mstest-writing-tests-assertions.md @@ -25,7 +25,7 @@ Use the class to veri - - - -- +- - - diff --git a/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md b/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md index aa13a3a3a614b..9a2cd697d955a 100644 --- a/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md +++ b/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md @@ -227,7 +227,7 @@ public class MyOtherTestClass is called right before your class is loaded (but after static constructor) and is called right after your class is unloaded. -It's possible to control the inheritance behavior: only for current class using [InheritanceBehavior.None]() or for all derived classes using [InheritanceBehavior.BeforeEachDerivedClass](). +It's possible to control the inheritance behavior: only for current class using [InheritanceBehavior.None]() or for all derived classes using [InheritanceBehavior.BeforeEachDerivedClass](). It's also possible to configure whether the class cleanup should be run at the end of the class or at the end of the assembly. @@ -322,18 +322,18 @@ This attribute can be applied to any test method or any fixture method (initiali When using the timeout feature, a separate thread/task is created to run the test method. The main thread/task is responsible for monitoring the timeout and unobserving the method thread/task if the timeout is reached. -Starting with MSTest 3.6, it is possible to specify property on the attribute (or globally through runsettings) to enable cooperative cancellation. In this mode, the method is responsible for checking the cancellation token and aborting the test if it is signaled as you would do in a typical `async` method. This mode is more performant and allows for more precise control over the cancellation process. This mode can be applied to both async and sync methods. +Starting with MSTest 3.6, it is possible to specify property on the attribute (or globally through runsettings) to enable cooperative cancellation. In this mode, the method is responsible for checking the cancellation token and aborting the test if it is signaled as you would do in a typical `async` method. This mode is more performant and allows for more precise control over the cancellation process. This mode can be applied to both async and sync methods. ### `STATestClassAttribute` -When applied to a test class, the attribute indicates that all test methods (and the `[ClassInitialize]` and `[ClassCleanup]` methods) in the class should be run in a single-threaded apartment (STA). This attribute is useful when the test methods interact with COM objects that require STA. +When applied to a test class, the attribute indicates that all test methods (and the `[ClassInitialize]` and `[ClassCleanup]` methods) in the class should be run in a single-threaded apartment (STA). This attribute is useful when the test methods interact with COM objects that require STA. > [!NOTE] > This is only supported on Windows and in version 3.6 and later. ### `STATestMethodAttribute` -When applied to a test method, the attribute indicates that the test method should be run in a single-threaded apartment (STA). This attribute is useful when the test method interacts with COM objects that require STA. +When applied to a test method, the attribute indicates that the test method should be run in a single-threaded apartment (STA). This attribute is useful when the test method interacts with COM objects that require STA. > [!NOTE] > This is only supported on Windows and in version 3.6 and later. @@ -351,7 +351,7 @@ It is also possible to specify the parallelism through the [parallelization prop The attribute can be used to prevent parallel execution of tests in a given assembly. This attribute can be applied at the assembly level, class level or method level. > [!NOTE] -> By default, MSTest runs tests in sequential order so you only need to use this attribute if you have applied the attribute at the assembly level. +> By default, MSTest runs tests in sequential order so you only need to use this attribute if you have applied the attribute at the assembly level. ### `RetryAttribute` diff --git a/docs/core/testing/unit-testing-mstest-writing-tests-testcontext.md b/docs/core/testing/unit-testing-mstest-writing-tests-testcontext.md index 2425807060964..b4c16a1690980 100644 --- a/docs/core/testing/unit-testing-mstest-writing-tests-testcontext.md +++ b/docs/core/testing/unit-testing-mstest-writing-tests-testcontext.md @@ -81,4 +81,4 @@ The or methods to write custom messages directly to the test output. This is especially useful for debugging purposes, as it provides real-time logging information within your test execution context. +You can also use or methods to write custom messages directly to the test output. This is especially useful for debugging purposes, as it provides real-time logging information within your test execution context. From 87909efbe63178b74befe2d10e31ba6b845fbb3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 10 Feb 2025 10:45:35 +0100 Subject: [PATCH 4/8] Apply suggestions from code review Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> --- .../unit-testing-mstest-writing-tests-testcontext.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/core/testing/unit-testing-mstest-writing-tests-testcontext.md b/docs/core/testing/unit-testing-mstest-writing-tests-testcontext.md index b4c16a1690980..24da2b905047b 100644 --- a/docs/core/testing/unit-testing-mstest-writing-tests-testcontext.md +++ b/docs/core/testing/unit-testing-mstest-writing-tests-testcontext.md @@ -43,9 +43,9 @@ The provides inf In MSTest 3.7 and later, the class also provides new properties helpful for `TestInitialize` and `TestCleanup` methods: -- - the data that will be provided to the parameterized test method or `null` if the test is not parameterized. -- - the display name of the test method. -- - the exception thrown by either the test method or test initialize, or `null` if the test method did not throw an exception. +- - the data that will be provided to the parameterized test method, or `null` if the test is not parameterized. +- - the display name of the test method. +- - the exception thrown by either the test method or test initialize, or `null` if the test method did not throw an exception. ### Data-driven tests @@ -81,4 +81,4 @@ The or methods to write custom messages directly to the test output. This is especially useful for debugging purposes, as it provides real-time logging information within your test execution context. +You can also use or methods to write custom messages directly to the test output. This is especially useful for debugging purposes, as it provides real-time logging information within your test execution context. From 437c0272edc4700dfdc691a08089a132241451a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 10 Feb 2025 10:46:21 +0100 Subject: [PATCH 5/8] Apply suggestions from code review Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> --- .../testing/unit-testing-mstest-writing-tests-attributes.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md b/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md index 9a2cd697d955a..a41aa76afe11b 100644 --- a/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md +++ b/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md @@ -48,7 +48,7 @@ The attr The method should be an instance `public` method defined as `void`, `Task`, or `ValueTask` (starting with MSTest v3.3). It can optionally be `async` but should not be `async void`. -The method should have zero parameters, unless it's used with , or similar attribute that provides test case data to the test method. +The method should have zero parameters, unless it's marked with , , or a similar attribute that provides test case data to the test method. Consider the following example test class: @@ -227,7 +227,7 @@ public class MyOtherTestClass is called right before your class is loaded (but after static constructor) and is called right after your class is unloaded. -It's possible to control the inheritance behavior: only for current class using [InheritanceBehavior.None]() or for all derived classes using [InheritanceBehavior.BeforeEachDerivedClass](). +It's possible to control the inheritance behavior: only for current class using , or for all derived classes using . It's also possible to configure whether the class cleanup should be run at the end of the class or at the end of the assembly. From b3374ec6526912c51b5c54c0fc0f6456a337ee8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 10 Feb 2025 11:37:18 +0100 Subject: [PATCH 6/8] Improve style --- ...testing-mstest-writing-tests-assertions.md | 60 +++++------ ...testing-mstest-writing-tests-attributes.md | 99 +++++-------------- ...esting-mstest-writing-tests-testcontext.md | 23 ++--- 3 files changed, 68 insertions(+), 114 deletions(-) diff --git a/docs/core/testing/unit-testing-mstest-writing-tests-assertions.md b/docs/core/testing/unit-testing-mstest-writing-tests-assertions.md index 392ef6b2eac31..8e3ebf3785c0d 100644 --- a/docs/core/testing/unit-testing-mstest-writing-tests-assertions.md +++ b/docs/core/testing/unit-testing-mstest-writing-tests-assertions.md @@ -14,43 +14,43 @@ Use the `Assert` classes of the class to verify that the code under test behaves as expected. Available APIs are: -- -- -- -- -- -- -- -- -- -- -- -- -- -- +- +- +- +- +- +- +- +- +- +- +- +- +- +- ## The `StringAssert` class Use the class to compare and examine strings. Available APIs are: -- -- -- -- -- +- +- +- +- +- ## The `CollectionAssert` class Use the class to compare collections of objects, or to verify the state of a collection. Available APIs are: -- -- -- -- -- -- -- -- -- -- -- +- +- +- +- +- +- +- +- +- +- +- diff --git a/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md b/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md index a41aa76afe11b..c0215ea30fde0 100644 --- a/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md +++ b/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md @@ -29,7 +29,7 @@ Every test class must have the `TestClass` attribute, and every test method must ### `TestClassAttribute` -The attribute marks a class that contains tests and, optionally, initialize or cleanup methods. +The [TestClass]](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute) attribute marks a class that contains tests and, optionally, initialize or cleanup methods. This attribute can be extended to change or extend the default behavior. @@ -44,11 +44,11 @@ public class MyTestClass ### `TestMethodAttribute` -The attribute is used inside a `TestClass` to define the actual test method to run. +The [TestMethod](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute) attribute is used inside a `TestClass` to define the actual test method to run. The method should be an instance `public` method defined as `void`, `Task`, or `ValueTask` (starting with MSTest v3.3). It can optionally be `async` but should not be `async void`. -The method should have zero parameters, unless it's marked with , , or a similar attribute that provides test case data to the test method. +The method should have zero parameters, unless it's marked with the [DataRow](xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute) attribute, the [DynamicData])xref:Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute) attribute, or a similar attribute that provides test case data to the test method. Consider the following example test class: @@ -74,7 +74,7 @@ Use the following elements to set up data-driven tests. For more information, se ### `DataRowAttribute` -The allows you to run the same test method with multiple different inputs. It can appear one or multiple times on a test method. It should be combined with . +The [DataRow](xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute) attribute allows you to run the same test method with multiple different inputs. It can appear one or multiple times on a test method. It should be combined with the [TestMethod](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute) attribute. The number and types of arguments must exactly match the test method signature. Consider the following example of a valid test class demonstrating the usage with inline arguments that align to test method parameters: @@ -164,7 +164,7 @@ public class TestClass } ``` -You can also create your own specialized data row attribute by inheriting the . +You can also create your own specialized `DataRow` attribute by inheriting the . ```csharp [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] @@ -187,9 +187,9 @@ Setup and cleanup that is common to multiple tests can be extracted to a separat ### Assembly level - is called right after your assembly is loaded and is called right before your assembly is unloaded. +The [AssemblyInitialize](xref:Microsoft.VisualStudio.TestTools.UnitTesting.AssemblyInitializeAttribute) attribute is called right after your assembly is loaded and the [AssemblyCleanup](xref:Microsoft.VisualStudio.TestTools.UnitTesting.AssemblyCleanupAttribute) attribute is called right before your assembly is unloaded. -The methods marked with these attributes should be defined as `static void`, `static Task` or `static ValueTask` (starting with MSTest v3.3), in a , and appear only once. The initialize part requires one parameter of type and the cleanup either no parameters, or starting with MSTest 3.8 can have one parameter of type . +The methods marked with these attributes should be defined as `static void`, `static Task` or `static ValueTask` (starting with MSTest v3.3), in a class marked with , and appear only once. The initialize part requires one parameter of type and the cleanup either no parameters, or starting with MSTest 3.8 can have one parameter of type . ```csharp [TestClass] @@ -207,29 +207,14 @@ public class MyTestClass } ``` -```csharp -[TestClass] -public class MyOtherTestClass -{ - [AssemblyInitialize] - public static async Task AssemblyInitialize(TestContext testContext) - { - } - - [AssemblyCleanup] - public static async Task AssemblyCleanup() // Starting with MSTest 3.8, it can be AssemblyCleanup(TestContext testContext) - { - } -} -``` - ### Class level - is called right before your class is loaded (but after static constructor) and is called right after your class is unloaded. +The [ClassInitialize](xref:Microsoft.VisualStudio.TestTools.UnitTesting.ClassInitializeAttribute) attribute is called right before your class is loaded (but after the static constructor) and the [ClassCleanup](xref:Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute) is called right after your class is unloaded. -It's possible to control the inheritance behavior: only for current class using , or for all derived classes using . +> [!IMPORTANT] +> By default, will be triggered after the last test of the assembly (similarly to ). You can change this behavior by setting the on the attribute. Alternatively, you can set this behavior globally for the assembly using the assembly attribute . -It's also possible to configure whether the class cleanup should be run at the end of the class or at the end of the assembly. +It's also possible to control the inheritance behavior: only for current class using , or for all derived classes using . The methods marked with these attributes should be defined as `static void`, `static Task` or `static ValueTask` (starting with MSTest v3.3), in a `TestClass`, and appear only once. The initialize part requires one parameter of type and the cleanup either no parameters, or starting with MSTest 3.8 can have one parameter of type . @@ -249,29 +234,13 @@ public class MyTestClass } ``` -```csharp -[TestClass] -public class MyOtherTestClass -{ - [ClassInitialize] - public static async Task ClassInitialize(TestContext testContext) - { - } - - [ClassCleanup] - public static async Task ClassCleanup() // Starting with MSTest 3.8, it can be ClassCleanup(TestContext testContext) - { - } -} -``` - ### Test level - is called right before your test is started and is called right after your test is finished. +The [TestInitialize](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute) attribute is called right before your test is started and the [TestCleanup](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestCleanupAttribute) is called right after your test is finished. -The is similar to the class constructor but is usually more suitable for long or async initializations. The is always called after the constructor and called for each test (including each data row of data-driven tests). +The is similar to the class constructor but is usually more suitable for long or async initializations. The is always called after the constructor and called for each test (including each entry of [data-driven tests](#attributes-used-for-data-driven-testing)). -The is similar to the class `Dispose` (or `DisposeAsync`) but is usually more suitable for long or async cleanups. The is always called just before the `DisposeAsync`/`Dispose` and called for each test (including each data row of data-driven tests). +The is similar to the class `Dispose` (or `DisposeAsync`) but is usually more suitable for long or async cleanups. The is always called just before the `DisposeAsync`/`Dispose` and called for each test (including each entry of [data-driven tests](#attributes-used-for-data-driven-testing)). The methods marked with these attributes should be defined as `void`, `Task` or `ValueTask` (starting with MSTest v3.3), in a `TestClass`, be parameterless, and appear one or multiple times. @@ -291,34 +260,18 @@ public class MyTestClass } ``` -```csharp -[TestClass] -public class MyOtherTestClass -{ - [TestInitialize] - public async Task TestInitialize() - { - } - - [TestCleanup] - public async Task TestCleanup() - { - } -} -``` - ## Attributes used to control test execution The following attributes can be used to modify the way tests are executed. ### `TimeoutAttribute` -The attribute can be used to specify the maximum time in milliseconds that a test method is allowed to run. If the test method runs longer than the specified time, the test will be aborted and marked as failed. +The [Timeout](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TimeoutAttribute) attribute can be used to specify the maximum time in milliseconds that a test method is allowed to run. If the test method runs longer than the specified time, the test will be aborted and marked as failed. This attribute can be applied to any test method or any fixture method (initialization and cleanup methods). It is also possible to specify the timeout globally for either all test methods or all test fixture methods by using the [timeout properties of the runsettings file](./unit-testing-mstest-configure.md#mstest-element). > [!NOTE] -> The timeout is not guaranteed to be precise. The test will be aborted after the specified time has passed, but it may take a few milliseconds longer. +> The timeout is not guaranteed to be precise. The test will be aborted after the specified time has passed, but it may take longer before the step is cancelled. When using the timeout feature, a separate thread/task is created to run the test method. The main thread/task is responsible for monitoring the timeout and unobserving the method thread/task if the timeout is reached. @@ -326,21 +279,21 @@ Starting with MSTest 3.6, it is possible to specify attribute indicates that all test methods (and the `[ClassInitialize]` and `[ClassCleanup]` methods) in the class should be run in a single-threaded apartment (STA). This attribute is useful when the test methods interact with COM objects that require STA. +When applied to a test class, the [STATestClass](xref:Microsoft.VisualStudio.TestTools.UnitTesting.STATestClassAttribute) attribute indicates that all test methods (and the `[ClassInitialize]` and `[ClassCleanup]` methods) in the class should be run in a single-threaded apartment (STA). This attribute is useful when the test methods interact with COM objects that require STA. > [!NOTE] > This is only supported on Windows and in version 3.6 and later. ### `STATestMethodAttribute` -When applied to a test method, the attribute indicates that the test method should be run in a single-threaded apartment (STA). This attribute is useful when the test method interacts with COM objects that require STA. +When applied to a test method, the [STATestMethod](xref:Microsoft.VisualStudio.TestTools.UnitTesting.STATestMethodAttribute) attribute indicates that the test method should be run in a single-threaded apartment (STA). This attribute is useful when the test method interacts with COM objects that require STA. > [!NOTE] > This is only supported on Windows and in version 3.6 and later. ### `ParallelizeAttribute` -By default, MSTest runs tests in a sequential order. The attribute can be used to run tests in parallel. This is an assembly level attribute. You can specify if the parallelism should be at **class level** (multiple classes can be run in parallel but tests in a given class are run sequentially) or at **method level**. +By default, MSTest runs tests in a sequential order. The assembly level attribute [Parallelize](xref:Microsoft.VisualStudio.TestTools.UnitTesting.ParallelizeAttribute) can be used to run tests in parallel. You can specify if the parallelism should be at [class level](xref:Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope.ClassLevel?displayProperty=nameWithType) (multiple classes can be run in parallel but tests in a given class are run sequentially) or at [method level](xref:Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope.MethodLevel?displayProperty=nameWithType). It's also possible to specify the maximum number of threads to use for parallel execution. A value of `0` (default value) means that the number of threads is equal to the number of logical processors on the machine. @@ -348,16 +301,16 @@ It is also possible to specify the parallelism through the [parallelization prop ### `DoNotParallelizeAttribute` -The attribute can be used to prevent parallel execution of tests in a given assembly. This attribute can be applied at the assembly level, class level or method level. +The [DoNotParallelize](xref:Microsoft.VisualStudio.TestTools.UnitTesting.DoNotParallelizeAttribute) attribute can be used to prevent parallel execution of tests in a given assembly. This attribute can be applied at the assembly level, class level or method level. > [!NOTE] -> By default, MSTest runs tests in sequential order so you only need to use this attribute if you have applied the attribute at the assembly level. +> By default, MSTest runs tests in sequential order so you only need to use this attribute if you have applied the assembly level [Parallelize](xref:Microsoft.VisualStudio.TestTools.UnitTesting.ParallelizeAttribute) attribute. ### `RetryAttribute` -The `RetryAttribute` was introduced in MSTest 3.8. This attribute causes the test method to be retried when it fails or timeouts. It allows you to specify the maximum number of retry attempts, the time delay between retries, and a delay backoff type, which is either constant or exponential. +The `Retry` attribute was introduced in MSTest 3.8. This attribute causes the test method to be retried when it fails or timeouts. It allows you to specify the maximum number of retry attempts, the time delay between retries, and a delay backoff type, which is either constant or exponential. -Only one `RetryAttribute` is expected to be present on a test method, and `RetryAttribute` cannot be used on methods that are not marked with `TestMethodAttribute`. +Only one `RetryAttribute` is expected to be present on a test method, and `RetryAttribute` cannot be used on methods that are not marked with [TestMethod](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute). > [!NOTE] > `RetryAttribute` derives from an abstract `RetryBaseAttribute`. You can also create your own retry implementations if the built-in `RetryAttribute` doesn't suite your needs. @@ -366,9 +319,9 @@ Only one `RetryAttribute` is expected to be present on a test method, and `Retry ### `DeploymentItemAttribute` -The MSTest framework introduced for copying files or folders specified as deployment items to the deployment directory (without adding a custom output path the copied files will be in TestResults folder inside the project folder). The deployment directory is where all the deployment items are present along with test project DLL. +The [DeploymentItem](xref:Microsoft.VisualStudio.TestTools.UnitTesting.DeploymentItemAttribute) attribute is used for copying files or folders specified as deployment items to the deployment directory (without adding a custom output path the copied files will be in `TestResults` folder inside the project folder). The deployment directory is where all the deployment items are present along with test project DLL. -It can be used either on test classes (classes marked with `TestClass` attribute) or on test methods (methods marked with `TestMethod` attribute). +It can be used either on test classes (classes marked with the [TestClass](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute) attribute) or on test methods (methods marked with [TestMethod](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute) attribute). Users can have multiple instances of the attribute to specify more than one item. @@ -396,7 +349,7 @@ public class UnitTest1 ### `ExpectedExceptionAttribute` -The MSTest framework introduced for marking a test method to expect an exception of a specific type. The test will pass if the expected exception is thrown and the exception message matches the expected message. +The [ExpectedException](xref:Microsoft.VisualStudio.TestTools.UnitTesting.ExpectedExceptionAttribute) attribute defines the expected exception the test method will throw. The test will pass if the expected exception is thrown and the exception message matches the expected message. > [!WARNING] > This attribute exists for backward compatibility and is not recommended for new tests. Instead, use the `Assert.ThrowsException` (or `Assert.ThrowsExactly` if using MSTest 3.8 and later) method. diff --git a/docs/core/testing/unit-testing-mstest-writing-tests-testcontext.md b/docs/core/testing/unit-testing-mstest-writing-tests-testcontext.md index 24da2b905047b..10f92957d2e24 100644 --- a/docs/core/testing/unit-testing-mstest-writing-tests-testcontext.md +++ b/docs/core/testing/unit-testing-mstest-writing-tests-testcontext.md @@ -14,7 +14,8 @@ The class gives The object is available in the following contexts: -- As a parameter to `[AssemblyInitialize]` and `[ClassInitialize]` methods. In this context, the properties related to the test run are not available. +- As a parameter to [AssemblyInitialize](xref:Microsoft.VisualStudio.TestTools.UnitTesting.AssemblyInitializeAttribute), the [ClassInitialize](xref:Microsoft.VisualStudio.TestTools.UnitTesting.ClassInitializeAttribute) methods. In this context, the properties related to the test run are not available. +- Starting with 3.6, optionally, as a parameter to [AssemblyCleanup](xref:Microsoft.VisualStudio.TestTools.UnitTesting.AssemblyCleanupAttribute), the [ClassCleanup](xref:Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute) methods. In this context, the properties related to the test run are not available. - As a property of a test class. In this context, the properties related to the test run are available. - As a constructor parameter of a test class (starting with v3.6). This way is recommended over using the property, because it gives access to the object in the constructor. While the property is only available after the constructor has run. This way also helps to ensure immutability of the object and allows the compiler to enforce that the object is not null. @@ -26,20 +27,20 @@ Or with MSTest 3.6+: ## The `TestContext` members -The `TestContext` class provides properties about the test run along with methods to manipulate the test environment. This section covers the most commonly used properties and methods. +The class provides properties about the test run along with methods to manipulate the test environment. This section covers the most commonly used properties and methods. ### Test run information The provides information about the test run, such as: -- – the name of the currently executing test. -- - the result of the current test. -- - the full name of the test class. -- - the directory where the test run is executed. -- - the directory where the deployment items are located. -- - the directory where the test results are stored. Typically a subdirectory of the . -- - the directory where the test results are stored. Typically a subdirectory of the . -- - the directory where the test results are stored. Typically a subdirectory of the . +- – the name of the currently executing test. +- - the result of the current test. +- - the full name of the test class. +- - the directory where the test run is executed. +- - the directory where the deployment items are located. +- - the directory where the test results are stored. Typically a subdirectory of the . +- - the directory where the test results are stored. Typically a subdirectory of the . +- - the directory where the test results are stored. Typically a subdirectory of the . In MSTest 3.7 and later, the class also provides new properties helpful for `TestInitialize` and `TestCleanup` methods: @@ -49,7 +50,7 @@ In MSTest 3.7 and later, the can be used to access the data for the current test during `TestInitialize` and `TestCleanup` methods. +In MSTest 3.7 and later, the property can be used to access the data for the current test during `TestInitialize` and `TestCleanup` methods. When targeting .NET framework, the enables you to retrieve and set data for each iteration in a data-driven test, using properties like `DataRow` and `DataConnection` (for [DataSource](xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceAttribute)-based tests). From 4bf84e5202ecc1ad03c1b577c2095e39694a0659 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Mon, 10 Feb 2025 09:36:29 -0800 Subject: [PATCH 7/8] Update docs/core/testing/unit-testing-mstest-writing-tests-attributes.md --- .../testing/unit-testing-mstest-writing-tests-attributes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md b/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md index c0215ea30fde0..066eb69198243 100644 --- a/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md +++ b/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md @@ -212,7 +212,7 @@ public class MyTestClass The [ClassInitialize](xref:Microsoft.VisualStudio.TestTools.UnitTesting.ClassInitializeAttribute) attribute is called right before your class is loaded (but after the static constructor) and the [ClassCleanup](xref:Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute) is called right after your class is unloaded. > [!IMPORTANT] -> By default, will be triggered after the last test of the assembly (similarly to ). You can change this behavior by setting the on the attribute. Alternatively, you can set this behavior globally for the assembly using the assembly attribute . +> By default, will be triggered after the last test of the assembly (similarly to ). You can change this behavior by setting the on the attribute. Alternatively, you can set this behavior globally for the assembly using the assembly attribute . It's also possible to control the inheritance behavior: only for current class using , or for all derived classes using . From 34f857ebcdb1850e06758d9e9f051f01829b28ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 10 Feb 2025 20:13:47 +0100 Subject: [PATCH 8/8] Apply suggestions from code review Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> --- .../unit-testing-mstest-writing-tests-attributes.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md b/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md index 066eb69198243..de97619d95378 100644 --- a/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md +++ b/docs/core/testing/unit-testing-mstest-writing-tests-attributes.md @@ -29,7 +29,7 @@ Every test class must have the `TestClass` attribute, and every test method must ### `TestClassAttribute` -The [TestClass]](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute) attribute marks a class that contains tests and, optionally, initialize or cleanup methods. +The [TestClass](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute) attribute marks a class that contains tests and, optionally, initialize or cleanup methods. This attribute can be extended to change or extend the default behavior. @@ -48,7 +48,7 @@ The [TestMethod](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAtt The method should be an instance `public` method defined as `void`, `Task`, or `ValueTask` (starting with MSTest v3.3). It can optionally be `async` but should not be `async void`. -The method should have zero parameters, unless it's marked with the [DataRow](xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute) attribute, the [DynamicData])xref:Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute) attribute, or a similar attribute that provides test case data to the test method. +The method should have zero parameters, unless it's marked with the [DataRow](xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute) attribute, the [DynamicData](xref:Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute) attribute, or a similar attribute that provides test case data to the test method. Consider the following example test class: @@ -293,7 +293,7 @@ When applied to a test method, the [STATestMethod](xref:Microsoft.VisualStudio.T ### `ParallelizeAttribute` -By default, MSTest runs tests in a sequential order. The assembly level attribute [Parallelize](xref:Microsoft.VisualStudio.TestTools.UnitTesting.ParallelizeAttribute) can be used to run tests in parallel. You can specify if the parallelism should be at [class level](xref:Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope.ClassLevel?displayProperty=nameWithType) (multiple classes can be run in parallel but tests in a given class are run sequentially) or at [method level](xref:Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope.MethodLevel?displayProperty=nameWithType). +By default, MSTest runs tests in a sequential order. The assembly level attribute [Parallelize](xref:Microsoft.VisualStudio.TestTools.UnitTesting.ParallelizeAttribute) attribute can be used to run tests in parallel. You can specify if the parallelism should be at [class level](xref:Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope.ClassLevel) (multiple classes can be run in parallel but tests in a given class are run sequentially) or at [method level](xref:Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope.MethodLevel). It's also possible to specify the maximum number of threads to use for parallel execution. A value of `0` (default value) means that the number of threads is equal to the number of logical processors on the machine. @@ -349,7 +349,7 @@ public class UnitTest1 ### `ExpectedExceptionAttribute` -The [ExpectedException](xref:Microsoft.VisualStudio.TestTools.UnitTesting.ExpectedExceptionAttribute) attribute defines the expected exception the test method will throw. The test will pass if the expected exception is thrown and the exception message matches the expected message. +The [ExpectedException](xref:Microsoft.VisualStudio.TestTools.UnitTesting.ExpectedExceptionAttribute) attribute defines the exception that the test method is expected to throw. The test passes if the expected exception is thrown and the exception message matches the expected message. > [!WARNING] > This attribute exists for backward compatibility and is not recommended for new tests. Instead, use the `Assert.ThrowsException` (or `Assert.ThrowsExactly` if using MSTest 3.8 and later) method.